sessions_controller.rb 562 B

12345678910111213141516171819202122
  1. class SessionsController < ApplicationController
  2. def new
  3. redirect_to home_path if logged_in?
  4. end
  5. def create
  6. @user = User.find_by(login: params[:session][:login].downcase)
  7. if @user && @user.authenticate(params[:session][:password])
  8. log_in @user
  9. params[:session][:remember_me] == '1' ? remember(@user) : forget(@user)
  10. redirect_back_or home_url
  11. else
  12. flash.now[:danger] = 'Invalid login/password combination'
  13. render 'new'
  14. end
  15. end
  16. def destroy
  17. log_out if logged_in?
  18. redirect_to login_url
  19. end
  20. end