parent
7b51d26295
commit
d5a469d736
@ -30,7 +30,7 @@ module Admin
|
||||
redirect_to(admin_reset_request_path) and return if user.nil?
|
||||
|
||||
user.setup_reset
|
||||
# TODO: user mailer deliver_now
|
||||
UserMailer.password_reset(user).deliver_now
|
||||
redirect_to admin_reset_request_path,
|
||||
success: "Reset request sent! Please check your email for instructions."
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Admin
|
||||
@user = User.create({ password: default_passwd }.merge(user_params.to_h))
|
||||
|
||||
if @user.persisted?
|
||||
# TODO: UserMailer.welcome(@user, default_passwd).deliver_now
|
||||
UserMailer.welcome(@user, default_passwd).deliver_now
|
||||
redirect_to admin_users_path, flash: { success: "Sucessfully created user #{@user.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to save user."
|
||||
|
12
app/mailers/user_mailer.rb
Normal file
12
app/mailers/user_mailer.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class UserMailer < ApplicationMailer
|
||||
def password_reset user
|
||||
@user = user
|
||||
mail to: user.email, subject: 'Password Reset'
|
||||
end
|
||||
|
||||
def welcome user, default_password
|
||||
@user = user
|
||||
@password = default_password
|
||||
mail to: user.email, subject: "Skill Assesment Acount"
|
||||
end
|
||||
end
|
@ -3,9 +3,6 @@
|
||||
%>
|
||||
|
||||
<h1>Password Reset</h1>
|
||||
|
||||
<%= raw(ap User.find_by(email: 'alan.admin@mailinator.com')) %>
|
||||
|
||||
<%= form_for :auth, url: admin_send_reset_path do |form| %>
|
||||
|
||||
<div class="form-group">
|
||||
|
13
app/views/user_mailer/password_reset.html.inky
Normal file
13
app/views/user_mailer/password_reset.html.inky
Normal file
@ -0,0 +1,13 @@
|
||||
<row>
|
||||
<columns class="email-body">
|
||||
<p>Hey there <%= @user.name %>,</p>
|
||||
<p>
|
||||
It looks like you want to reset your password?
|
||||
If not, it is safe to ignore this email.
|
||||
Otherwise go to the following link to enter a new password.
|
||||
</p>
|
||||
<p>
|
||||
<%= link_to nil, admin_reset_url(reset_token: @user.reset_token) %>.
|
||||
</p>
|
||||
</columns>
|
||||
</row>
|
7
app/views/user_mailer/password_reset.text.erb
Normal file
7
app/views/user_mailer/password_reset.text.erb
Normal file
@ -0,0 +1,7 @@
|
||||
Hey there <%= @user.name %>,
|
||||
|
||||
It looks like you want to reset your password?
|
||||
If not, it is safe to ignore this email.
|
||||
Otherwise go to the following link to enter a new password:
|
||||
|
||||
<%= admin_reset_url(reset_token: @user.reset_token) %>
|
15
app/views/user_mailer/welcome.html.inky
Normal file
15
app/views/user_mailer/welcome.html.inky
Normal file
@ -0,0 +1,15 @@
|
||||
<row>
|
||||
<columns class="email-body">
|
||||
<p>Hey there <%= @user.name %>,</p>
|
||||
<p>
|
||||
Looks like you now have access to the skills assessment app.
|
||||
We've given you a temporary password below. Please sign in an personalize it asap.
|
||||
</p>
|
||||
<p>
|
||||
Password: <%= @password%>
|
||||
</p>
|
||||
<p>
|
||||
<%= link_to nil, admin_url %>.
|
||||
</p>
|
||||
</columns>
|
||||
</row>
|
8
app/views/user_mailer/welcome.text.erb
Normal file
8
app/views/user_mailer/welcome.text.erb
Normal file
@ -0,0 +1,8 @@
|
||||
Hey there <%= @user.name %>,
|
||||
|
||||
Looks like you now have access to the skills assessment app.
|
||||
We've given you a temporary password below. Please sign in an personalize it asap.
|
||||
|
||||
Password: <%= @password %>
|
||||
|
||||
<%= admin_url %>.
|
@ -44,8 +44,9 @@ module Admin
|
||||
|
||||
test "should process a reset request" do
|
||||
user = users(:admin)
|
||||
post admin_send_reset_url, params: { auth: { email: user.email } }
|
||||
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
post admin_send_reset_url, params: { auth: { email: user.email } }
|
||||
end
|
||||
refute_equal user.reset_token, User.find(user.id).reset_token
|
||||
assert_redirected_to admin_reset_request_url
|
||||
assert_match(/request.*sent/i, flash[:success])
|
||||
|
@ -28,9 +28,11 @@ module Admin
|
||||
end
|
||||
|
||||
test "should post create" do
|
||||
assert_difference("User.count", 1) do
|
||||
post admin_create_user_url, params: { user:
|
||||
{ email: 'new.user@mailinator.com', name: 'New User', role: 'reviewer' } }
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
assert_difference("User.count", 1) do
|
||||
post admin_create_user_url, params: { user:
|
||||
{ email: 'new.user@mailinator.com', name: 'New User', role: 'reviewer' } }
|
||||
end
|
||||
end
|
||||
assert_redirected_to admin_users_url
|
||||
end
|
||||
|
12
test/mailers/previews/user_mailer_preview.rb
Normal file
12
test/mailers/previews/user_mailer_preview.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
||||
class UserMailerPreview < ActionMailer::Preview
|
||||
def password_reset
|
||||
user = User.find_by(email: 'alan.admin@mailinator.com')
|
||||
UserMailer.password_reset user
|
||||
end
|
||||
|
||||
def welcome
|
||||
user = User.find_by(email: 'alan.admin@mailinator.com')
|
||||
UserMailer.welcome user, '[default-password]'
|
||||
end
|
||||
end
|
20
test/mailers/user_mailer_test.rb
Normal file
20
test/mailers/user_mailer_test.rb
Normal file
@ -0,0 +1,20 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserMailerTest < ActionMailer::TestCase
|
||||
test "password_reset" do
|
||||
user = users(:admin)
|
||||
user.setup_reset
|
||||
mail = UserMailer.password_reset user
|
||||
|
||||
assert_equal [user.email], mail.to
|
||||
assert_match user.reset_token, mail.body.encoded
|
||||
end
|
||||
|
||||
test "welcome" do
|
||||
user = users(:admin)
|
||||
mail = UserMailer.welcome user, 'p0o9i8u7'
|
||||
|
||||
assert_equal [user.email], mail.to
|
||||
assert_match 'p0o9i8u7', mail.body.encoded
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user