private async Task <ActionResult> RemoveCredentialInternal(User user, Credential cred, string message) { if (cred == null) { TempData["Message"] = Strings.CredentialNotFound; return(RedirectToAction("Account")); } // Count credentials and make sure the user can always login if (!cred.IsApiKey() && CountLoginCredentials(user) <= 1) { TempData["Message"] = Strings.CannotRemoveOnlyLoginCredential; } else { await AuthenticationService.RemoveCredential(user, cred); if (cred.IsPassword()) { // Clear the password login claim, to remove warnings. OwinContext.RemoveClaim(NuGetClaims.PasswordLogin); } // Notify the user of the change await MessageService.SendCredentialRemovedNoticeAsync(user, AuthenticationService.DescribeCredential(cred)); TempData["Message"] = message; } return(RedirectToAction("Account")); }
private async Task <JsonResult> RemoveApiKeyCredential(User user, Credential cred) { if (cred == null) { Response.StatusCode = (int)HttpStatusCode.NotFound; return(Json(Strings.CredentialNotFound)); } await AuthenticationService.RemoveCredential(user, cred); // Notify the user of the change await MessageService.SendCredentialRemovedNoticeAsync(user, AuthenticationService.DescribeCredential(cred)); return(Json(Strings.CredentialRemoved)); }