ストームパス + angularjs の電子メール検証ワークフローをセットアップしようとしています。メールに送信された確認リンクをクリックすると、にリダイレクトされhttp://localhost:3000/register/verify?sptoken=4rxDhXLpvcNj7AUzSvYIDL
ます。これは、チュートリアルによると予想される URLです。問題は、URL でユーザーを認証する必要があることです。ユーザーは、電子メールで検証された登録済み資格情報でログインした後にのみ認証されるため、これは自滅的です。
私が混乱したチュートリアルの 1 つのステップは、問題の原因である可能性があるのはAdd the sptoken Paremeterです。コントローラーのプロパティにパラメーターを追加するように指示'/register/verify?sptoken'
されています。angularジェネレーターによって作成されたコントローラーファイルは実質的に空であり、ルーティングに影響を与えるべきではないため、これは私には意味がありませんでした。代わりに、モジュールの状態に対してこれを行いました。url
emailVerification
emailVerification
$stateProvider
これに加えて、他の手順は簡単でした。sp: { authenticate: false }
状態の設定を試みましたemailVerification
が、これで問題は解決しませんでした。
Angular app.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'
});
});
register.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;