public async Task <IFormResult> HandleAsync(DeleteRoleClaimEditModel request) { var role = await roleManager.Roles .Where(r => r.Id == request.RoleId) .Include(r => r.Claims) .SingleAsync(); var claim = role?.Claims .Single(r => r.Id == request.RoleClaimId) .ToClaim(); if (claim != null) { var result = await roleManager.RemoveClaimAsync(role, claim); return(result.Succeeded ? FormResult.Success : FormResult.Fail(result.Errors?.FirstOrDefault()?.Description ?? "Unable to delete role claim due to an error")); } var errorMessage = "Unable to delete role claim due to an error"; if (role is null) { errorMessage = "Unable to locate role to delete the requested role claim"; } else if (claim is null) { errorMessage = "Unable to locate role claim"; } return(FormResult.Fail(errorMessage)); }
public async Task <IFormResult> HandleAsync(AddUserEditModel registerEditModel) { var user = new User.Models.User { UserName = registerEditModel.Email, Email = registerEditModel.Email, }; var result = await userManager.CreateAsync(user, registerEditModel.Password); return(result.Succeeded ? FormResult.Success : FormResult.Fail(result.Errors.FirstOrDefault()?.Description ?? ACCOUNT_REGISTRATION_ERROR)); }
public async Task <IFormResult> HandleAsync(AddRoleClaimEditModel request) { var role = await roleManager.FindByIdAsync(request.RoleId.ToString()); if (role != null) { var claim = new Claim(request.Type, request.Value); await roleManager.AddClaimAsync(role, claim); return(FormResult.Success); } return(FormResult.Fail("Unable to add role claim")); }
public async Task <IFormResult> HandleAsync(EditRoleEditModel request) { var role = await roleManager.FindByIdAsync(request.RoleId.ToString()); if (role.Name != request.RoleName) { var result = await roleManager.SetRoleNameAsync(role, request.RoleName); return(result.Succeeded ? FormResult.Success : FormResult.Fail(result.Errors?.FirstOrDefault()?.Description ?? "Unable to set role name")); } return(FormResult.Success); }
public async Task <IFormResult> HandleAsync(DeleteRoleEditModel request) { var role = await roleManager.FindByIdAsync(request.RoleId.ToString()); if (role != null) { var result = await roleManager.DeleteAsync(role); if (result.Succeeded) { return(FormResult.Success); } return(FormResult.Fail(result.Errors?.FirstOrDefault()?.Description ?? "Unable to delete role due to an error")); } return(FormResult.Fail("Unable to locate and delete role")); }
public async Task <IFormResult> HandleAsync(AddRoleEditModel request) { var role = new Role { Name = request.RoleName }; var result = await roleManager.CreateAsync(role); if (result.Succeeded) { // Set the role id so we can pass it into the redirect // after the handler returns request.RoleId = role.Id; return(FormResult.Success); } return(FormResult.Fail(result.Errors?.FirstOrDefault()?.Description ?? "There was an error creating the role")); }
public async Task <IFormResult> HandleAsync(ConfirmPhoneNumberEditModel request) { var user = applicationContext.User; if (user != null) { var result = await userManager.VerifyChangePhoneNumberTokenAsync(user, request.SecurityCode, user.PhoneNumber); if (result) { user.PhoneNumberConfirmed = true; return(FormResult.Success); } return(FormResult.Fail("Invalid confirmation code")); } return(FormResult.Fail("Unable to confirm phone number due to an error")); }
public async Task <IFormResult> HandleAsync(AddPhoneNumberEditModel request) { var user = applicationContext.User; if (user != null) { user.PhoneNumber = request.PhoneNumber; user.PhoneNumberConfirmed = false; var code = await userManager.GenerateChangePhoneNumberTokenAsync(user, user.PhoneNumber); var subject = @"bitbyte.io - security code"; var message = $"Your security code is: {code}"; var result = await smsService.SendSmsMessageAsync(request.PhoneNumber, subject, message); if (result != null && result.MessageId.HasValue()) { return(FormResult.Success); } } return(FormResult.Fail("Unable to send sercurity code")); }