I have developed a form "main.html#!/register" where users can input their first name, last name, email, and login details. Once these details are entered, an email verification is sent before they can proceed to the page "main.html#!/success".
The positive aspect is: If users try to access the page from the login page without confirming their email, they will be denied access. The downside is: Immediately after registering, users can navigate to "main.html#!/success" without verifying their email.
Use case: Users cannot reach "main.html#!/success" without completing registration. Users cannot access "main.html#!/success" from the login page "main.html#!/login" if they have not verified their email address. The issue lies in: Users can view "main.html#!/success" right after registering without confirming their email.
Question: How can I utilize the email verification condition user.emailVerified and the user authentication method $requireSignIn() to grant access to the page "main.html#!/success"? I have implemented a resolve function to restrict unauthorized entry.
Here are my code snippets: 1-resolve function: Authentication is a service I have established
when('/success', {
templateUrl: 'views/success.html',
controller: 'SuccessController',
resolve: {
currentAuth: function(Authentication) {
return Authentication.requireAuth();
} //currentAuth
}//resolve
}).
2-code within the Authentication service
requireAuth: function() {
return auth.$requireSignIn();
}, //require Authentication
3- the register function (located within the service)
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
4- login function
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