Example #1
0
        public async Task <ApiResponse <bool> > Verify(Guid tcid, string token)
        {
            Guard.Against.NullOrWhiteSpace(token, nameof(token));
            Guard.Against.NullOrEmpty(tcid, nameof(tcid));

            var tenantContact = await _hostRepository.GetFirstAsync <TenantContact>(tc => tc.Id == tcid,
                                                                                    includeProperties : "Tokens");

            if (tenantContact == null)
            {
                return(ApiResponse <bool> .Error());  //ErrorProvider.GetError("no_tenant_contact")
            }

            var validToken = tenantContact.Tokens.FirstOrDefault(t => t.Value == token);

            if (validToken != null && !validToken.Valid)
            {
                return(ApiResponse <bool> .Error()); //ErrorProvider.GetError("token_issued")
            }

            var validDurationPassed = validToken.CreatedOn.AddHours(24) < DateTime.Now;

            if (validDurationPassed)
            {
                return(ApiResponse <bool> .Error()); // ErrorProvider.GetError("token_expired")
            }
            validToken.Valid             = false;
            tenantContact.EmailConfirmed = true;
            _hostRepository.Update(tenantContact);
            await _hostRepository.SaveAsync();

            await CreateTenantResources(tenantContact.Email, tenantContact.PasswordHash);

            return(ApiResponse <bool> .Success());
        }
Example #2
0
 public async Task <Tenant> GetTenantByHostname(string hostname)
 => await _hostRepository.GetFirstAsync <Tenant>(t => t.Host == hostname,
                                                 includeProperties : "TenantSetting,Responsibles.Tokens");