dei*_*tch 34 firebase firebase-security
问题说明了一切.在Firebase中,如何在用户创建帐户时确认电子邮件,或者就此而言,通过电子邮件重置密码.
我可以更广泛地问:有没有办法从Firebase发送电子邮件?例如通知等.这不是你通常会在客户端做的事情.
amc*_*mtt 47
更新
请注意,这绝不是处理电子邮件验证的非常安全的方式,而且由于Firebase现在支持电子邮件验证,因此可能应该使用它.
原始答案
我使用密码重置功能解决了电子邮件验证问题.
在帐户创建时,我向用户提供临时(随机生成)密码.然后我触发密码重置,它将通过链接向用户发送电子邮件.该链接将允许用户设置新密码.
要生成随机密码,您可以使用与此类似的代码:
function () {
var possibleChars = ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?_-'];
var password = '';
for(var i = 0; i < 16; i += 1) {
password += possibleChars[Math.floor(Math.random() * possibleChars.length)];
}
return password;
}
Run Code Online (Sandbox Code Playgroud)
请注意,这是在客户端上发生的,因此恶意用户可能会篡改您的逻辑.
Dar*_*ard 28
这需要在firebase之外完成.我将用户存储在/ users /并保持状态(PENDING,ACTIVE,DELETED).我有一个小服务,监视用户的PENDING状态并发送确认电子邮件.其中包含指向我已创建的用于将用户状态更新为ACTIVE的Web服务的链接.
Rob*_*rco 22
[Firebase工程师 - 更新2014-01-27]
Firebase Simple Login现在支持用于电子邮件/密码身份验证的密码重置.
每个简单登录客户端库都有一个新方法,用于为指定的电子邮件地址生成密码重置电子邮件 - sendPasswordResetEmail()
在Web和Android以及sendPasswordResetForEmail()
iOS上.
此电子邮件将包含一个临时令牌,用户可以使用该令牌登录其帐户并更新其凭据.此令牌将在24小时后或用户更改密码时到期,以先发生者为准.
另请注意,Firebase简单登录可以完全配置电子邮件模板以及发送地址(包括来自您的域的带有付费帐户的白标电子邮件).
要访问此功能,您需要将客户端库更新为v1.2.0
更高版本或更高版本.要获取最新版本,请访问https://www.firebase.com/docs/downloads.html.
另外,请访问https://www.firebase.com/docs/security/simple-login-email-password.html以获取最新的Firebase简单登录 - Web客户端文档.
截至2016年7月,您可能不必使用重置链接等.只需使用sendEmailVerification()
和applyActionCode
功能:
简而言之,在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)
})
};
}
])
Run Code Online (Sandbox Code Playgroud)
而且,通过上述方法,我认为无需在用户数据区域中保留用户电子邮件的验证.的applyActionCode
变化emailVerified
,以true
从false
.
用户使用本地帐户登录时,电子邮件验证非常重要.然而,对于许多社会认证,进入的emailVerified
将是true
已.
在使用Firebase 3.0 SDK进行电子邮件验证的文章中进行了详细说明
我解决这个问题的方法是使用Zapier,它有一个内置的firebase API.它检查添加的子元素的位置.然后它从新节点的数据中获取邮件地址和验证URL并将它们向前发送.该网址指向我的角度应用,该应用将用户电子邮件设置为已验证.
当我在firebase中托管我的应用程序文件时,我不需要处理在后台进行轮询的任何服务器或进程.
有一个延迟,但由于我在验证邮件之前没有阻止用户,所以没关系.Zapier有免费等级,因为我没有太多的流量,所以暂时是一个不错的解决方法.
归档时间: |
|
查看次数: |
27660 次 |
最近记录: |