public async Task <ActionResult> UpdateWithdrawSettings(UpdateWithdrawModel model) { if (!await IsSettingsUnlocked()) { return(JsonError()); } if (model.DisableConfirmation) { var twofactor = await UserManager.GetUserTwoFactorAsync(User.Identity.GetUserId(), TwoFactorComponent.Withdraw); if (twofactor == null || twofactor.Type == TwoFactorType.None) { return(JsonError(Resources.User.securityTfaEmailErrorMessage)); } } var result = await UserSecurityWriter.UpdateWithdrawSettings(User.Identity.GetUserId(), model); if (!result.Success) { return(Json(result)); } await UserSyncService.SyncUser(User.Identity.GetUserId()); return(Json(result)); }
public async Task <IWriterResult> DisableUser(string adminUserId, string userName) { var userId = ""; using (var context = DataContextFactory.CreateContext()) { var user = await context.Users.FirstOrDefaultNoLockAsync(u => u.UserName == userName).ConfigureAwait(false); if (user == null) { return(new WriterResult(false, "User Not Found")); } userId = user.Id; user.IsDisabled = true; user.SecurityStamp = Guid.NewGuid().ToString(); context.LogActivity(adminUserId, $"Disabling User {userName}"); await context.SaveChangesAsync().ConfigureAwait(false); } await UserSyncService.SyncUser(userId); return(new WriterResult(true, $"User '{userName}' Successfully Disabled.")); }
public async Task <ActionResult> UpdateApiSettings(UpdateApiModel model) { if (!ModelState.IsValid) { return(PartialView("_UpdateApi", model)); } if (!await IsSettingsUnlocked()) { ModelState.AddModelError("Error", Resources.User.securityUnlockTokenExpiredError); return(PartialView("_UpdateApi", model)); } var result = await UserSecurityWriter.UpdateApiSettings(User.Identity.GetUserId(), model); if (!ModelState.IsWriterResultValid(result)) { return(PartialView("_UpdateApi", model)); } await UserSyncService.SyncUser(User.Identity.GetUserId()); await ApiKeyStore.UpdateApiAuthKey(model); return(PartialView("_UpdateApi", model)); }
private ISyncService[] CreateSyncServices() { var userService = new UserSyncService(_logger); var orgService = new OrganizationSyncService(userService, _logger); var personService = new PersonSyncService(userService, _logger); var dealService = new DealSyncService(userService, _logger); var activityService = new ActivitySyncService(userService, _logger); var noteService = new NoteSyncService(userService, _logger); var orgRelationshipService = new OrganizationRelationshipSyncService(orgService, _logger); return(new ISyncService[] { userService, orgService, personService, dealService, activityService, noteService, orgRelationshipService, new ActivityFieldSyncService(_logger), new ActivityTypeSyncService(_logger), new PersonFieldSyncService(_logger), new DealFieldSyncService(_logger), new NoteFieldSyncService(_logger), new OrganizationFieldSyncService(_logger) }); }
public DealSyncService(UserSyncService userService, ILogger logger = null) { if (userService == null) { throw new ArgumentNullException(nameof(userService)); } _userService = userService; _logger = logger; }
public async Task <IWriterResult> ApproveChangeEmail(string userId, AdminChangeEmailApproveModel model) { var syncUserId = string.Empty; using (var context = DataContextFactory.CreateContext()) { if (model.Status == ApprovalQueueStatus.Pending) { return(new WriterResult(false, $"Unable to set item to {model.Status}.")); } var approval = await context.ApprovalQueue.FirstOrDefaultNoLockAsync(x => x.Id == model.ApprovalId && x.Type == ApprovalQueueType.ChangeEmail); if (approval == null) { return(new WriterResult(false, "Not Found.")); } if (approval.Status != Enums.ApprovalQueueStatus.Pending) { return(new WriterResult(false, $"Unable to approve {approval.Type} status is {approval.Status}.")); } if (approval.RequestUserId == userId) { return(new WriterResult(false, $"Another admin must approve this {approval.Type}.")); } var existing = await context.Users.FirstOrDefaultNoLockAsync(x => x.Email == approval.Data); if (existing != null && model.Status == ApprovalQueueStatus.Approved) { return(new WriterResult(false, $"Email '{approval.Data}' is already in use.")); } approval.Status = model.Status; approval.Message = model.Message; approval.ApproveUserId = userId; approval.Approved = DateTime.UtcNow; if (model.Status == ApprovalQueueStatus.Approved) { syncUserId = approval.DataUserId; approval.DataUser.Email = JsonConvert.DeserializeObject <AdminChangeEmailModel>(approval.Data).NewEmailAddress; } await context.SaveChangesAsync(); } await UserSyncService.SyncUser(syncUserId); return(new WriterResult(true, model.Status == ApprovalQueueStatus.Approved ? "Action approved, users email address has now been updated." : "Action Rejected, email change rejected.")); }
public async Task <IWriterResult> CreateVerification(string userId, UserVerificationModel model) { using (var context = DataContextFactory.CreateContext()) { var user = await context.Users.FirstOrDefaultNoLockAsync(x => x.Id == userId); if (user.VerificationLevel != VerificationLevel.Level1 && user.VerificationLevel != VerificationLevel.Legacy) { return(new WriterResult(false, $"Verification has already been submitted.")); } var verification = await context.UserVerification.FirstOrDefaultNoLockAsync(x => x.UserId == userId); if (verification != null) { return(new WriterResult(false, $"Verification has already been submitted.")); } verification = new Entity.UserVerification { UserId = userId, FirstName = model.FirstName, LastName = model.LastName, Birthday = model.Birthday, Gender = model.Gender, Address = model.Address, City = model.City, State = model.State, Postcode = model.Postcode, Country = model.Country, Identification1 = model.Identification1, Identification2 = model.Identification2, Timestamp = DateTime.UtcNow }; context.UserVerification.Add(verification); user.VerificationLevel = VerificationLevel.Level2Pending; await context.SaveChangesAsync(); } await UserSyncService.SyncUser(userId); return(new WriterResult(true, $"Successfully submitted verification information.")); }
public async Task <IWriterResult> ActivateUser(string adminUserId, AdminActivateUserModel model) { string userId = ""; EmailMessageModel emailModel = new EmailMessageModel(); using (var context = DataContextFactory.CreateContext()) { var user = await context.Users.FirstOrDefaultNoLockAsync(x => x.UserName == model.UserName); if (user == null) { return(new WriterResult(false, $"User '{model.UserName}' not found")); } if (user.EmailConfirmed) { return(new WriterResult(false, $"User '{model.UserName}' already activated")); } userId = user.Id; user.EmailConfirmed = true; context.LogActivity(adminUserId, $"Activating user {user.UserName}"); await context.SaveChangesAsync(); var emailParameters = new List <object> { model.UserName }; emailModel = new EmailMessageModel { BodyParameters = emailParameters.ToArray(), Destination = user.Email, EmailType = EmailTemplateType.AccountActivated }; } await UserSyncService.SyncUser(userId); await EmailService.SendEmail(emailModel); return(new WriterResult(true, $"Successfully activated {model.UserName} - Email sent.")); }
public async Task <IWriterResult> AdminApproveVerification(string userId, ApproveVerificationModel model) { using (var context = DataContextFactory.CreateContext()) { var approvalUser = await context.Users.FirstOrDefaultNoLockAsync(x => x.Id == userId); var verification = await context.UserVerification .Include(x => x.User) .FirstOrDefaultNoLockAsync(x => x.Id == model.VerificationId); if (verification == null) { return(new WriterResult(false, $"Verification not found.")); } verification.Approved = DateTime.UtcNow; verification.ApprovedBy = approvalUser.Id; verification.User.VerificationLevel = model.VerificationLevel; await context.SaveChangesAsync(); } await UserSyncService.SyncUser(userId); return(new WriterResult(true, $"Successfully approved {model.VerificationLevel} verification.")); }
/// <summary> /// Gets all users associated with sms postini account /// </summary> /// <returns>A array of valid UserRecords or Null</returns> public UserRecord[] GetUsers() { if (this.CheckAuthEmail() == false) { return null; } if (this.CheckAuthPassword() == false) { return null; } try { //Create an Instance of the authElement AuthElem authCredentials = new AuthElem(); // populate the ife authelement authCredentials.apiKey = this.strApiKey; authCredentials.email = this.strEmail; authCredentials.pword = this.strPassword; // Setup our WS request. GetUsersCriteria criteria = new GetUsersCriteria(); // Show every user in the account hierarchy this admin has permissions to view. criteria.InAccountOrgHierarchy = true; GetUsersControl control = new GetUsersControl(); // Return alias information for users. control.ReturnAliases = true; // Return API Attributes for users. control.ReturnAttributes = true; // Return approved sender addresses for users. control.ReturnApprovedSenderAddresses = true; // Return blocked sender addresses for users. control.ReturnBlockedSenderAddresses = true; // Retrieve users UserSyncService syncService = new UserSyncService(); UserRecord[] userRecords = syncService.GetUsers(authCredentials, criteria, control); return userRecords; } catch (System.Web.Services.Protocols.SoapException ex) { String realSoapExceptionName = ex.Detail.FirstChild.LocalName; String realSoapExceptionMessage = ex.Detail.FirstChild.InnerText; if(blnDebug) Console.WriteLine("Postinilib: GetUsers error, Soap Exception: " + realSoapExceptionName + " - " + realSoapExceptionMessage); return null; } catch (Exception ex) { if(blnDebug) Console.WriteLine("Postinilib: GetUsers error " + ex.Message); return null; } }
public async static Task SyncUsersAsync([TimerTrigger("0 * * * * *")] TimerInfo timerInfo, TextWriter log) { var dbContext = new ApplicationDbContext(); var userSyncService = new UserSyncService(dbContext, GetTenantAccessTokenAsync, log); await userSyncService.SyncAsync(); }