Sha256: 422c863a819ef44aa7bb46000aac9bc36610723eab1079c2b3c041602c61ba8b

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

require_dependency "whodat/application_controller"

  module Whodat
    class SessionsController < ApplicationController

      def new
      end

      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

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

      private

      def session_params
        params.require(:session).permit(:name, :email, :password )
      end
    end
  end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whodat-1.0.1 app/controllers/whodat/sessions_controller.rb
whodat-1.0.0 app/controllers/whodat/sessions_controller.rb