Class: KnockOnce::UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- KnockOnce::UsersController
- Includes:
- ActiveModel::SecurePassword
- Defined in:
- app/controllers/knock_once/users_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'app/controllers/knock_once/users_controller.rb', line 42 def create @user = User.new(user_params) if @user.save render json: @user else render json: @user.errors., status: :unprocessable_entity end end |
#destroy ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/knock_once/users_controller.rb', line 29 def destroy @user = current_user if @user.authenticate(params[:current_password]) if @user.destroy render json: :success else render json: @user.errors. end else render status: :unprocessable_entity, json: ['Current password is incorrect'] end end |
#show ⇒ Object
8 9 10 11 |
# File 'app/controllers/knock_once/users_controller.rb', line 8 def show @user = current_user render json: @user end |
#update ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/knock_once/users_controller.rb', line 13 def update @user = User.find_by_id(current_user.id) if @user.authenticate(params[:current_password]) if @user.update(user_params) render json: { user: @user, message: 'Your profile has been updated!' } else render json: @user.errors., status: :unprocessable_entity end else render status: :unprocessable_entity, json: ['Current password is incorrect'] end end |