Example #1
0
        public async Task PutResetPassword(string orgId, string id, [FromBody] OrganizationUserResetPasswordRequestModel model)
        {
            var orgGuidId = new Guid(orgId);

            // Calling user must have Manage Reset Password permission
            if (!_currentContext.ManageResetPassword(orgGuidId))
            {
                throw new NotFoundException();
            }

            // Get the calling user's Type for this organization and pass it along
            var orgType = _currentContext.Organizations?.FirstOrDefault(o => o.Id == orgGuidId)?.Type;

            if (orgType == null)
            {
                throw new NotFoundException();
            }

            var result = await _userService.AdminResetPasswordAsync(orgType.Value, orgGuidId, new Guid(id), model.NewMasterPasswordHash, model.Key);

            if (result.Succeeded)
            {
                return;
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            await Task.Delay(2000);

            throw new BadRequestException(ModelState);
        }
        public async Task PutResetPassword(string orgId, string id, [FromBody] OrganizationUserResetPasswordRequestModel model)
        {
            var orgGuidId = new Guid(orgId);

            // Calling user must have Manage Reset Password permission
            if (!_currentContext.ManageResetPassword(orgGuidId))
            {
                throw new NotFoundException();
            }

            var orgUser = await _organizationUserRepository.GetByIdAsync(new Guid(id));

            if (orgUser == null || orgUser.Status != OrganizationUserStatusType.Confirmed ||
                orgUser.OrganizationId != orgGuidId || string.IsNullOrEmpty(orgUser.ResetPasswordKey) ||
                !orgUser.UserId.HasValue)
            {
                throw new BadRequestException("Organization User not valid");
            }

            var user = await _userService.GetUserByIdAsync(orgUser.UserId.Value);

            if (user == null)
            {
                throw new NotFoundException();
            }


            var result = await _userService.AdminResetPasswordAsync(user, model.NewMasterPasswordHash, model.Key);

            if (result.Succeeded)
            {
                return;
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            await Task.Delay(2000);

            throw new BadRequestException(ModelState);
        }