Class: Lines::SessionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

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

#destroyObject

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

#newObject

Renders form for creating a new article



12
13
# File 'app/controllers/lines/sessions_controller.rb', line 12

def new
end