如何使用Firebase电子邮件地址验证 [英] How to use Firebase email address verification
本文介绍了如何使用Firebase电子邮件地址验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人做过吗?
解决方案
总之,下面基本上就是这样,在AngularJS中: b $ b
// thecontroller.js
$ scope.sendVerifyEmail = function(){
console.log('Email sent,whaaaaam!');
currentAuth.sendEmailVerification();
}
//其中currentAuth来自类似这样的内容:
// routerconfig
....
templateUrl:'bla .html',
解析:{
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',函数(Auth){
return Auth。$ requireSignIn()
}]
}
})
//然后像digest所以每个词是什么样的声音:
$ b。控制器('emailVerifyController',['$ scope','$ stateParams','currentAuth','DatabaseRef',
函数$ scope,$ stateParams,currentAuth,DatabaseRef){
console.log(currentAuth);
$ scope.doVerify = function(){
firebase.auth()
.applyActionCode ($ stateParams.oobCode)
.then(函数(数据){
//更改emailVerified登录用户
console.log('验证发生');
})
.catch(function(error){
$ scope.error = error.message;
console.log(error.message,error.reason)
})
};
$ p
There appears to be an option to confirm email address in Firebase Web SDK3, see here (put your own project id in the link), but I can't find documentation for how to use it.
Anybody done it?
解决方案 In short, below is basically how you'll approach this, in AngularJS:
// thecontroller.js
$scope.sendVerifyEmail = function() {
console.log('Email sent, whaaaaam!');
currentAuth.sendEmailVerification();
}
// where currentAuth came from something like this:
// routerconfig
....
templateUrl: 'bla.html',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn() // this throws an AUTH_REQUIRED broadcast
}]
}
...
// intercept the broadcast like so if you want:
....
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
if (error === "AUTH_REQUIRED") {
$state.go('login', { toWhere: toState });
}
});
....
// So user receives the email. How do you process the `oobCode` that returns?
// You may do something like this:
// catch the url with its mode and oobCode
.state('emailVerify', {
url: '/verify-email?mode&oobCode',
templateUrl: 'auth/verify-email.html',
controller: 'emailVerifyController',
resolve: {
currentAuth:['Auth', function(Auth) {
return Auth.$requireSignIn()
}]
}
})
// Then digest like so where each term is what they sound like:
.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) {
// change emailVerified for logged in User
console.log('Verification happened');
})
.catch(function(error) {
$scope.error = error.message;
console.log(error.message, error.reason)
})
};
}
])
Explained more in the article Email Verification with Firebase 3.0 SDK
这篇关于如何使用Firebase电子邮件地址验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文