diff options
author | jomo <github@jomo.tv> | 2016-12-14 23:57:08 +0100 |
---|---|---|
committer | jomo <github@jomo.tv> | 2016-12-14 23:57:08 +0100 |
commit | abeb405bab21bcd216fd9f9b894cd23fbc53a06b (patch) | |
tree | 4fd7944b2c472c64f8c79c56a44a7dffb0bc24e8 | |
parent | 381e6e8b5be7c9e9035ca360d04d8beac7fc9a1a (diff) |
rescue and fail gracefully when updated user can't be saved
saving the user can fail when the new ign or name are already assigned to a different user.
it's not worth implementing automatic correction because there can be multiple or even circular
'dependencies' of unique names that need to be changed
-rw-r--r-- | app/controllers/sessions_controller.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b58028a..784647c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -29,8 +29,11 @@ class SessionsController < ApplicationController if new_ign.present? && new_ign != user.ign user.name = new_ign if user.ign == user.name user.ign = new_ign - user.save - flash[:notice] += " Your name has been changed to #{new_ign}!" + if (user.save rescue false) + flash[:notice] += " Your name has been changed to #{new_ign}!" + else + flash[:alert] = "Failed to save your new username #{new_ign}! Please contact admins." + end end flash[:alert] = "Remember to validate your email! Your account may be deleted soon!" if !user.confirmed? |