javascript AngularJS 忘记密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32918788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 15:55:07  来源:igfitidea点击:

AngularJS Forgot password

javascriptangularjsnode.js

提问by Shane

I have a forgot password form, on which when the user enters an email it hits the backend and sends out an email link to user as below.

我有一个忘记密码的表单,当用户输入电子邮件时,它会点击后端并向用户发送电子邮件链接,如下所示。

enter image description here

在此处输入图片说明

The user clicks on the link, which invokes the back-end service. How can i control this url via angular? So, basically this calls a back-end resouce, but i want this url to be handled in front-end too.

用户点击链接,调用后端服务。我怎样才能通过 控制这个网址angular?所以,基本上这称为后端资源,但我希望这个 url 也能在前端处理。

If this question is not so clear, can anyone show me an example of forgot password implementation in AngularJS and NodJs or any backend.

如果这个问题不是很清楚,谁能给我看一个在 AngularJS 和 NodJs 或任何后端中实现忘记密码的例子。

回答by Raju Bera

if you can change the link in the email then change it in the following way:

如果您可以更改电子邮件中的链接,请按以下方式更改:

http://localhost:3000/#/resetpassword/<token>

Now in your angular route you need to listen to this route as following:

现在在您的角度路线中,您需要按照以下方式收听此路线:

angular.module('myApp', ['ngRoute'])

 .controller('ResetPasswordController', function($scope, $route, $routeParams, $location) {
     //password resetting functionality
 })
.config(function($routeProvider, $locationProvider) {
  $routeProvider
   .when('/resetpassword/:token', {
    templateUrl: 'reset.html',
    controller: 'ResetPasswordController',
    resolve: {
      // Call the backend service to check if the token is valid
      verifyToken: function($q, $route) {
        var deferred = $q.defer();
        $http({
          method: 'GET',
          url: '/reset/' + $route.current.params.token
        }).success(function (data) {
           deferred.resolve(data);
        }).error(function (msg) {
          deferred.reject(msg);
        });

        return deferred.promise;
      }
    }
  })
});