Skip to content

Commit

Permalink
Catch SMTP Error to flash message if new user email send doesn't work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs-panda committed Sep 29, 2024
1 parent 0aff723 commit d385ce4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,21 @@ def create
save_worked = false
end
if save_worked
# @user.send_reset_password_instructions
flash[:success] = "Successfully created user."
redirect_to(users_path) && return
begin
@user.send_reset_password_instructions
flash[:success] = "Successfully created user."
redirect_to(users_path)
rescue StandardError => e
error_message = e.message
if error_message.include?("The from address does not match a verified Sender Identity")
flash[:success] = "Successfully created user but reset password instructions not sent:
Net::SMTPFatalError"
else
flash[:error] = "Failed to create user."
@user.destroy
end
redirect_to(users_path)
end
else
render action: "new"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def self.instructor_create(email, course_name)

User.assign_random_password user

# user.send_reset_password_instructions
user.send_reset_password_instructions
user
end

Expand Down

0 comments on commit d385ce4

Please sign in to comment.