Sha256: 39b497e40abaf587489b0b56cc6944ece01e384186111dcb6e6be9139f2221c4

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

class Identity::EmailVerificationsController < ApplicationController
  skip_before_action :authenticate, only: :edit

  before_action :set_user, only: :edit

  def edit
    @user.update! verified: true
  end

  def create
    UserMailer.with(user: Current.user).email_verification.deliver_later
  end

  private
    def set_user
    <%- if code_verifiable? -%>
      verified_user = User.find_by(email: params[:email])

      if verified_user && verified_user.verification_code.value == params[:token]
        @user = verified_user
      else
        render json: { error: "That email verification code is invalid" }, status: :bad_request
      end
    <%- else -%>
      @user = User.where(email: params[:email]).find_signed!(params[:token], purpose: "email_verification/#{params[:email]}")
    rescue
      render json: { error: "That email verification link is invalid" }, status: :bad_request
    <%- end -%>
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authentication-zero-2.12.6 lib/generators/authentication/templates/controllers/api/identity/email_verifications_controller.rb.tt