Class: Lines::SessionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Lines::SessionsController
- Defined in:
- app/controllers/lines/sessions_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Authenticate user and create a new session.
-
#destroy ⇒ Object
Destroys the current session (logout).
-
#new ⇒ Object
Renders form for creating a new article.
Instance Method Details
#create ⇒ Object
Authenticate user and create a new session.
16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/lines/sessions_controller.rb', line 16 def create user = Lines::User.find_by(email: params[:email]) if user && user.authenticate(params[:password]) session[:user_id] = user.id redirect_to admin_root_url, notice: "Logged in!" else flash.now.alert = "Email or password is invalid" render "new" end end |
#destroy ⇒ Object
Destroys the current session (logout)
28 29 30 31 |
# File 'app/controllers/lines/sessions_controller.rb', line 28 def destroy session[:user_id] = nil redirect_to root_url, notice: "Logged out!" end |
#new ⇒ Object
Renders form for creating a new article
12 13 |
# File 'app/controllers/lines/sessions_controller.rb', line 12 def new end |