Created
March 3, 2011 04:55
-
-
Save gamov/852351 to your computer and use it in GitHub Desktop.
session controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
skip_before_filter :login_required, :only => [:new, :create] | |
layout nil | |
def new | |
render #:layout => nil | |
end | |
def create | |
user = User.authenticate(params[:username], params[:password]) | |
if user | |
session[:user_id] = user.id | |
logger.info "User '#{user.username} logged in" | |
flash[:notice]= "Welcome back #{user.name}!" | |
redirect_to_target_or_default(root_url) | |
# redirect_to root_url, :notice => "Logged in!" | |
else | |
logger.info "Failed login: u=#{params[:username]}" | |
flash.now[:alert]= "Invalid username or password" | |
render :action => 'new' #, :layout => nil | |
end | |
# puts current_user.inspect | |
end | |
def destroy | |
logger.info "User '#{current_user.username} logged out" if current_user | |
session[:user_id] = nil | |
redirect_to login_url, :notice => "Logged out, bye." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment