public async Task<IActionResult> ViewGrantedApps(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeGrantInfo); var applications = await _dbContext.LocalAppGrant.Where(t => t.GatewayUserId == user.Id).ToListAsync(); return Json(new AiurCollection<AppGrant>(applications) { Code = ErrorType.Success, Message = "Successfully get all your granted apps!" }); }
public async Task <IActionResult> ResetTwoFAKey(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); // reset 2fa key await _userManager.SetTwoFactorEnabledAsync(user, false); await _userManager.ResetAuthenticatorKeyAsync(user); return(this.Protocol(ErrorType.Success, "Successfully reset the user's TwoFAKey!")); }
public async Task <JsonResult> ViewTwoFactorEnabled(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); bool enabled = user.TwoFactorEnabled; return(Json(new AiurValue <bool>(enabled) { Code = ErrorType.Success, Message = "Successfully get the target user's TwoFactorEnabled." })); }
public async Task <JsonResult> ViewHas2FAkey(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); bool key = user.Has2FAKey; return(Json(new AiurValue <bool>(key) { Code = ErrorType.Success, Message = "Successfully get the target user's Has2FAkey." })); }
public async Task <IActionResult> GetRecoveryCodes(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); await _userManager.SetTwoFactorEnabledAsync(user, true); var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); return(Json(new AiurCollection <string>(recoveryCodes.ToList()) { Code = ErrorType.Success, Message = "Sucess regenerate recovery Codes!." })); }
public async Task <IActionResult> View2FAKey(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); var(twoFAKey, twoFAQRUri) = await _twoFAHelper.LoadSharedKeyAndQrCodeUriAsync(user); return(Json(new View2FAKeyViewModel { TwoFAKey = twoFAKey, TwoFAQRUri = twoFAQRUri, Code = ErrorType.Success, Message = "Successfully set the user's TwoFAKey!" })); }
public async Task<IActionResult> ViewSocialAccounts(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ManageSocialAccount); var accounts = await _dbContext .ThirdPartyAccounts .Where(t => t.OwnerId == user.Id) .OrderByDescending(t => t.BindTime) .ToListAsync(); return Json(new AiurCollection<ThirdPartyAccount>(accounts) { Code = ErrorType.Success, Message = "Successfully get all your audit log!" }); }
public async Task<IActionResult> ViewAuditLog(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ViewAuditLog); var logs = await _dbContext .AuditLogs .Where(t => t.UserId == user.Id) .OrderByDescending(t => t.HappenTime) .ToListAsync(); return Json(new AiurCollection<AuditLogLocal>(logs) { Code = ErrorType.Success, Message = "Successfully get all your audit log!" }); }
public async Task <IActionResult> SetTwoFAKey(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); if (!user.Has2FAKey) { user.Has2FAKey = true; await _userManager.UpdateAsync(user); } var hasKey = user.Has2FAKey; return(Json(new AiurValue <bool>(hasKey) { Code = ErrorType.Success, Message = "Successfully set the user's TwoFAKey!" })); }
public async Task <IActionResult> DisableTwoFA(UserOperationAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangeBasicInfo); var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); if (true == disable2faResult.Succeeded) { user.TwoFactorEnabled = false; user.Has2FAKey = false; await _userManager.ResetAuthenticatorKeyAsync(user); await _userManager.UpdateAsync(user); } bool success = disable2faResult.Succeeded; return(Json(new AiurValue <bool>(success) { Code = ErrorType.Success, Message = "Successfully called DisableTwoFA method!" })); }