Class: Users::SessionsController

Inherits:
Devise::SessionsController
  • Object
show all
Includes:
RedirectCheckingHelper
Defined in:
app/controllers/users/sessions_controller.rb

Instance Method Summary collapse

Methods included from RedirectCheckingHelper

#check_redirect_to

Instance Method Details

#create {|resource| ... } ⇒ Object

Sign in

Yields:

  • (resource)

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/users/sessions_controller.rb', line 21

def create
  # https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb
  self.resource = warden.authenticate!(auth_options)
  set_flash_message(:notice, :signed_in) if is_flashing_format?
  (resource_name, resource)
  yield resource if block_given?

  # if an invitation_code exists, activate the email for that user
  if session[:invitation_code].present?
    InvitationCodeService.invite(current_user, session[:invitation_code])
    redirect_url = session[:invitation_redirect_url] || root_path

    session[:invitation_code] = nil
    session[:invitation_redirect_url] = nil

    redirect_to redirect_url and return
  end

  # redirect new users to verify their email
  if current_user.primary_identity_id.blank? && current_user.created_at > 2.hours.ago
    redirect_to  and return
  end

  respond_with resource, location: (resource)
end

#destroyObject

Sign out


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/users/sessions_controller.rb', line 48

def destroy
  signed_out = sign_out(:user)
  set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
  yield if block_given?

  check_redirect_to

  if can_redirect
    redirect_to redirect_url
  else
    respond_to_on_destroy
  end
end

#newObject


8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/users/sessions_controller.rb', line 8

def new
  if session[:invitation_code].present?
    invited_guest_email = InvitationCodeService.verify(session[:invitation_code])
    @invited_guest_identity = UserIdentity.unlinked.find_by(email: invited_guest_email)
    if @invited_guest_identity.present?
      @invited_guest_identity.name = @invited_guest_identity.email if @invited_guest_identity.name.blank?
    end
  end

  super
end

#refresh_itObject

Refresh the identity_token


63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/users/sessions_controller.rb', line 63

def refresh_it
  refresh_site_identity_token

  check_redirect_to

  if can_redirect
    redirect_to redirect_url
  else
    redirect_to root_path
  end
end