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-04-14 10:40:17 +00:00
|
|
|
session[:user_id] = user.id
|
|
|
|
redirect_to admin_dashboards_path, :notice => "Logged in!"
|
|
|
|
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
|
|
|
|
session[:user_id] = nil
|
|
|
|
redirect_to root_url, :notice => "Logged out!"
|
|
|
|
end
|
|
|
|
end
|