2016-08-17 17:49:09 -05:00
|
|
|
module Admin
|
|
|
|
class AuthController < AdminController
|
2016-08-18 15:35:17 -05:00
|
|
|
skip_before_action :authorize_admin
|
|
|
|
|
2016-08-17 17:49:09 -05:00
|
|
|
def login
|
|
|
|
end
|
|
|
|
|
|
|
|
def auth
|
2016-08-18 15:35:17 -05:00
|
|
|
admin = User.find_by(email: auth_params[:email], role: 'admin')
|
|
|
|
|
|
|
|
if admin && admin.authenticate(auth_params[:password])
|
|
|
|
session[:user] = admin.to_i
|
|
|
|
redirect_to admin_path
|
|
|
|
else
|
|
|
|
redirect_to admin_login_path,
|
|
|
|
flash: { error: "Sorry, incorrect email or password. Please try again." }
|
|
|
|
end
|
2016-08-17 17:49:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def logout
|
2016-08-18 15:35:17 -05:00
|
|
|
reset_session
|
|
|
|
redirect_to admin_login_path
|
2016-08-17 17:49:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|