firebase 发送和处理验证操作代码-AngularJS
示例
//thecontroller.js
$scope.sendVerifyEmail = function() {
console.log('Email sent, whaaaaam!');
currentAuth.sendEmailVerification();
}
//这里的currentAuth来自这样的东西:
//路由器配置
....
templateUrl: 'bla.html',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn() //这会引发AUTH_REQUIRED广播
}]
}
...
//如果需要,可以像这样拦截广播:
....
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
if (error === "AUTH_REQUIRED") {
$state.go('login', { toWhere: toState });
}
});
....
//因此,用户收到电子邮件。您如何处理返回的“oobCode”?
//您可以执行以下操作:
//用其模式和oobCode捕获URL
.state('emailVerify', {
url: '/verify-email?mode&oobCode',
templateUrl: 'auth/verify-email.html',
controller: 'emailVerifyController',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn()
}]
}
})
//然后像这样消化每个术语的含义:
.controller('emailVerifyController', ['$scope', '$stateParams', 'currentAuth', 'DatabaseRef',
function($scope, $stateParams, currentAuth, DatabaseRef) {
console.log(currentAuth);
$scope.doVerify = function() {
firebase.auth()
.applyActionCode($stateParams.oobCode)
.then(function(data) {
//更改已登录用户的emailVerified
toastr.success('Verification happened', 'Success!');
})
.catch(function(error) {
$scope.error = error.message;
toastr.error(error.message, error.reason, { timeOut: 0 });
})
};
}
])
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短