Class: HyperKittenMeow::Admin::SessionsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/hyper_kitten_meow/admin/sessions_controller.rb

Instance Method Summary collapse

Methods included from Concerns::Controllers::Admin::AdminController

#authorize, #current_user, #logged_in?

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/hyper_kitten_meow/admin/sessions_controller.rb', line 9

def create
  permitted = params.require(:session).permit([:email, :password])
  user = User.find_by(email: permitted[:email].downcase)
  if user && user.authenticate(permitted[:password])
    # Log the user in and redirect to the user's show page.

    user.set_encrypted_remember_token!
    session[:user_id] = user.id
    cookies.permanent.signed[:user_id] = user.id
    cookies.permanent[:remember_token] = user.remember_token
    redirect_to admin_posts_path
  else
    flash.now[:error] = t("sessions.failed_login")
    render 'new'
  end
end

#destroyObject



26
27
28
29
30
31
# File 'app/controllers/hyper_kitten_meow/admin/sessions_controller.rb', line 26

def destroy
  session.delete(:user_id)
  cookies.delete(:user_id)
  cookies.delete(:remember_token)
  redirect_to root_url
end

#newObject



6
7
# File 'app/controllers/hyper_kitten_meow/admin/sessions_controller.rb', line 6

def new
end