forked from saurabh/orbit4-5
23 lines
526 B
Ruby
23 lines
526 B
Ruby
class SessionsController < ApplicationController
|
|
layout "authentication"
|
|
|
|
def new
|
|
end
|
|
|
|
def create
|
|
user = User.find_by(user_name: params[:user_name]) rescue nil
|
|
if user && user.authenticate(params[:password])
|
|
session[:user_id] = user.id
|
|
redirect_to admin_dashboards_path, :notice => "Logged in!"
|
|
else
|
|
flash.now.alert = "Invalid username or password"
|
|
render "new"
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
session[:user_id] = nil
|
|
redirect_to root_url, :notice => "Logged out!"
|
|
end
|
|
end
|