Refactored login module. Implemented standard sessions controller.
This commit is contained in:
parent
b1a700ab5d
commit
e40f865c45
13 changed files with 89 additions and 332 deletions
24
app/controllers/sessions_controller.rb
Normal file
24
app/controllers/sessions_controller.rb
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class SessionsController < ApplicationController
|
||||
|
||||
skip_before_filter :authenticate
|
||||
layout 'login'
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.authenticate(params[:nick], params[:password])
|
||||
if user
|
||||
session[:user_id] = user.id
|
||||
redirect_to session['return_to'] || root_url, :notice => "Logged in!"
|
||||
else
|
||||
flash.now.alert = "Invalid email or password"
|
||||
render "new"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
session[:user_id] = nil
|
||||
redirect_to login_url, :notice => "Logged out!"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue