Class: Stay::Users::PasswordsController
- Inherits:
-
Devise::PasswordsController
- Object
- Devise::PasswordsController
- Stay::Users::PasswordsController
- Defined in:
- app/controllers/stay/users/passwords_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /resource/password.
-
#new ⇒ Object
GET /resource/password/new.
-
#update ⇒ Object
PUT /resource/password.
Instance Method Details
#create ⇒ Object
POST /resource/password
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/stay/users/passwords_controller.rb', line 14 def create user = Stay::User.find_by(email: params[:user][:email]) source = request.headers['Content-Type'] == 'application/json' ? 'json' : 'html' user.update(source: source) if user.present? user.send_reset_password_instructions user.source == 'json' ? render(json: { success: true, message: 'Password reset instructions have been sent to your email.' }) : redirect_to(new_session_path(resource_name)) else user.source == 'json' ? render(json: { error: 'Email not found.' }) : redirect_to(new_session_path(resource_name)) end end |
#new ⇒ Object
GET /resource/password/new
9 10 11 |
# File 'app/controllers/stay/users/passwords_controller.rb', line 9 def new super end |
#update ⇒ Object
PUT /resource/password
34 35 36 37 38 39 40 41 |
# File 'app/controllers/stay/users/passwords_controller.rb', line 34 def update self.resource = resource_class.reset_password_by_token(params[:user] || params) if self.resource.errors.empty? self.resource.source == 'json' ? render(json: { success: true, message: "Password has been successfully reset" }) : redirect_to(new_session_path(resource_name)) else self.resource.source == 'json' ? render(json: { success: false, errors: self.resource.errors. }) : redirect_to(new_session_path(resource_name)) end end |