2014-04-14 10:40:17 +00:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
layout "authentication"
|
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-04-21 02:48:36 +00:00
|
|
|
user = User.find_by(user_name: params[:user_name]) rescue nil
|
2014-05-09 06:03:55 +00:00
|
|
|
if (user && user.authenticate(params[:password]) && user.is_confirmed?.eql?(true))
|
2014-05-27 10:18:23 +00:00
|
|
|
if user.is_approved?
|
|
|
|
session[:user_id] = user.id
|
|
|
|
redirect_to admin_dashboards_path, :notice => "Logged in!"
|
|
|
|
elsif user.is_admin?
|
|
|
|
session[:user_id] = user.id
|
|
|
|
redirect_to admin_dashboards_path, :notice => "Logged in!"
|
|
|
|
else
|
|
|
|
flash.now.alert = "User not approved."
|
|
|
|
render "new"
|
|
|
|
end
|
2014-04-14 10:40:17 +00:00
|
|
|
else
|
2014-04-21 07:19:29 +00:00
|
|
|
flash.now.alert = "Invalid username or password"
|
2014-04-14 10:40:17 +00:00
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2014-05-28 07:57:58 +00:00
|
|
|
log_user_action
|
2014-04-14 10:40:17 +00:00
|
|
|
session[:user_id] = nil
|
|
|
|
redirect_to root_url, :notice => "Logged out!"
|
|
|
|
end
|
|
|
|
end
|