Class: UserTemplateTasks

Inherits:
Volt::Task
  • Object
show all
Defined in:
app/user_templates/tasks/user_template_tasks.rb

Instance Method Summary collapse

Instance Method Details

#send_reset_email(email) ⇒ Object



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
# File 'app/user_templates/tasks/user_template_tasks.rb', line 4

def send_reset_email(email)
  # Find user by e-mail
  Volt.skip_permissions do
    store._users.where(email: email).first.then do |user|
      if user
        reset_token = UserTemplates::PasswordResetToken.for_user(user.id)

        reset_url, _ = url_for(
          component: 'user_templates',
          controller: 'password_reset',
          action: 'index',
          user_id: user.id,
          token: reset_token
        )

        Mailer.deliver('user_templates/mailers/forgot',
          {to: email, name: user._name, reset_url: reset_url}
        )

        nil
      else
        raise "There is no account with the e-mail of #{email}."
      end
    end
  end
end