我创建了一个表单“main.html#!/ register”,允许用户输入:firstname,lastname,email和login . 一旦所有输入的电子邮件验证都被发送,那么在验证电子邮件之前,他们无法访问“main.html#!/ success”页面 .
The good news is :如果他们尝试从登录页面进入访问页面而未确认电子邮件,则他们将无法访问 . The bad news is :注册后,如果他们进入"main.html#!/success",他们就能打开这个页面!!
使用案例:用户无法在没有注册的情况下访问“main.html#!/ success”用户无法从登录页面“main.html#!”访问“main.html#!/ success” . / login“,如果他还没有验证他的电子邮件问题是:用户可以在注册后立即访问”main.html#!/ success“而无需确认电子邮件 .
Question :如何使用电子邮件验证条件user.emailVerified和用户auth $ requireSignIn()来允许访问页面"main.html#!/success"?我已经放置了一个解决功能,以防止没有注册的任何访问 .
这是我的代码1 - 解析功能:身份验证是我创建的服务
when('/success', {
templateUrl: 'views/success.html',
controller: 'SuccessController',
resolve: {
currentAuth: function(Authentication) {
return Authentication.requireAuth();
} //currentAuth
}//resolve
}).
身份验证服务中的2代码
requireAuth: function() {
return auth.$requireSignIn();
}, //require Authentication
3-寄存器功能(在服务中)
register: function(user) {
auth.$createUserWithEmailAndPassword(
user.email,
user.password
).then(function(regUser) {
var regRef = ref.child('users')
.child(regUser.uid).set({
date: firebase.database.ServerValue.TIMESTAMP,
regUser: regUser.uid,
firstname: user.firstname,
lastname: user.lastname,
email: user.email
}); //userinfo
regUser.sendEmailVerification().then(function() {
// Email sent.
alert("your Email is verified: " + regUser.emailVerified) ;
}).catch(function(error) {
// An error happened.
alert(error);
});
}).catch(function(error) {
$rootScope.message = error.message;
}); //createUserWithEmailAndPassword
} //register
3-登录功能
login: function(user) {
auth.$signInWithEmailAndPassword(
user.email,
user.password
).then(function(user) {
if(user.emailVerified){
$location.path('/success');
}
else{
$rootScope.message= "Please validate your registration first : "+user.emailVerified;
}
}).catch(function(error) {
$rootScope.message = error.message;
}); //signInWithEmailAndPassword
}, //login
1 回答
您正试图在客户端强制执行此操作 . 相反,您应该对Firebase规则中经过验证的已登录用户实施访问权限 . 例如:
".write": "$user_id === auth.uid && auth.token.email_verified == true"