Module: NoPassword::EmailAuthentication

Extended by:
ActiveSupport::Concern
Included in:
EmailAuthenticationsController
Defined in:
app/controllers/concerns/nopassword/email_authentication.rb

Overview

Controller concern that provides the email authentication flow. Include this in your controller to get the full authentication flow, or override individual methods to customize behavior.

Example:

class SessionsController < ApplicationController
include NoPassword::EmailAuthentication

def verification_succeeded(email)
  self.current_user = User.find_or_create_by(email: email)
  redirect_to dashboard_url
end
end

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/concerns/nopassword/email_authentication.rb', line 37

def create
  @authentication.email = authentication_params[:email]
  @authentication.return_url ||= after_authentication_url

  if @authentication.valid? && @authentication.challenge.save
    @authentication.save
    deliver_challenge(@authentication.challenge)
    render :create, status: :accepted
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



68
69
70
71
# File 'app/controllers/concerns/nopassword/email_authentication.rb', line 68

def destroy
  @authentication.delete
  redirect_to root_url
end

#newObject



34
35
# File 'app/controllers/concerns/nopassword/email_authentication.rb', line 34

def new
end

#showObject



50
51
52
# File 'app/controllers/concerns/nopassword/email_authentication.rb', line 50

def show
  # Confirmation page - user clicks link in email and lands here
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/concerns/nopassword/email_authentication.rb', line 54

def update
  if @verification.verify
    email = @authentication.email
    @authentication.delete
    verification_succeeded(email)
  elsif @verification.different_browser?
    verification_different_browser(@verification)
  elsif @verification.expired?
    verification_expired(@verification)
  else
    verification_failed(@verification)
  end
end