Class: Auth::PasswordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/auth/passwords_controller.rb

Instance Method Summary collapse

Methods included from Response

#json_response

Instance Method Details

#resetObject



18
19
20
21
22
# File 'app/controllers/auth/passwords_controller.rb', line 18

def reset
  current_user.send_reset_password_instructions

  render status: :ok
end

#tokenObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/auth/passwords_controller.rb', line 7

def token
  raw, enc = Devise.token_generator.generate(User, :reset_password_token)

  current_user.reset_password_token = enc
  current_user.reset_password_sent_at = Time.now.utc

  current_user.save(validate: false)

  render json: { token: raw }, status: :ok
end

#unknownObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/auth/passwords_controller.rb', line 24

def unknown
  params.require(:email)

  user = User.find_by(email: params[:email])

  render status: :ok and return if user.nil?

  user.send_reset_password_instructions

  render status: :ok
end

#updateObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/auth/passwords_controller.rb', line 36

def update
  params.require(%i[reset_password_token password password_confirmation])

  user = User.reset_password_by_token(params)

  render status: :ok and return if user.errors.empty?

  render json: user.errors, status: :unprocessable_entity
end