Class: Authorio::SessionsController

Inherits:
AuthorioController show all
Defined in:
app/controllers/authorio/sessions_controller.rb

Instance Method Summary collapse

Methods inherited from AuthorioController

#authorized?, #current_user, #index, #logged_in?, #profile_url, #rememberable?, #user_scope_description, #user_session

Instance Method Details

#createObject

POST /session



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

def create
  user = User.find_by_username! auth_user_params[:username]
  raise Exceptions::InvalidPassword unless user.authenticate(auth_user_params[:password])

  write_session_cookie(user) if auth_user_params[:remember_me]
  # Even if we don't have a permanent remember-me session, we make a temporary session
  session[:user_id] = user.id
  redirect_to edit_user_path(user)
rescue Exceptions::InvalidPassword
  redirect_back_with_error 'Incorrect password. Try again.'
end

#destroyObject

DELETE /session



24
25
26
27
28
29
30
31
# File 'app/controllers/authorio/sessions_controller.rb', line 24

def destroy
  reset_session
  if (cookie = cookies.encrypted[:user]) && (session = Session.find_by_cookie(cookie))
    cookies.delete :user
    session.destroy
  end
  redirect_to new_session_path
end

#newObject

GET /session/new



6
7
8
# File 'app/controllers/authorio/sessions_controller.rb', line 6

def new
  @session = Session.new(authorio_user: User.first)
end