2012-05-02 10:18:07 +01:00
|
|
|
class Users::SettingsController < Users::BaseController
|
2012-10-03 17:38:42 +01:00
|
|
|
include AvatarHelper
|
2014-11-13 21:41:07 +00:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :set_current_user
|
2015-04-06 23:54:16 +01:00
|
|
|
before_action -> { authorize @user, :update? }
|
2012-05-02 10:18:07 +01:00
|
|
|
|
|
|
|
def profile
|
2014-03-17 17:01:17 +00:00
|
|
|
if request.patch?
|
2012-05-02 10:18:07 +01:00
|
|
|
send_confirmation = params[:user][:email] != @user.email
|
2015-05-26 22:48:22 +01:00
|
|
|
if @user.update_without_password(user_params)
|
2012-10-03 17:38:42 +01:00
|
|
|
update_avatar(@user, params)
|
2012-05-02 10:18:07 +01:00
|
|
|
if send_confirmation
|
2013-03-01 11:33:31 +00:00
|
|
|
@user.confirmed_at = @user.confirmation_sent_at = nil
|
2012-05-02 10:18:07 +01:00
|
|
|
@user.send_confirmation_instructions
|
|
|
|
end
|
|
|
|
flash[:notice] = t('flash.user.saved')
|
2015-02-10 22:08:39 +00:00
|
|
|
redirect_to profile_settings_path and return
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
2015-02-10 22:08:39 +00:00
|
|
|
flash[:error] = t('flash.user.save_error')
|
|
|
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-16 18:30:40 +01:00
|
|
|
def reset_auth_token
|
|
|
|
@user.reset_authentication_token!
|
|
|
|
flash[:notice] = t("flash.user.reset_auth_token")
|
|
|
|
redirect_to profile_settings_path
|
|
|
|
end
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
def private
|
2014-03-17 17:01:17 +00:00
|
|
|
if request.patch?
|
2015-05-26 22:48:22 +01:00
|
|
|
if @user.update_with_password(user_params)
|
2012-05-02 10:18:07 +01:00
|
|
|
flash[:notice] = t('flash.user.saved')
|
2015-02-10 22:08:39 +00:00
|
|
|
redirect_to private_settings_path and return
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
2015-02-10 22:08:39 +00:00
|
|
|
flash[:error] = t('flash.user.save_error')
|
|
|
|
flash[:warning] = @user.errors.full_messages.join('. ')
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notifiers
|
2014-03-17 17:01:17 +00:00
|
|
|
if request.patch?
|
2015-05-27 23:32:41 +01:00
|
|
|
if @user.notifier.update_attributes(settings_notifier_params)
|
2012-05-02 10:18:07 +01:00
|
|
|
flash[:notice] = I18n.t("flash.settings.saved")
|
2015-02-10 22:08:39 +00:00
|
|
|
redirect_to notifiers_settings_path and return
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
2015-02-10 22:08:39 +00:00
|
|
|
flash[:error] = I18n.t("flash.settings.save_error")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def builds_settings
|
|
|
|
@user.builds_setting ||= @user.build_builds_setting
|
|
|
|
if request.patch?
|
2015-05-26 22:48:22 +01:00
|
|
|
if @user.builds_setting.update_attributes(user_builds_setting_params)
|
2015-02-10 22:08:39 +00:00
|
|
|
flash[:notice] = I18n.t("flash.settings.saved")
|
|
|
|
redirect_to builds_settings_settings_path and return
|
|
|
|
end
|
|
|
|
flash[:error] = I18n.t("flash.settings.save_error")
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
|
|
|
end
|
2014-03-14 22:54:04 +00:00
|
|
|
|
2015-05-26 22:48:22 +01:00
|
|
|
private
|
|
|
|
|
2015-05-27 23:32:41 +01:00
|
|
|
def settings_notifier_params
|
|
|
|
subject_params(SettingsNotifier)
|
|
|
|
end
|
|
|
|
|
2015-05-26 22:48:22 +01:00
|
|
|
def user_params
|
|
|
|
subject_params(User)
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_builds_setting_params
|
|
|
|
subject_params(UserBuildsSetting)
|
|
|
|
end
|
|
|
|
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|