0

我正在尝试为stormpath + angularjs 设置电子邮件验证工作流程。单击发送到我的电子邮件的验证链接后,我被重定向到http://localhost:3000/register/verify?sptoken=4rxDhXLpvcNj7AUzSvYIDL. 根据教程,这是预期的 url 。问题是 url 需要对用户进行身份验证。这是弄巧成拙的,因为用户只有在使用通过电子邮件验证的注册凭据登录后才能获得身份验证。

教程中的一个步骤让我感到困惑,这可能是问题的原因是Add the sptoken Paremeter。它说将参数添加'/register/verify?sptoken'到控制器中的url属性中emailVerification。这对我来说没有意义,因为角度生成器创建的控制器文件实际上是空的,不应该影响路由,所以相反,我为模块中的emailVerification状态做了这个。$stateProvider

除此之外,其他步骤都很简单。我尝试设置sp: { authenticate: false }状态emailVerification,但这并没有解决问题。

角应用程序.js

'use strict';

/**
 * @ngdoc overview
 * @name clientApp
 * @description
 * # clientApp
 *
 * Main module of the application.
 */
angular
  .module('clientApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch',
    'xeditable',
    'ng-sortable',
    'ui.bootstrap',
    'stormpath',
    'stormpath.templates',
    'ui.router'
  ])
.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');

$stateProvider
.state('login', {
    url: '/login',
    templateUrl: 'views/login.html',
    controller: 'LoginCtrl'
})
.state('register', {
    url: '/register',
    templateUrl: 'views/register.html',
    controller: 'RegisterCtrl' 
})
.state('emailVerification', {
    url: '/register/verify?sptoken',
    templateUrl: 'views/emailverification.html',
    controller: 'EmailverificationCtrl'
})
.state('passwordResetRequest', {
    url: '/password/requestReset',
    templateUrl: 'views/passwordresetrequest.html',
    controller: 'PasswordResetRequestCtrl'
})
.state('passwordReset', {
    url: '/password/reset',
    templateUrl: 'views/passwordreset.html',
    controller: 'PasswordResetCtrl'
})
.state('main', {
    url: '/',
    templateUrl: 'views/main.html',
    controller: 'MainCtrl',
    controllerAs: 'main'
});
})
.run(function(editableOptions, $stormpath) {
    editableOptions.theme = 'bs3';
    $stormpath.uiRouter({
    loginState: 'login',
    defaultPostLoginState: 'main',
    forbiddenState: 'forbidden'
});
});

注册.html

<div class="container">
<div class='row'>
    <div class='col-xs-12'>
        <h3>Register</h3>
        <hr>
    </div>
</div>

<div sp-registration-form template-url='/views/customregistrationtpl.html'></div>
</div>

emailVerification.html

<div class="container">
  <div class="row">
    <div class="col-xs-12">
      <h3>Verify Your Account</h3>
      <hr>
    </div>
  </div>

  <div sp-email-verification></div>
</div>

服务器 app.js

var express = require('express');
var stormpathExpressSdk = require('stormpath-sdk-express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var app = express();

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());

// stormpath
var apiKey = require(path.join(process.env.HOME, '/.stormpath/apiKey'));
var spMiddleware = stormpathExpressSdk.createMiddleware({
  appHref: apiKey.href,
  apiKeyId: apiKey.id,
  apiKeySecret: apiKey.secret
});

// development error handler
if (app.get('env') === 'development') {

  // This will change in production since we'll be using the dist folder
  app.use(express.static(path.join(__dirname, '../client')));
  // This covers serving up the index page
  app.use(express.static(path.join(__dirname, '../client/.tmp')));
  app.use(express.static(path.join(__dirname, '../client/app')));

  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
if(app.get('env') === 'production') {

  // changes it to use the optimized version for production
  app.use(express.static(path.join(__dirname, '/dist')));

  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: {}
    });
  });
}

// attach stormpath routes
spMiddleware.attachDefaults(app);
app.use(spMiddleware.authenticate);

// Includes all routes
var router = require('./router')(app);

module.exports = app;
4

0 回答 0