Class: Admin::InvitesController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/invites_controller.rb

Instance Attribute Summary

Attributes included from PagesCore::Authentication

#current_user

Instance Method Summary collapse

Methods inherited from PagesCore::AdminController

#redirect, underscore

Methods included from PagesCore::PoliciesHelper

#policy, #verify_policy, #verify_policy_with_proc

Methods included from PagesCore::ProcessTitler

inc_number_of_requests, original_title

Methods included from PagesCore::ErrorRenderer

#render_error

Methods included from PagesCore::Authentication

#authenticate!, #deauthenticate!, #logged_in?

Instance Method Details

#acceptObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/admin/invites_controller.rb', line 13

def accept
  @user = PagesCore::CreateUserService.call(user_params, invite: @invite)
  if @user.valid?
    authenticate!(@user)
    redirect_to admin_default_url
  else
    render action: :show
  end
end

#createObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/admin/invites_controller.rb', line 34

def create
  @invite = PagesCore::InviteService.call(invite_params,
                                          user: current_user,
                                          host: request.host,
                                          protocol: request.protocol)
  if @invite.valid?
    redirect_to admin_invites_url
  else
    render action: :new
  end
end

#destroyObject



46
47
48
49
50
# File 'app/controllers/admin/invites_controller.rb', line 46

def destroy
  flash[:notice] = "The invite to #{@invite.email} has been deleted"
  @invite.destroy
  redirect_to admin_invites_url
end

#indexObject



9
10
11
# File 'app/controllers/admin/invites_controller.rb', line 9

def index
  redirect_to admin_users_url
end

#newObject



27
28
29
30
31
32
# File 'app/controllers/admin/invites_controller.rb', line 27

def new
  @invite = current_user.invites.new
  Role.roles.each do |role|
    @invite.roles.new(name: role.name) if role.default
  end
end

#showObject



23
24
25
# File 'app/controllers/admin/invites_controller.rb', line 23

def show
  @user = User.new(email: @invite.email)
end