Class: Cally::SessionController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Cally::SessionController
- Defined in:
- app/controllers/cally/session_controller.rb
Instance Method Summary collapse
Methods included from Methods
#admin_or_same_user?, #logged_in_as_admin?, #same_user?, #set_mailgun_prefix, #test_env?
Methods included from ApplicationHelper
#current_user, #is_admin?, #is_first_user?, #logged_in?
Instance Method Details
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/cally/session_controller.rb', line 5 def create user = User.find_by(email: params[:session][:email].downcase) # checks if the parameter email is connected to a user in the database # and the given password is correct # When this is all true then create a session variable with the user's id # and then returns to the page which you were on before the login form if user && user.authenticate(params[:session][:password]) if user.update(last_logged_in_time: user.logged_in_time, logged_in_time: DateTime.current()) session[:user_id] = user.id flash[:success] = "Welcome #{user.username}" if session[:return_to] redirect_to user_path(user) #redirect_to session[:return_to] session[:return_to] = nil else redirect_to user_path(user) end else flash.now[:error] = "Error saving logged in time" redirect_to login_path end else flash[:error] = "Error logging in" redirect_to login_path end end |
#destroy ⇒ Object
34 35 36 37 38 39 |
# File 'app/controllers/cally/session_controller.rb', line 34 def destroy session[:user_id] = nil reset_session flash[:success] = "Successfully logged out" redirect_to login_path end |