Sha256: 67c6de96945d8931106701045ded30ba794272a7afc8230445248735c16b73da
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
module Minimalist module Sessions def show redirect_to new_session_path end def new @user = User.new end def create if user = User.authenticate(user_params[:email], user_params[:password]) user.logged_in session[:user_id] = user.id after_authentication(user) redirect_back_or_default(login_redirect_to(user)) return else after_authentication_failure flash.now[:alert] = "Couldn't log you in as '#{user_params[:email]}'" render action: 'new' end end def destroy session[:user_id] = nil flash[:notice] = "You have been logged out." redirect_to logout_redirect_to end private def user_params @user_params ||= params.require(:user).permit(:email, :password) end def login_redirect_to(user) '/' end def logout_redirect_to '/' end def after_authentication(user) # overide in application end def after_authentication_failure # overide in application end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
minimalist_authentication-1.0.0 | lib/minimalist/sessions.rb |