2014-03-09 14:43:33 -06:00
|
|
|
class UserSessionsController < ApplicationController
|
|
|
|
def new
|
2014-04-29 21:02:02 -06:00
|
|
|
session[:return_to] ||= request.referer
|
2014-03-09 14:43:33 -06:00
|
|
|
@user = User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if @user = login(params[:email], params[:password])
|
2014-04-29 21:02:02 -06:00
|
|
|
redirect_to session.delete(:return_to) || 'pages#home'
|
2014-03-09 14:43:33 -06:00
|
|
|
else
|
|
|
|
flash.now[:alert] = "Login failed"
|
|
|
|
render action: "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
logout
|
|
|
|
redirect_to(:users, notice: 'Logged out!')
|
|
|
|
end
|
|
|
|
end
|