public async Task <SignInResponse> SetPassword([FromBody] SetPasswordRequest model) { var user = await _userManager.FindByIdAsync(model.UserId); if (user == null) { throw new BadRequestException("USER_NOT_FOUND"); } if (user.SecurityUser.IsInvitationAccepted) { throw new BadRequestException("ALREADY_ACCEPTED"); } var resetPasswordResult = await _userManager.SetPassworForInvitationdAsync(user, model.Code, model.Password); if (!resetPasswordResult.Succeeded) { throw new BadRequestException("TOKEN_IS_INVALID"); } var result = _signInResponseProvider.Get(user, false); await _userToSService.AcceptAsync(user.SecurityUser.Id); await _setInvitationAcceptedService.SetInvitationAccepted(user.SecurityUser.Id); return(result); }
public async Task <Guid> Register(CompanyRegisterRequest request) { var user = _companyRegisterRequestToUserConverter.Convert(request); using (var context = _contextFactory()) using (var userManager = _userManagerFactory()) { await userManager.CreateAsync(user, request.Password); // TODO that is workarond for usermanager bug. Without it roles are not loaded correctly. That could be fixed in the future context.UserRoles.AddRange( new List <UserRole> { new UserRole { Role = await context.Roles.FindAsync(UserRoles.CompanyAdministrator.RoleId), UserId = user.Id }, new UserRole { Role = await context.Roles.FindAsync(UserRoles.Employee.RoleId), UserId = user.Id }, }); context.Attach(user); await context.SaveChangesAsync(); await _companyRegisterEmailNotificationService.SendAsync(user); await _companyRegisterInternalEmailNotificationService.SendAsync(user); await _userToSService.AcceptAsync(user.SecurityUser.Id); return(user.Id); } }
public async Task Accept(bool accepted) { if (!accepted) { throw new BadRequestException("MUST_BE_ACCEPTED"); } var securityUserId = await _currentSecurityUserProvider.GetSecurityUserIdAsync(User); await _userToSService.AcceptAsync(securityUserId); }