コード例 #1
0
        public async Task CompleteUser(Guid code, string email, string password, string passwordConfirm)
        {
            var pending = await _pendingIdentityRepository.GetAsync(code, email);

            if (pending is null)
            {
                _logger.LogWarning($"Pending user not found with code: {code} and email: {email}");
                throw new VmsException(Codes.InvalidCredentials, "The account registration has not been made.");
            }


            //TODO: make sure this check is done on creation of account pending.
            //var existing = await _identityRepository.GetByEmailAndRole(email, Roles.);
            //if (existing != null)
            //    throw new VmsException(Codes.EmailInUse, "Their has already been an account created with this email.");

            if (password != passwordConfirm)
            {
                throw new VmsException(Codes.InvalidCredentials, "The credentials are invalid.");
            }

            var pword      = _passwordManager.EncryptPassword(password);
            var numberCode = await GetCode(pending.BusinessId);

            var identity = new Domain.Identity(email, pword.Hash, pword.Salt, pending.Role, pending.BusinessId, numberCode);

            await _identityRepository.AddAsync(identity);

            await _pendingIdentityRepository.RemoveAsync(pending);

            _publisher.PublishEvent(new UserAccountCreated(identity.Id, identity.Email, identity.Code), RequestInfo.Empty);
        }
コード例 #2
0
ファイル: AdminIdentityService.cs プロジェクト: mumby0168/VMS
        public async Task DeleteBusinessAdmin(Guid id, Guid businessId)
        {
            var identity = await _identityRepository.GetAsync(id, businessId);

            if (identity != null)
            {
                await _identityRepository.RemoveAsync(identity);

                return;
            }

            var pending = await _pendingIdentityRepository.GetAsync(id, businessId);

            if (pending != null)
            {
                await _pendingIdentityRepository.RemoveAsync(pending);

                return;
            }

            _logger.LogWarning($"Admin with id: {id} could not be found to be deleted.");
            throw new VmsException(Codes.NoIdentityFound, "The admin could not be found to be deleted.");
        }