2014-04-14 10:40:17 +00:00
|
|
|
class SessionsController < ApplicationController
|
|
|
|
layout "authentication"
|
|
|
|
|
|
|
|
def new
|
2014-07-16 03:42:10 +00:00
|
|
|
if session[:user_id]
|
|
|
|
redirect_to admin_dashboards_path
|
|
|
|
end
|
2014-04-14 10:40:17 +00:00
|
|
|
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-07-16 03:42:10 +00:00
|
|
|
if user.is_approved? || user.is_admin?
|
2014-05-27 10:18:23 +00:00
|
|
|
session[:user_id] = user.id
|
2014-08-15 02:29:17 +00:00
|
|
|
session[:login_referer] = nil
|
|
|
|
if params[:referer_url]
|
2014-09-23 09:06:17 +00:00
|
|
|
redirect_to URI.parse(params[:referer_url]).path
|
2014-07-16 03:42:10 +00:00
|
|
|
else
|
|
|
|
redirect_to admin_dashboards_path
|
|
|
|
end
|
2014-05-27 10:18:23 +00:00
|
|
|
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
|
2014-07-16 03:42:10 +00:00
|
|
|
redirect_to root_url
|
2014-04-14 10:40:17 +00:00
|
|
|
end
|
|
|
|
end
|