Last active
May 26, 2020 10:15
-
-
Save pixeltrix/b408f9be9f7aaaebc4f2c7d6088cd039 to your computer and use it in GitHub Desktop.
Revisions
-
pixeltrix revised this gist
May 26, 2020 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ class UsersController < ApplicationController respond_to :json def update new_password = params[:user] && params[:user][:password] token = params[:authentication_token] if !new_password render_errors({"password"=>["can't be blank"]}.to_json) elsif (user = User.for_authentication_token(token)) if user.suspended? render_forbidden user.inactive_message else setter = PasswordSetter.new(user) setter.set_password new_password, self end else render_unauthorized end end end -
pixeltrix revised this gist
May 26, 2020 . 1 changed file with 30 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ class ActivationsController < ApplicationController respond_to :json def create new_password = params[:user] && params[:user][:password] token = params[:confirmation_token] if !new_password render_errors({"password"=>["can't be blank"]}.to_json) elsif (@user = User.for_confirmation_token(token)) if @user.try(:suspended?) render_unauthorized @user.inactive_message else setter = PasswordSetter.new(@user) setter.set_password new_password, self end else render_unauthorized end end def render_success @user.confirm! super end end -
pixeltrix created this gist
May 26, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ class PasswordSetter def initialize user @user = user end def set_password password, responder @user.password = password if @user.valid? @user.save! responder.render_success else errors = @user.errors.messages.to_json responder.render_errors errors end end end