Class: Whodat::SessionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #sign_in, #sign_out

Methods included from ApplicationHelper

#current_user, #user_signed_in?

Methods included from SessionsHelper

#create_session, #current_user, #destroy_session

Instance Method Details

#createObject



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

def create
  user = Whodat::User.find_by( email: session_params[:email])
  if user && user.authenticate(session_params[:password])
    create_session(user)
    flash[:notice] = "Welcome, #{user.name}!"
    redirect_to main_app.root_path
  else
    flash[:notice] = "Invalid email or password. Please try again."
    render :new
  end
end

#destroyObject



21
22
23
24
25
# File 'app/controllers/whodat/sessions_controller.rb', line 21

def destroy
  destroy_session(current_user)
  flash[:notice] = "You've been signed out, come back soon."
  redirect_to main_app.root_path
end

#newObject



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

def new
end