diff options
Diffstat (limited to 'app/controllers/sessions_controller.rb')
-rw-r--r-- | app/controllers/sessions_controller.rb | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 68cb949..fa5d024 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,22 +1,28 @@ class SessionsController < ApplicationController + # GET /sessions/new def new + if @user.nil? + @user = User.new + end end - # find the user and create a new session - def create - user = User.find_by(email: params[:session][:email].downcase) - if user && user.authenticate(params[:session][:password]) - sign_in user - redirect_to root_path - else - render 'new' - end - end + # POST /sessions + def create + # find the user... + @user = User.find_by(email: params[:session][:email].downcase) + # ... and create a new session + if @user && @user.authenticate(params[:session][:password]) + sign_in @user + redirect_to root_path + else + redirect_to new_session_path + end + end + # DELETE /sessions/current def destroy - sign_out - redirect_to root_path + sign_out + redirect_to root_path end - end |