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> 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 <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)); }
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.")); }