This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
2008-10-01 02:19:35 -04:00
|
|
|
class Sessions < Application
|
|
|
|
def index
|
|
|
|
redirect '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
user = User.find_by_user_name params[:user_name]
|
2008-10-11 04:22:58 -04:00
|
|
|
if user and user.authenticated_against?(params[:password])
|
2008-10-01 02:19:35 -04:00
|
|
|
session[:user_id] = user.id
|
2008-10-17 18:17:42 -04:00
|
|
|
valid_anonymous_user!
|
2008-10-11 04:22:58 -04:00
|
|
|
if request.xhr?
|
|
|
|
render '', :status => 200
|
|
|
|
else
|
|
|
|
flash[:notice] = 'Great success!'
|
|
|
|
redirect '/'
|
|
|
|
end
|
2008-10-01 02:19:35 -04:00
|
|
|
else
|
2008-10-11 04:22:58 -04:00
|
|
|
if request.xhr?
|
|
|
|
render '', :status => 401
|
|
|
|
else
|
|
|
|
flash.now[:error] = 'Login failed'
|
|
|
|
render :new
|
|
|
|
end
|
2008-10-01 02:19:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
|
|
|
reset_session
|
2008-10-11 04:22:58 -04:00
|
|
|
if request.xhr?
|
|
|
|
render '', :status => 200
|
|
|
|
else
|
|
|
|
flash[:notice] = 'Goodbye!'
|
|
|
|
redirect '/'
|
|
|
|
end
|
2008-10-01 02:19:35 -04:00
|
|
|
end
|
|
|
|
end
|