Class: ErpTechSvcs::UserController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ErpTechSvcs::UserController
- Defined in:
- app/controllers/erp_tech_svcs/user_controller.rb
Instance Method Summary collapse
Instance Method Details
#activate ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 3 def activate login_url = params[:login_url].blank? ? ErpTechSvcs::Config.login_url : params[:login_url] if @user = User.load_from_activation_token(params[:activation_token]) @user.activate! redirect_to login_url, :notice => 'User was successfully activated.' else redirect_to login_url, :notice => "Invalid activation token." end end |
#reset_password ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 31 def reset_password begin login_url = params[:login_url].blank? ? ErpTechSvcs::Config.login_url : params[:login_url] if user = (User.find_by_email(params[:login]) || User.find_by_username(params[:login])) new_password = Sorcery::Model::TemporaryToken.generate_random_token user.password_confirmation = new_password if user.change_password!(new_password) user.add_instance_attribute(:login_url,login_url) user.add_instance_attribute(:domain, params[:domain]) user.deliver_reset_password_instructions! = "Password has been reset. An email has been sent with further instructions to #{user.email}." success = true else = "Error re-setting password." success = false end else = "Invalid user name or email address." success = false end render :json => {:success => success,:message => } rescue Exception=>ex logger.error ex. logger.error ex.backtrace render :json => {:success => false,:message => 'Error sending email.'} end end |
#update_password ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 13 def update_password if user = User.authenticate(current_user.username, params[:old_password]) user.password_confirmation = params[:password_confirmation] if user.change_password!(params[:password]) success = true else #### validation failed #### = user.errors. success = false end else = "Invalid current password." success = false end request.xhr? ? (render :json => {:success => success, :message => }) : (render :text => ) end |