Skip to content

Instantly share code, notes, and snippets.

@tuxayo
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxayo/5ba28eae36440293c74e to your computer and use it in GitHub Desktop.
Save tuxayo/5ba28eae36440293c74e to your computer and use it in GitHub Desktop.
Voilà à peu près mon point de départ
def change_password
@user = User.find(params[:id])
authorize! :update, @user
@user_input = params.require(:user)
if (@user.valid_password?(@user_input['old_password']))
if (@user_input['password'] == @user_input['password_confirmation'])
@user.password = @user_input['password']
save_successful = @user.save
if save_successful
redirect_to root_path, :notice => 'Mot de passe mis à jour'
else
flash[:error] = t('activerecord.errors.models.user.attributes.password.too_short')
render :password
end
else
flash[:error] = t('messages.users.password_dont_match')
render :password
end
else
flash[:error] = t('messages.users.invalid_old_password')
render :password
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment