Class: Incline::SessionsController

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

Overview

A simple controller providing the login and logout methods for the application.

Instance Method Summary collapse

Instance Method Details

#createObject

POST /incline/login



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/incline/sessions_controller.rb', line 22

def create
  if (@user = Incline::UserManager.authenticate(params[:session][:email], params[:session][:password], request.remote_ip))
    if @user.activated?
      # log the user in.
       @user
      params[:session][:remember_me] == '1' ? remember(@user) : forget(@user)

      # show alerts on login.
      session[:show_alerts] = true

      redirect_back_or @user
    else
      flash[:safe_warning] = 'Your account has not yet been activated.<br/>Check your email for the activation link.'
      redirect_to main_app.root_url
    end
  else
    # deny login.
    flash.now[:danger] = 'Invalid email or password.'
    render 'new'
  end
end

#destroyObject

DELETE /incline/logout



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/incline/sessions_controller.rb', line 46

def destroy
  # Check to see if an external auth system should be used.
  auth_url = ::Incline::UserManager.end_external_authentication(request)
  if auth_url.blank?
    log_out if logged_in?
    redirect_to main_app.root_url
  else
    redirect_to auth_url
  end
end

#newObject

GET /incline/login



14
15
16
17
18
# File 'app/controllers/incline/sessions_controller.rb', line 14

def new
  # Before displaying the login form, make sure an external auth system shouldn't be used.
  auth_url = ::Incline::UserManager.begin_external_authentication(request)
  redirect_to auth_url unless auth_url.blank?
end