Sha256: ea352f9f7d09f1ad8ae6a9ad13b048697ad60bb22df1cc5932b7073b11028d32

Contents?: true

Size: 987 Bytes

Versions: 5

Compression:

Stored size: 987 Bytes

Contents

class SessionsController < ApplicationController
  skip_before_action :authenticate, except: :destroy

  def new
    @<%= singular_table_name %> = <%= class_name %>.new
  end

  def create
    @<%= singular_table_name %> = <%= class_name %>.find_by_email(params[:email])

    if @<%= singular_table_name %>.try(:authenticate, params[:password])
      if params[:remember_me] == "1"
        cookies.permanent[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
      else
        cookies[:session_token] = { value: @<%= singular_table_name %>.session_token, httponly: true }
      end

      redirect_to root_path, notice: "Signed in successfully"
    else
      redirect_to sign_in_path(email_hint: params[:email]), alert: "Invalid email or password"
    end
  end

  def destroy
    cookies.delete :session_token
    Current.<%= singular_table_name %>.regenerate_session_token
    redirect_to sign_in_path, notice: "Signed out successfully"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-0.0.5 lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt
authentication-zero-0.0.4 lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt
authentication-zero-0.0.3 lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt
authentication-zero-0.0.2 lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt
authentication-zero-0.0.1 lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt