Class: Spree::Api::V2::Storefront::PasswordsController

Inherits:
BaseController
  • Object
show all
Includes:
Core::ControllerHelpers::Store
Defined in:
app/controllers/spree/api/v2/storefront/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/spree/api/v2/storefront/passwords_controller.rb', line 8

def create
  user = Spree.user_class.find_by(email: params[:user][:email])

  if user&.send_reset_password_instructions(current_store)
    head :ok
  else
    head :not_found
  end
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/spree/api/v2/storefront/passwords_controller.rb', line 18

def update
  user = Spree.user_class.reset_password_by_token(
    password: params[:user][:password],
    password_confirmation: params[:user][:password_confirmation],
    reset_password_token: params[:id]
  )

  if user.errors.empty?
    head :ok
  else
    render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity
  end
end