public async Task <AdminInviteResponse> InviteSuperAdminUser(AdminInviteRequest request) { var response = new AdminInviteResponse(); var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId); if (!currentUser.IsSuperAdmin) { response.SetInvalid(); return(response); } var user = await _userRepository.Select(x => x.Email == request.Email); if (user.IsExist()) { response.ErrorMessages.Add("user_already_invited"); response.Status = ResponseStatus.Invalid; return(response); } var invitedUser = _userFactory.CreateEntityFromRequest(request, currentUser, _cryptoHelper.GetSaltAsString()); var id = await _userRepository.Insert(request.CurrentUserId, invitedUser); if (id > 0) { // todo:send invite email response.Status = ResponseStatus.Success; return(response); } response.SetFailed(); return(response); }
public async Task <IActionResult> Invite(AdminInviteModel model) { if (model.IsNotValid()) { model.SetInputModelValues(); return(View(model)); } var request = new AdminInviteRequest(CurrentUser.Id, model.OrganizationUid, model.Email, model.FirstName, model.LastName); var response = await _adminService.InviteSuperAdminUser(request); if (response.Status.IsNotSuccess) { model.MapMessages(response); model.SetInputModelValues(); return(View(model)); } // todo : email gönderme senaryosu CurrentUser.IsActionSucceed = true; return(Redirect("/Admin/InviteDone/")); }
public User CreateEntityFromRequest(AdminInviteRequest request, CurrentUser currentUser, string salt) { var entity = new User(); entity.IsAdmin = true; entity.Email = request.Email; entity.FirstName = request.FirstName; entity.LastName = request.LastName; entity.Name = MapName(request.FirstName, request.LastName); entity.ObfuscationSalt = salt; entity.IsActive = true; entity.OrganizationId = currentUser.OrganizationId; entity.OrganizationUid = currentUser.OrganizationUid; entity.OrganizationName = currentUser.Organization.Name; entity.InvitedByUserId = currentUser.Id; entity.InvitedByUserUid = currentUser.Uid; entity.InvitedByUserName = currentUser.Name; entity.InvitedAt = DateTime.UtcNow; entity.InvitationToken = Guid.NewGuid(); return(entity); }
public static AdminInviteRequest GetAdminInviteRequest() { var request = new AdminInviteRequest(CurrentUserId, UidOne, EmailOne, StringOne, StringOne); return(request); }