Search code examples
ruby-on-railsdevise

Forgot password Devise gem API


I have been using Devise gem in my application. I could able to configure devise sessions_controller to respond to both request from web and from mobile API call.

But now i am trying to see how i can use the Forgot Password option of Devise gem for Mobile API call. I can able to use the sign in with API as like below

curl -X POST 'http://localhost:3002/users/sign_in.json' -d 'user[email]=balan@test.com&user[password]=123456'

can i do the same with forgot password?


Solution

  • Got the answer.

    1) Create a custom action which recieves email as input

    2) Add below code

    @user = User.find_by_email("email@email.com")
    if @user.present?
     @user.send_reset_password_instructions
     render :text => "updated"
    else
         render :text => "no such email"
    end