【问题标题】:How to implement password reset in angularjs with UI router如何使用 UI 路由器在 angularjs 中实现密码重置
【发布时间】:2016-03-02 06:40:56
【问题描述】:

在我的 AngularJS 应用程序中,我使用 JWT 和 UI Router 实现了登录、注册和忘记密码功能。

当用户点击忘记密码时,将向用户发送一封电子邮件,其中包含重置密码的链接。我们如何将此链接映射到 AngularJS 应用程序中的特定状态(密码重置)?

密码重置链接的格式为http://myapp.com/reset/token。我还需要检索该令牌。

谢谢。

【问题讨论】:

  • 这实在是太宽泛了,无法合理回答,而且密码管理应该是服务器的责任,而不是客户端的责任。
  • 将来自服务器的 url 映射到密码重置页面是客户端的责任。我知道如何将状态映射到 url 等。但在这种情况下,我不知道如何将 URL 映射到特定状态。

标签: angularjs


【解决方案1】:

您可以在 https://github.com/meanjs/mean/ 中找到一个干净的实现(在这个 repo modules/users/client/config/users.client.routes.js)

在此示例中,重置 url 将类似于 localhost:3000/password/reset/:token

angular.module('users').config(['$stateProvider',
  function ($stateProvider) {
    // Users state routing
    $stateProvider
      .state('password', {
        abstract: true,
        url: '/password',
        template: '<ui-view/>'
      })
      .state('password.forgot', {
        url: '/forgot',
        templateUrl: 'modules/users/client/views/password/forgot-password.client.view.html'
      })
      .state('password.reset', {
        abstract: true,
        url: '/reset',
        template: '<ui-view/>'
      })
      .state('password.reset.invalid', {
        url: '/invalid',
        templateUrl: 'modules/users/client/views/password/reset-password-invalid.client.view.html'
      })
      .state('password.reset.success', {
        url: '/success',
        templateUrl: 'modules/users/client/views/password/reset-password-success.client.view.html'
      })
      .state('password.reset.form', {
        url: '/:token',
        templateUrl: 'modules/users/client/views/password/reset-password.client.view.html'
      });
  }
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多