public async Task <AdminAcceptInviteResponse> AcceptSuperAdminUserInvite(AdminAcceptInviteRequest request) { var response = new AdminAcceptInviteResponse(); var user = await _userRepository.Select(x => x.InvitationToken == request.Token && x.Email == request.Email); if (user.IsNotExist()) { response.SetInvalidBecauseNotFound("user"); return(response); } if (await _organizationRepository.Any(x => x.Id == user.OrganizationId && !x.IsActive)) { response.SetInvalidBecauseNotFound("organization"); return(response); } if (user.InvitedAt.HasValue && user.InvitedAt.Value.AddDays(2) > DateTime.UtcNow) { user.FirstName = request.FirstName; user.LastName = request.LastName; user.PasswordHash = _cryptoHelper.Hash(request.Password, user.ObfuscationSalt); // todo:send welcome email //todo:uow var result = await _userRepository.Update(user.Id, user); if (result) { var organization = _cacheManager.GetCachedOrganization(user.OrganizationUid); organization.UserCount++; result = await _organizationRepository.Update(user.Id, organization); if (result) { _cacheManager.UpsertOrganizationCache(organization, _organizationFactory.MapCurrentOrganization(organization)); response.Status = ResponseStatus.Success; return(response); } } } response.SetFailed(); return(response); }
public Organization GetCachedOrganization(long organizationId) { var item = Get(CACHE_NAME_ORGANIZATION, organizationId.ToString()); if (item == null) { var organization = _organizationRepository.SelectById(organizationId).Result; if (organization.IsNotExist()) { return(null); } UpsertOrganizationCache(organization, _organizationFactory.MapCurrentOrganization(organization)); return(organization); } return((Organization)item.Item); }
public async Task <SignUpResponse> CreateOrganizationWithAdmin(SignUpRequest request) { var response = new SignUpResponse(); var user = await _userRepository.Select(x => x.Email == request.Email); if (user.IsExist()) { response.ErrorMessages.Add("email_already_exist"); response.Status = ResponseStatus.Invalid; return(response); } var organization = await _organizationRepository.Select(x => x.Name == request.OrganizationName); if (organization.IsExist()) { response.ErrorMessages.Add("organization_name_already_exist"); response.Status = ResponseStatus.Invalid; return(response); } organization = _organizationFactory.CreateEntityFromRequest(request, _cryptoHelper.GetKeyAsString(), _cryptoHelper.GetIVAsString()); var salt = _cryptoHelper.GetSaltAsString(); var passwordHash = _cryptoHelper.Hash(request.Password, salt); user = _userFactory.CreateEntityFromRequest(request, organization, salt, passwordHash); var english = await _languageRepository.Select(x => x.IsoCode2Char == "en"); user.LanguageId = english.Id; user.LanguageUid = english.Uid; user.LanguageName = english.Name; user.LanguageIconUrl = english.IconUrl; var loginLog = _userLoginLogFactory.CreateEntityFromRequest(request, user); var integration = _integrationFactory.CreateDefault(organization); var integrationClient = _integrationClientFactory.CreateEntity(integration); var project = _projectFactory.CreateDefault(organization); var(uowResult, insertedOrganization, insertedUser) = await _signUpUnitOfWork.DoWork(organization, user, loginLog, integration, integrationClient, project); if (uowResult) { // todo:send welcome email // todo:send email log _cacheManager.UpsertUserCache(insertedUser, _userFactory.MapCurrentUser(insertedUser)); _cacheManager.UpsertOrganizationCache(insertedOrganization, _organizationFactory.MapCurrentOrganization(insertedOrganization)); response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }