Class: Remotty::Users::PasswordsController

Inherits:
Devise::PasswordsController
  • Object
show all
Includes:
BaseController
Defined in:
app/controllers/remotty/users/passwords_controller.rb

Instance Method Summary collapse

Instance Method Details

#create {|resource| ... } ⇒ Object

POST /resource/password email주소를 이용해서 패스워드 변경 요청 메일을 발송함

return

  • success - no_content

  • failure - validation error message

Yields:

  • (resource)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/remotty/users/passwords_controller.rb', line 11

def create
  self.resource = resource_class.send_reset_password_instructions(resource_params)
  yield resource if block_given?

  if successfully_sent?(resource)
    render json: {
      msg: find_message("send_instructions")
    }
  else
    render_error 'VALIDATION_ERROR', resource.errors.full_messages.first
  end
end

#update {|resource| ... } ⇒ Object

PUT /resource/password 토큰을 이용한 패스워드 변경 성공시 자동으로 로그인을 시도하고 토큰을 생성함

return

  • success - 로그인 후 user with token json return

  • failure - unauthorized with error message

Yields:

  • (resource)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/remotty/users/passwords_controller.rb', line 32

def update
  self.resource = resource_class.reset_password_by_token(resource_params)
  yield resource if block_given?

  if resource.errors.empty?
    resource.unlock_access! if unlockable?(resource)
     resource_name, resource, :store => false

    token = resource.generate_auth_token!(auth_source)
    render json: resource.with_token(token)
  else
    render_error 'UNAUTHORIZED',
                 resource.errors.full_messages.first,
                 :unauthorized
  end
end