Class: Concen::SessionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/concen/sessions_controller.rb', line 11

def create
  user = User.where(:username => /#{params[:username]}/i).first

  if user && user.authenticate(params[:password])
    cookies.permanent[:auth_token] = user.auth_token
    redirect_to concen_root_path, :notice => "You have successfully signed in!"
  else
    flash.now.alert = "Invalid email or password"
    render "new"
  end
end

#destroyObject



23
24
25
26
# File 'app/controllers/concen/sessions_controller.rb', line 23

def destroy
  cookies.delete(:auth_token)
  redirect_to root_path, :notice => "You have successfully signed out!"
end

#newObject



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

def new
  if User.all.any?
    render
  else
    redirect_to new_concen_user_path
  end
end