简体   繁体   English

使用 angular firebase 将电子邮件发送到不同的电子邮件以验证注册

[英]Send email to different email to verify registration using angular firebase

I was able to verify user email before registration.我能够在注册前验证用户电子邮件。 But I want to receive verification email to my email address to complete the registration process.但我想通过我的电子邮件地址接收验证电子邮件以完成注册过程。 I want to get notification to my email address and after my approval only registration process completes.我想收到我的电子邮件地址的通知,在我批准后,仅注册过程完成。 I have check email verification: auth-service.ts我有支票电子邮件验证: auth-service.ts

 async SignIn(email,password)
    {
     const loading =await this.LoadingCtrl.create({
       message:'Authenticating..',
       spinner:"crescent",
       showBackdrop:true
     });
     loading.present();
     this.afauth.setPersistence(firebase.default.auth.Auth.Persistence.LOCAL)
     .then(()=>{
       this.afauth.signInWithEmailAndPassword(email,password)
       .then((data)=>{
         if(!data.user.emailVerified){
           loading.dismiss();
           this.toast('Please check your credentials','warning');
           this.afauth.signOut();
         }else{
           loading.dismiss();
           this.router.navigate(['/home']);
         }
       })
       .catch(error=>{
         loading.dismiss();
         this.toast(error.message,'danger');
       })
     })
     .catch(error=>{
       loading.dismiss();
       this.toast(error.message,'danger');
     });
    } 

to register:注册:

async register(){
    if(this.firstname && this.lastname && this.email && this.password){
      const loading =await this.loadingCtrl.create({
        message:'Processing...',
        spinner:'crescent',
        showBackdrop:true
      });
      loading.present();
      
      this.afauth.createUserWithEmailAndPassword(this.email,this.password)
      .then((data)=>{
        data.user.sendEmailVerification();
        this.afs.collection('user').doc(data.user.uid).set({
          'userId':data.user.uid,
          'userEmail':this.email,
          'userFirstname':this.firstname,
          'userLastname':this.lastname
        })
        .then(()=>{
          loading.dismiss();
          this.toast('Registration Success','success');
          this.router.navigate(['/login']);
        })
        .catch(error=>{
          loading.dismiss();
          this.toast(error.message,'danger')
        })
      })
    }
  }

It sounds like you want to approve that users can use your app, which is different from allowing them to verify their own email address.听起来您想批准用户可以使用您的应用程序,这与允许他们验证自己的电子邮件地址不同。

While this is a valid use-case, Firebase Authentication doesn't have built-in functionality for this use-case.虽然这是一个有效的用例,但 Firebase 身份验证没有针对此用例的内置功能。

Firebase Authentication only deals with the authentication part, so allowing the user to provide their credentials - and verifying those credentials. Firebase 身份验证仅处理身份验证部分,因此允许用户提供其凭据 - 并验证这些凭据。 To only allow users with a verified email address, or users that you've approved, to use the app is authorization and is part of the application logic you'll have to build yourself.仅允许具有经过验证的电子邮件地址的用户或您已批准的用户使用该应用程序是授权,并且是您必须自己构建的应用程序逻辑的一部分。

For allowing only approved users access to the app/data, the common process is:为了只允许批准的用户访问应用程序/数据,常见的过程是:

  1. Create a list of approved users in the database, or add a isApproved field to the profile document you already have that the users can't set themselves.在数据库中创建已批准用户的列表,或将isApproved字段添加到您已经拥有的用户无法自行设置的配置文件文档中。
  2. In your application code after authenticating the user, check if they are in the list of allowed users and only allow them to continue to the next screen in the app if they are.在对用户进行身份验证后,在您的应用程序代码中,检查他们是否在允许的用户列表中,如果是,则只允许他们继续进入应用程序的下一个屏幕。
  3. If your database security rules only allow users to read data if they are on the list of approved users.如果您的数据库安全规则仅允许用户在批准的用户列表中读取数据。
  4. In any custom backend code you have, check whether the user is approved before executing their request.在您拥有的任何自定义后端代码中,请在执行请求之前检查用户是否获得批准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM