Class: CargoWiki::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cargo_wiki/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/cargo_wiki/sessions_controller.rb', line 9

def create
  user = User.find_by_username(params[:username])
  if user && user.authenticate(params[:password])
    params[:remember_me] ? cookies.permanent[:auth_token] = user.auth_token : cookies[:auth_token] = user.auth_token
    redirect_to root_url, :notice => "Logged in!"
  else
    flash.now.alert = "Invalid username or password"
    render "new"
  end
end

#destroyObject



20
21
22
23
# File 'app/controllers/cargo_wiki/sessions_controller.rb', line 20

def destroy
  cookies.delete(:auth_token)
  redirect_to root_url, :notice => "Logged out!"
end

#newObject



3
4
5
6
7
# File 'app/controllers/cargo_wiki/sessions_controller.rb', line 3

def new
  if signed_in?
    redirect_to root_url, :alert => "You're already logged in"
  end
end