public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
insoshi / app / controllers / sessions_controller.rb
100644 32 lines (28 sloc) 0.933 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
 
  # render new.rhtml
  def new
  end
 
  def create
    self.current_person = Person.authenticate(params[:email], params[:password])
    if logged_in?
      if params[:remember_me] == "1"
        self.current_person.remember_me
        cookies[:auth_token] = { :value => self.current_person.remember_token , :expires => self.current_person.remember_token_expires_at }
      end
      redirect_back_or_default('/')
      flash[:success] = "Logged in successfully"
    else
      flash[:error] = "Invalid email/password combination"
      params[:password] = nil
      render :action => 'new'
    end
  end
 
  def destroy
    self.current_person.forget_me if logged_in?
    cookies.delete :auth_token
    reset_session
    flash[:success] = "You have been logged out."
    redirect_back_or_default('/')
  end
end