Class: Plum::SessionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/plum/sessions_controller.rb', line 9

def create
  user = Plum::User.find_by(email: params[:email])
  if user&.authenticate(params[:password])
    session[:plum_user_id] = user.id
    redirect_to cp_root_path, notice: "Welcome back!"
  else
    flash.now[:alert] = "Invalid email or password"
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



20
21
22
23
# File 'app/controllers/plum/sessions_controller.rb', line 20

def destroy
  session[:plum_user_id] = nil
  redirect_to , notice: "You have been logged out"
end

#newObject



5
6
7
# File 'app/controllers/plum/sessions_controller.rb', line 5

def new
  redirect_to cp_root_path if logged_in?
end