Module: Authifer::AuthenticationHelper

Defined in:
lib/authifer/authentication_helper.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_user(user_attributes) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/authifer/authentication_helper.rb', line 26

def authenticate_user(user_attributes)
  user = find_user(email: user_attributes[:email])

  user = build_user if !user

  if user.password != user_attributes[:password] || user.password.nil?
    user.errors.add(:credentials, "are invalid. We don't have any users with that email/password combination")
  end

  user
end

#current_userObject



10
11
12
# File 'lib/authifer/authentication_helper.rb', line 10

def current_user
  @current_user ||= logged_in? ? find_user(id: session[:user_id]) : build_user
end

#ensure_logged_in!Object



3
4
5
6
7
8
# File 'lib/authifer/authentication_helper.rb', line 3

def ensure_logged_in!
  unless logged_in?
    @redirect_url = request.fullpath
    halt display.(build_user)
  end
end

#logged_in?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/authifer/authentication_helper.rb', line 18

def logged_in?
  !session[:user_id].nil?
end

#login(user) ⇒ Object



14
15
16
# File 'lib/authifer/authentication_helper.rb', line 14

def (user)
  session[:user_id] = user.id
end

#logoutObject



22
23
24
# File 'lib/authifer/authentication_helper.rb', line 22

def logout
  session[:user_id] = nil
end