Sha256: c4c16afe6e65564cfae51dc98e14e5f82c01bf70ac1744cc0622fcefcbe7619b

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

class Sessions::PasswordlessesController < ApplicationController
  skip_before_action :authenticate

  <%- if options.lockable? -%>
  before_action :require_lock, only: :create
  <%- end -%>
  before_action :set_user, only: :edit

  def new
  end

  def edit
    @session = @user.sessions.create!
    cookies.signed.permanent[:session_token] = { value: @session.id, httponly: true }

    revoke_tokens; redirect_to(root_path, notice: "Signed in successfully")
  end

  def create
    if @user = User.find_by(email: params[:email], verified: true)
      send_passwordless_email
      redirect_to sign_in_path, notice: "Check your email for sign in instructions"
    else
      redirect_to new_sessions_passwordless_path, alert: "You can't sign in until you verify your email"
    end
  end

  private
    def set_user
      token = SignInToken.find_signed!(params[:sid]); @user = token.user
    rescue StandardError
      redirect_to new_sessions_passwordless_path, alert: "That sign in link is invalid"
    end

    def send_passwordless_email
      UserMailer.with(user: @user).passwordless.deliver_later
    end

    def revoke_tokens
      @user.sign_in_tokens.delete_all
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.24 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.23 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.22 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.21 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt
authentication-zero-2.16.20 lib/generators/authentication/templates/controllers/html/sessions/passwordlesses_controller.rb.tt