Class: Users::ConfirmationsController

Inherits:
Devise::ConfirmationsController
  • Object
show all
Defined in:
app/controllers/users/confirmations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createJson

Returns Json that contains wheter the email confirmation was sent or not. If it is not successful, it returs an error message.

Examples:

# Executing this controller's action from javascript's frontend
let email = '[email protected]';
let data = {
    user: {
        email: email
    }
};
this.http.post('127.0.0.1/conformation', data);


58
59
60
61
62
63
64
65
66
# File 'app/controllers/users/confirmations_controller.rb', line 58

def create
    super do |resource|
        if successfully_sent?(resource)
            return respond_with_successful
        else
            return respond_with_error(resource.errors.full_messages.to_sentence)
        end
    end
end

#showObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/users/confirmations_controller.rb', line 4

def show

    # delete all previus messages
    flash.clear

    # get the confirmation token sent through get params
    token = params[:confirmation_token]

    # validate that token were sent
    if token.blank?
        return flash[:danger] = I18n.t("core.users/confirmations.messages_warning_invalid_token")
    end

    # check if token belongs to a unconfirmed user
    user = Lesli::User.find_by(:confirmation_token => token, :confirmed_at => nil)

    # validate that user were found
    if user.blank?
        return flash[:danger] = I18n.t("core.users/confirmations.messages_warning_invalid_token")
    end

    # register a log with a validation atempt for the user
    activity = user.activities.create({ title: "user_confirmation", description: "Confirmation process started" })
    

    registration_operator = LesliShield::UserRegistrationOperator.new(user)

    # confirm the user
    registration_operator.confirm

    # let the user knows that the confirmation is done
    flash[:success] = I18n.t("core.users/confirmations.messages_success_email_updated")
    
    # if new account, launch account onboarding in another thread, 
    # so the user can continue with the registration process
    registration_operator. if user..blank?
    #Thread.new { registration_operator.create_account } if user.account.blank?

end