Open Closed

Tenant self registration admin role and email confirmation issue #7077


User avatar
0
franciscokadzi@gmail.com created
  • ABP Framework version: v7.4.2
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I have the following questions

  1. I have tenant self registration configured, but one thing we realised is that the admin role can be removed for the admin user created during the tenant self registration. Why is that possible? Is there a way to fix that? Each tenant should have at least one admin user.
  2. I need all users to verify their emails before they are able to login, but that does not work for tenant registration. New tenants do not get the email confirmation email. I came across this ticket https://support.abp.io/QA/Questions/5042/Send-email-to-tenant-admin-on-tenant-creation. Is that feature now available? If yes how do I get it to work? If not, is there a workaround for it?

4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    1. the admin role can be removed for the admin user created during the tenant self registration.

    Can you explain it in detail? And share some screenshots?

    Thanks.

    2. You can add an IDistributedEventHandler<TenantCreatedEto> on the template project to send the mail.

  • User Avatar
    0
    franciscokadzi@gmail.com created

    hi

    1. the admin role can be removed for the admin user created during the tenant self registration.

    Can you explain it in detail? And share some screenshots?

    In the image, the role of admin can be removed by the user. Is it not the case that there must always be at least one admin for a tenant?

    For the emailing confirmation issue, I tried doing this but got user does not exist error. Can you help with a detailed code on getting this to work please?

    public async Task HandleEventAsync(TenantCreatedEto eventData)
    {
        var user = await UserManager.FindByEmailAsync(Input.EmailAddress);
        var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
    
        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme);
        await _emailSender.SendAsync(Input.EmailAddress, "Email confirmation",
            $"Please confirm your email address by clicking the following link.<br> <a href='{callbackUrl}'>Confirm my email address</a>.");
    
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    In the image, the role of admin can be removed by the user. Is it not the case that there must always be at least one admin for a tenant?

    We don't limit this operation. You can customize it.

    For the emailing confirmation issue, I tried doing this but got user does not exist error.

    Please try to change the current tenant id.

    public async Task HandleEventAsync(TenantCreatedEto eventData)
    {
        using (CurrentTenant.Change(eventData.Id))
        {
            var user = await UserManager.FindByEmailAsync(Input.EmailAddress);
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user);
        
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme);
            await _emailSender.SendAsync(Input.EmailAddress, "Email confirmation",
                $"Please confirm your email address by clicking the following link.
         Confirm my email address.");
        }
    }
    
  • User Avatar
    0
    franciscokadzi@gmail.com created

    Hi thanks for the help. The user not found issue is resolved now. But I get new errors. I have tried several options including AccountAppService.SendEmailConfirmationTokenAsync but to no avail. The HandleEventAsync is currently in my TenantRegister.cshtml.cs file.

    Can you provide me with specifics on how to get this done. Possibly provide me with the complete code and where exactly to place it, in order for it to work.

    I tried this option also

    public async Task HandleEventAsync(TenantCreatedEto eventData)
    {
        using (CurrentTenant.Change(eventData.Id))
        {
            var tenantEmail = eventData.Properties.GetOrDefault("AdminEmail");
            var user = await UserManager.FindByEmailAsync(tenantEmail);
    
    
            var emailArgs = new SendEmailConfirmationTokenDto
            {
                AppName = "MVC",
                ReturnUrl = ReturnUrl,
                ReturnUrlHash = ReturnUrlHash,
                UserId = user.Id,
            };
    
            await AccountAppService.SendEmailConfirmationTokenAsync(emailArgs);
    
        }
    }
    

    but I get NullReferenceException: Object reference not set to an instance of an object.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11