Sha256: 52b9a88bfa14ec4cc93aeab8f6ce6693024c232bc0481c88fe72ff0ae155751d
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 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 %>.try(:authenticate, params[:password]) @session = @<%= singular_table_name %>.sessions.create!(session_params) cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true } 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 @session.destroy redirect_to sessions_path, notice: "That session has been logged out" end private def set_session @session = Current.user.sessions.find(params[:id]) end def session_params { user_agent: request.user_agent, ip_address: request.remote_ip } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
authentication-zero-2.0.0 | lib/generators/authentication/templates/controllers/html/sessions_controller.rb.tt |