Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password Reset support #45

Open
ike opened this issue Jun 19, 2017 · 1 comment
Open

Password Reset support #45

ike opened this issue Jun 19, 2017 · 1 comment

Comments

@ike
Copy link
Contributor

ike commented Jun 19, 2017

Poop, the password reset section in ember-authenticate-me wasn't reusable. Can we make it reusable in the library instead? Something like this in addon/controllers/reset-password should work:

import Ember from 'ember';
import getConfig from 'ember-authenticate-me/configuration';

export function resetPassword(error) {
      const emberAuthenticateMeConfig = getConfig();
      const PASSWORD_RESET_URI = emberAuthenticateMeConfig.passwordResetUri ||
        '/api/password_resets';

      if (!error) {
        return new Ember.RSVP.Promise((resolve, reject) => {
          return Ember.$.ajax({
            type: "PUT",
            url: [PASSWORD_RESET_URI, this.get('token')].join('/'),

            data: {
              password: this.get('password'),
              password_confirmation: this.get('password_confirmation')
            },

            success(/*data*/){
              resolve(...arguments);
            },

            error(err/*, text*/) {
              reject(...arguments);
            }
          });
        });
      }
}

Then in both the addon controller and in your code, it could be used like this:

import { resetPassword } from 'ember-authenticate-me/controllers/reset-password';

...

export default Ember.Component.extend({
  ...
  actions: {
    ...
    forgotPassword() {
      return resetPassword(this.get('errors')).then((/*data*/) => {
        this.set('requestSent', true);
      });
    }
  }
});

The catch part of the promise will work too. Let me know if that isn't clear.

@Samsinite
Copy link
Contributor

@ike I believe I helped this get fixed with you for wholestory correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants