Sha256: 5a63eae4cd98c7cf85e8f54e8063d62cf768a9f356ecf5ec10c00924e2edf095
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
class SessionsController < ApplicationController skip_before_action :authenticate, only: %i[ new create ] before_action :set_session, only: :destroy def index @sessions = Current.<%= singular_table_name %>.sessions.order(created_at: :desc) end 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 %> && <%= singular_table_name %>.authenticate(params[:password]) <%- if two_factor? -%> if <%= singular_table_name %>.otp_secret signed_id = <%= singular_table_name %>.signed_id(purpose: :authentication_challenge, expires_in: 20.minutes) redirect_to new_two_factor_authentication_challenge_path(token: signed_id) else @session = <%= singular_table_name %>.sessions.create! cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } redirect_to root_path, notice: "Signed in successfully" end <%- else -%> @session = <%= singular_table_name %>.sessions.create! cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } redirect_to root_path, notice: "Signed in successfully" <%- end -%> else redirect_to sign_in_path(email_hint: params[:email]), alert: "That email or password is incorrect" end end def destroy @session.destroy; redirect_to(sessions_path, notice: "That session has been logged out") end private def set_session @session = Current.<%= singular_table_name %>.sessions.find(params[:id]) end end
Version data entries
3 entries across 3 versions & 1 rubygems