Module: Authentication

Extended by:
ActiveSupport::Concern
Included in:
Admin::UsersController, AuthenticationController, My::ConfirmationsController, My::ProfilesController
Defined in:
app/controllers/concerns/authentication.rb

Overview

Adds methods for user authentication

Instance Method Summary collapse

Instance Method Details

Parameters:

  • value (String)


37
38
39
40
41
42
43
44
# File 'app/controllers/concerns/authentication.rb', line 37

def cookie_data(value)
  {
    value: value,
    expires: 1.year.from_now,
    domain: :all,
    httponly: true
  }
end

#create_token_for_user(user) ⇒ Object

Parameters:



12
13
14
15
16
17
18
19
# File 'app/controllers/concerns/authentication.rb', line 12

def create_token_for_user(user)
  forced_user = User.find_by(id: user.primary_id)
  user = forced_user unless forced_user.nil?

  token = user.tokens.create!(tracking_for_entity)

  cookies['token'] = cookie_data(token.cookie_pair)
end

#deactivate_tokenObject



21
22
23
24
25
# File 'app/controllers/concerns/authentication.rb', line 21

def deactivate_token
  token = Token.find_by(token: cookies['token'].split(':').last)
  token&.update(active: false)
  pop_token
end

#pop_tokenObject



27
28
29
30
31
32
33
34
# File 'app/controllers/concerns/authentication.rb', line 27

def pop_token
  if cookies['pt']
    cookies['token'] = cookie_data(cookies['pt'])
    cookies.delete 'pt', domain: :all
  else
    cookies.delete 'token', domain: :all
  end
end

#redirect_authenticated_userObject



7
8
9
# File 'app/controllers/concerns/authentication.rb', line 7

def redirect_authenticated_user
  redirect_to my_path unless current_user.nil?
end