From 5325c65b880db94f5bbcfd1a3912a251f23f4ec1 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Tue, 19 Dec 2017 13:22:01 -0800 Subject: [PATCH] Replace identity code with built-in version on the templates --- build/dependencies.props | 1 + .../RazorPagesWeb-CSharp.csproj.in | 1 + .../StarterWeb-CSharp.csproj.in | 1 + .../.template.config/template.json | 40 +- .../Controllers/AccountController.cs | 27 +- .../Data/ApplicationDbContext.cs | 25 - .../Data/ApplicationUser.cs | 13 - ...000000000_CreateIdentitySchema.Designer.cs | 11 +- ...t.cs => IdentityDbContextModelSnapshot.cs} | 13 +- .../Extensions/EmailSenderExtensions.cs | 24 - .../Extensions/UrlHelperExtensions.cs | 38 -- .../Pages/Account/AccessDenied.cshtml | 10 - .../Pages/Account/AccessDenied.cshtml.cs | 16 - .../Pages/Account/ConfirmEmail.cshtml | 12 - .../Pages/Account/ConfirmEmail.cshtml.cs | 43 -- .../Pages/Account/ExternalLogin.cshtml | 33 -- .../Pages/Account/ExternalLogin.cshtml.cs | 137 ----- .../Pages/Account/ForgotPassword.cshtml | 26 - .../Pages/Account/ForgotPassword.cshtml.cs | 56 -- .../Account/ForgotPasswordConfirmation.cshtml | 10 - .../ForgotPasswordConfirmation.cshtml.cs | 16 - .../Pages/Account/Lockout.cshtml | 10 - .../Pages/Account/Lockout.cshtml.cs | 16 - .../Pages/Account/Login.cshtml | 82 --- .../Pages/Account/Login.cshtml.cs | 99 ---- .../Pages/Account/LoginWith2fa.cshtml | 41 -- .../Pages/Account/LoginWith2fa.cshtml.cs | 95 ---- .../Account/LoginWithRecoveryCode.cshtml | 29 - .../Account/LoginWithRecoveryCode.cshtml.cs | 88 --- .../Account/Manage/ChangePassword.cshtml | 35 -- .../Account/Manage/ChangePassword.cshtml.cs | 102 ---- .../Pages/Account/Manage/Disable2fa.cshtml | 25 - .../Pages/Account/Manage/Disable2fa.cshtml.cs | 61 --- .../Account/Manage/EnableAuthenticator.cshtml | 53 -- .../Manage/EnableAuthenticator.cshtml.cs | 138 ----- .../Account/Manage/ExternalLogins.cshtml | 52 -- .../Account/Manage/ExternalLogins.cshtml.cs | 108 ---- .../Manage/GenerateRecoveryCodes.cshtml | 25 - .../Manage/GenerateRecoveryCodes.cshtml.cs | 49 -- .../Pages/Account/Manage/Index.cshtml | 45 -- .../Pages/Account/Manage/Index.cshtml.cs | 128 ----- .../Pages/Account/Manage/ManageNavPages.cs | 34 -- .../Account/Manage/ResetAuthenticator.cshtml | 23 - .../Manage/ResetAuthenticator.cshtml.cs | 51 -- .../Pages/Account/Manage/SetPassword.cshtml | 35 -- .../Account/Manage/SetPassword.cshtml.cs | 93 ---- .../Manage/TwoFactorAuthentication.cshtml | 49 -- .../Manage/TwoFactorAuthentication.cshtml.cs | 51 -- .../Pages/Account/Manage/_Layout.cshtml | 23 - .../Pages/Account/Manage/_ManageNav.cshtml | 15 - .../Account/Manage/_StatusMessage.cshtml | 10 - .../Pages/Account/Manage/_ViewImports.cshtml | 1 - .../Pages/Account/Register.cshtml | 37 -- .../Pages/Account/Register.cshtml.cs | 91 ---- .../Pages/Account/ResetPassword.cshtml | 37 -- .../Pages/Account/ResetPassword.cshtml.cs | 87 --- .../Account/ResetPasswordConfirmation.cshtml | 10 - .../ResetPasswordConfirmation.cshtml.cs | 16 - .../Pages/Account/_ViewImports.cshtml | 1 - .../Pages/Shared/_LoginPartial.cshtml | 25 + .../Pages/_LoginPartial.cshtml | 29 +- .../Services/EmailSender.cs | 17 - .../Services/IEmailSender.cs | 12 - .../content/RazorPagesWeb-CSharp/Startup.cs | 24 +- .../.template.config/template.json | 11 +- .../Identity/Controllers/AccountController.cs | 480 ----------------- .../Identity/Controllers/ManageController.cs | 506 ------------------ .../Identity/Data/ApplicationDbContext.cs | 26 - .../Extensions/EmailSenderExtensions.cs | 18 - .../Extensions/UrlHelperExtensions.cs | 29 - .../ExternalLoginViewModel.cs | 15 - .../ForgotPasswordViewModel.cs | 15 - .../AccountViewModels/LoginViewModel.cs | 22 - .../LoginWith2faViewModel.cs | 22 - .../LoginWithRecoveryCodeViewModel.cs | 16 - .../AccountViewModels/RegisterViewModel.cs | 27 - .../ResetPasswordViewModel.cs | 27 - .../Areas/Identity/Models/ApplicationUser.cs | 13 - .../ChangePasswordViewModel.cs | 29 - .../EnableAuthenticatorViewModel.cs | 23 - .../ExternalLoginsViewModel.cs | 20 - .../GenerateRecoveryCodesViewModel.cs | 13 - .../Models/ManageViewModels/IndexViewModel.cs | 25 - .../ManageViewModels/RemoveLoginViewModel.cs | 14 - .../ManageViewModels/SetPasswordViewModel.cs | 24 - .../TwoFactorAuthenticationViewModel.cs | 17 - .../Areas/Identity/Services/EmailSender.cs | 17 - .../Areas/Identity/Services/IEmailSender.cs | 12 - .../Views/Account/AccessDenied.cshtml | 8 - .../Views/Account/ConfirmEmail.cshtml | 10 - .../Views/Account/ExternalLogin.cshtml | 32 -- .../Views/Account/ForgotPassword.cshtml | 25 - .../Account/ForgotPasswordConfirmation.cshtml | 8 - .../Identity/Views/Account/Lockout.cshtml | 8 - .../Areas/Identity/Views/Account/Login.cshtml | 87 --- .../Views/Account/LoginWith2fa.cshtml | 40 -- .../Account/LoginWithRecoveryCode.cshtml | 28 - .../Identity/Views/Account/Register.cshtml | 36 -- .../Views/Account/ResetPassword.cshtml | 36 -- .../Account/ResetPasswordConfirmation.cshtml | 8 - .../Identity/Views/Account/SignedOut.cshtml | 8 - .../Views/Manage/ChangePassword.cshtml | 35 -- .../Identity/Views/Manage/Disable2fa.cshtml | 24 - .../Views/Manage/EnableAuthenticator.cshtml | 52 -- .../Views/Manage/ExternalLogins.cshtml | 52 -- .../Views/Manage/GenerateRecoveryCodes.cshtml | 24 - .../Areas/Identity/Views/Manage/Index.cshtml | 45 -- .../Identity/Views/Manage/ManageNavPages.cs | 38 -- .../Views/Manage/ResetAuthenticator.cshtml | 21 - .../Identity/Views/Manage/SetPassword.cshtml | 34 -- .../Manage/TwoFactorAuthentication.cshtml | 49 -- .../Identity/Views/Manage/_Layout.cshtml | 23 - .../Identity/Views/Manage/_ManageNav.cshtml | 16 - .../Views/Manage/_StatusMessage.cshtml | 10 - .../Identity/Views/Manage/_ViewImports.cshtml | 1 - .../Areas/Identity/Views/_ViewImports.cshtml | 6 - .../Areas/Identity/Views/_ViewStart.cshtml | 3 - .../Controllers/AccountController.cs | 6 - ...000000000_CreateIdentitySchema.Designer.cs | 172 +++--- .../00000000000000_CreateIdentitySchema.cs | 16 +- .../IdentityDbContextModelSnapshot.cs} | 15 +- .../content/StarterWeb-CSharp/Startup.cs | 35 +- .../Views/Shared/_LoginPartial.cshtml | 13 +- test/Templates.Test/MvcTemplateTest.cs | 2 +- test/Templates.Test/RazorPagesTemplateTest.cs | 6 +- 125 files changed, 197 insertions(+), 4861 deletions(-) delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationUser.cs rename src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/{ApplicationDbContextModelSnapshot.cs => IdentityDbContextModelSnapshot.cs} (94%) delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/EmailSenderExtensions.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/UrlHelperExtensions.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ManageNavPages.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_Layout.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ManageNav.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_StatusMessage.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ViewImports.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/_ViewImports.cshtml create mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_LoginPartial.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Services/EmailSender.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Services/IEmailSender.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Controllers/AccountController.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Controllers/ManageController.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Data/ApplicationDbContext.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Extensions/EmailSenderExtensions.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Extensions/UrlHelperExtensions.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/ExternalLoginViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/ForgotPasswordViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/LoginViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/LoginWith2faViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/LoginWithRecoveryCodeViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/RegisterViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/AccountViewModels/ResetPasswordViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ApplicationUser.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/ChangePasswordViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/EnableAuthenticatorViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/ExternalLoginsViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/GenerateRecoveryCodesViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/IndexViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/RemoveLoginViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/SetPasswordViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Models/ManageViewModels/TwoFactorAuthenticationViewModel.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Services/EmailSender.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Services/IEmailSender.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/AccessDenied.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ConfirmEmail.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ExternalLogin.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ForgotPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ForgotPasswordConfirmation.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/Lockout.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/Login.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/LoginWith2fa.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/LoginWithRecoveryCode.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/Register.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ResetPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/ResetPasswordConfirmation.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Account/SignedOut.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/ChangePassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/Disable2fa.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/EnableAuthenticator.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/ExternalLogins.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/GenerateRecoveryCodes.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/Index.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/ManageNavPages.cs delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/ResetAuthenticator.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/SetPassword.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/TwoFactorAuthentication.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/_Layout.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/_ManageNav.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/_StatusMessage.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/Manage/_ViewImports.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/_ViewImports.cshtml delete mode 100644 src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Areas/Identity/Views/_ViewStart.cshtml rename src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/{Areas/Identity => }/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs (84%) rename src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/{Areas/Identity => }/Data/Migrations/00000000000000_CreateIdentitySchema.cs (95%) rename src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/{Areas/Identity/Data/Migrations/ApplicationDbContextModelSnapshot.cs => Data/Migrations/IdentityDbContextModelSnapshot.cs} (93%) diff --git a/build/dependencies.props b/build/dependencies.props index 780930ea69..0cc48dbc78 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -12,6 +12,7 @@ 2.1.0-preview1-27928 2.1.0-preview1-27928 2.1.0-preview1-27928 + 2.1.0-preview1-27928 2.1.0-preview1-27928 2.1.0-preview1-27928 2.1.0-preview1-27928 diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/RazorPagesWeb-CSharp.csproj.in b/src/Microsoft.DotNet.Web.ProjectTemplates/RazorPagesWeb-CSharp.csproj.in index 5421350f15..66cf730f3d 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/RazorPagesWeb-CSharp.csproj.in +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/RazorPagesWeb-CSharp.csproj.in @@ -27,6 +27,7 @@ + diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in b/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in index fa0418f000..cf039256e6 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in @@ -27,6 +27,7 @@ + diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json index 77119c9bf4..82587c523d 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json @@ -34,13 +34,19 @@ ] }, { - "condition": "(!IndividualAuth && !OrganizationalAuth)", + "condition": "(!OrganizationalAuth)", "exclude": [ "Controllers/**", "Pages/Account/**", "Pages/_LoginPartial.cshtml" ] }, + { + "condition": "(!IndividualLocalAuth)", + "exclude": [ + "Pages/Shared/_LoginPartial.cshtml" + ] + }, { "condition": "(!IndividualLocalAuth || UseLocalDB)", "exclude": [ @@ -50,32 +56,6 @@ { "condition": "(!IndividualLocalAuth)", "exclude": [ - "Pages/Account/ConfirmEmail.cshtml", - "Pages/Account/ConfirmEmail.cshtml.cs", - "Pages/Account/ExternalLogin.cshtml", - "Pages/Account/ExternalLogin.cshtml.cs", - "Pages/Account/ForgotPassword.cshtml", - "Pages/Account/ForgotPassword.cshtml.cs", - "Pages/Account/ForgotPasswordConfirmation.cshtml", - "Pages/Account/ForgotPasswordConfirmation.cshtml.cs", - "Pages/Account/Lockout.cshtml", - "Pages/Account/Lockout.cshtml.cs", - "Pages/Account/Login.cshtml", - "Pages/Account/Login.cshtml.cs", - "Pages/Account/LoginWith2fa.cshtml", - "Pages/Account/LoginWith2fa.cshtml.cs", - "Pages/Account/LoginWithRecoveryCode.cshtml", - "Pages/Account/LoginWithRecoveryCode.cshtml.cs", - "Pages/Account/Register.cshtml", - "Pages/Account/Register.cshtml.cs", - "Pages/Account/ResetPassword.cshtml", - "Pages/Account/ResetPassword.cshtml.cs", - "Pages/Account/ResetPasswordConfirmation.cshtml", - "Pages/Account/ResetPasswordConfirmation.cshtml.cs", - "Pages/Account/Manage/**", - "Extensions/EmailSenderExtensions.cs", - "Extensions/UrlHelperExtensions.cs", - "Services/**", "Data/**" ] }, @@ -97,6 +77,12 @@ "exclude": [ "Extensions/AzureAdB2C*.cs" ] + }, + { + "condition": "(!OrganizationalAuth || !IndividualB2CAuth)", + "exclude": [ + "Controllers/AccountController.cs" + ] } ] } diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Controllers/AccountController.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Controllers/AccountController.cs index b3551c6f0d..763b5ed702 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Controllers/AccountController.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Controllers/AccountController.cs @@ -7,14 +7,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; #endif -#if (IndividualLocalAuth) -using Microsoft.AspNetCore.Identity; -#endif using Microsoft.AspNetCore.Mvc; -#if (IndividualLocalAuth) -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; -#endif #if (IndividualB2CAuth) using Microsoft.Extensions.Options; #endif @@ -24,25 +17,7 @@ namespace Company.WebApplication1.Controllers [Route("[controller]/[action]")] public class AccountController : Controller { -#if (IndividualLocalAuth) - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public AccountController(SignInManager signInManager, ILogger logger) - { - _signInManager = signInManager; - _logger = logger; - } - - [HttpPost] - [ValidateAntiForgeryToken] - public async Task Logout() - { - await _signInManager.SignOutAsync(); - _logger.LogInformation("User logged out."); - return RedirectToPage("/Index"); - } -#elseif (OrganizationalAuth) +#if (OrganizationalAuth) [HttpGet] public IActionResult SignIn() { diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs deleted file mode 100644 index 64fdd804c7..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationDbContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; - -namespace Company.WebApplication1.Data -{ - public class ApplicationDbContext : IdentityDbContext - { - public ApplicationDbContext(DbContextOptions options) - : base(options) - { - } - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - // Customize the ASP.NET Identity model and override the defaults if needed. - // For example, you can rename the ASP.NET Identity table names and more. - // Add your customizations after calling base.OnModelCreating(builder); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationUser.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationUser.cs deleted file mode 100644 index 0fcfc519b1..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/ApplicationUser.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; - -namespace Company.WebApplication1.Data -{ - // Add profile data for application users by adding properties to the ApplicationUser class - public class ApplicationUser : IdentityUser - { - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs index 483520ed85..f27fc96c28 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -11,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(ApplicationDbContext))] + [DbContext(typeof(IdentityDbContext))] [Migration("00000000000000_CreateIdentitySchema")] partial class CreateIdentitySchema { @@ -140,7 +141,7 @@ namespace Company.WebApplication1.Data.Migrations b.ToTable("AspNetUserTokens"); }); - modelBuilder.Entity("Company.WebApplication1.Models.ApplicationUser", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id"); @@ -215,7 +216,7 @@ namespace Company.WebApplication1.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Claims") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); @@ -223,7 +224,7 @@ namespace Company.WebApplication1.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Logins") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); @@ -236,7 +237,7 @@ namespace Company.WebApplication1.Data.Migrations .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Roles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs similarity index 94% rename from src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs rename to src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs index 01138f20da..546959138c 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Data/Migrations/IdentityDbContextModelSnapshot.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; #endif +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; @@ -11,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Company.WebApplication1.Data.Migrations { - [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(IdentityDbContext))] + partial class IdentityDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -139,7 +140,7 @@ namespace Company.WebApplication1.Data.Migrations b.ToTable("AspNetUserTokens"); }); - modelBuilder.Entity("Company.WebApplication1.Models.ApplicationUser", b => + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id"); @@ -214,7 +215,7 @@ namespace Company.WebApplication1.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserClaim", b => { - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Claims") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); @@ -222,7 +223,7 @@ namespace Company.WebApplication1.Data.Migrations modelBuilder.Entity("Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin", b => { - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Logins") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); @@ -235,7 +236,7 @@ namespace Company.WebApplication1.Data.Migrations .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); - b.HasOne("Company.WebApplication1.Models.ApplicationUser") + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany("Roles") .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/EmailSenderExtensions.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/EmailSenderExtensions.cs deleted file mode 100644 index d50d7f1d1c..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/EmailSenderExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Company.WebApplication1.Services; - -namespace Company.WebApplication1.Services -{ - public static class EmailSenderExtensions - { - public static Task SendEmailConfirmationAsync(this IEmailSender emailSender, string email, string link) - { - return emailSender.SendEmailAsync(email, "Confirm your email", - $"Please confirm your account by clicking here."); - } - - public static Task SendResetPasswordAsync(this IEmailSender emailSender, string email, string callbackUrl) - { - return emailSender.SendEmailAsync(email, "Reset Password", - $"Please reset your password by clicking here."); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/UrlHelperExtensions.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/UrlHelperExtensions.cs deleted file mode 100644 index e0f33aa62d..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Extensions/UrlHelperExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.Mvc -{ - public static class UrlHelperExtensions - { - public static string GetLocalUrl(this IUrlHelper urlHelper, string localUrl) - { - if (!urlHelper.IsLocalUrl(localUrl)) - { - return urlHelper.Page("/Index"); - } - - return localUrl; - } - - public static string EmailConfirmationLink(this IUrlHelper urlHelper, string userId, string code, string scheme) - { - return urlHelper.Page( - "/Account/ConfirmEmail", - pageHandler: null, - values: new { userId, code }, - protocol: scheme); - } - - public static string ResetPasswordCallbackLink(this IUrlHelper urlHelper, string code, string scheme) - { - return urlHelper.Page( - "/Account/ResetPassword", - pageHandler: null, - values: new { code }, - protocol: scheme); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml deleted file mode 100644 index 3510edef22..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@page -@model AccessDeniedModel -@{ - ViewData["Title"] = "Access denied"; -} - -
-

@ViewData["Title"]

-

You do not have access to this resource.

-
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs deleted file mode 100644 index 3bed2536e1..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Company.WebApplication1.Pages.Account -{ - public class AccessDeniedModel : PageModel - { - public void OnGet() - { - - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml deleted file mode 100644 index 903896477c..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml +++ /dev/null @@ -1,12 +0,0 @@ -@page -@model ConfirmEmailModel -@{ - ViewData["Title"] = "Confirm email"; -} - -

@ViewData["Title"]

-
-

- Thank you for confirming your email. -

-
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml.cs deleted file mode 100644 index 134f874024..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ConfirmEmail.cshtml.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class ConfirmEmailModel : PageModel - { - private readonly UserManager _userManager; - - public ConfirmEmailModel(UserManager userManager) - { - _userManager = userManager; - } - - public async Task OnGetAsync(string userId, string code) - { - if (userId == null || code == null) - { - return RedirectToPage("/Index"); - } - - var user = await _userManager.FindByIdAsync(userId); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{userId}'."); - } - - var result = await _userManager.ConfirmEmailAsync(user, code); - if (!result.Succeeded) - { - throw new ApplicationException($"Error confirming email for user with ID '{userId}':"); - } - - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml deleted file mode 100644 index 51c9b9264f..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml +++ /dev/null @@ -1,33 +0,0 @@ -@page -@model ExternalLoginModel -@{ - ViewData["Title"] = "Register"; -} - -

@ViewData["Title"]

-

Associate your @Model.LoginProvider account.

-
- -

- You've successfully authenticated with @Model.LoginProvider. - Please enter an email address for this site below and click the Register button to finish - logging in. -

- -
-
-
-
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml.cs deleted file mode 100644 index d96924a5e3..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ExternalLogin.cshtml.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class ExternalLoginModel : PageModel - { - private readonly SignInManager _signInManager; - private readonly UserManager _userManager; - private readonly ILogger _logger; - - public ExternalLoginModel( - SignInManager signInManager, - UserManager userManager, - ILogger logger) - { - _signInManager = signInManager; - _userManager = userManager; - _logger = logger; - } - - [BindProperty] - public InputModel Input { get; set; } - - public string LoginProvider { get; set; } - - public string ReturnUrl { get; set; } - - [TempData] - public string ErrorMessage { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - public string Email { get; set; } - } - - public IActionResult OnGetAsync() - { - return RedirectToPage("./Login"); - } - - public IActionResult OnPost(string provider, string returnUrl = null) - { - // Request a redirect to the external login provider. - var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl }); - var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); - return new ChallengeResult(provider, properties); - } - - public async Task OnGetCallbackAsync(string returnUrl = null, string remoteError = null) - { - if (remoteError != null) - { - ErrorMessage = $"Error from external provider: {remoteError}"; - return RedirectToPage("./Login", new { ReturnUrl = returnUrl }); - } - var info = await _signInManager.GetExternalLoginInfoAsync(); - if (info == null) - { - ErrorMessage = "Error loading external login information."; - return RedirectToPage("./Login", new { ReturnUrl = returnUrl }); - } - - // Sign in the user with this external login provider if the user already has a login. - var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true); - if (result.Succeeded) - { - _logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - if (result.IsLockedOut) - { - return RedirectToPage("./Lockout"); - } - else - { - // If the user does not have an account, then ask the user to create an account. - ReturnUrl = returnUrl; - LoginProvider = info.LoginProvider; - if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email)) - { - Input = new InputModel - { - Email = info.Principal.FindFirstValue(ClaimTypes.Email) - }; - } - return Page(); - } - } - - public async Task OnPostConfirmationAsync(string returnUrl = null) - { - // Get the information about the user from the external login provider - var info = await _signInManager.GetExternalLoginInfoAsync(); - if (info == null) - { - ErrorMessage = "Error loading external login information during confirmation."; - return RedirectToPage("./Login", new { ReturnUrl = returnUrl }); - } - - if (ModelState.IsValid) - { - var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; - var result = await _userManager.CreateAsync(user); - if (result.Succeeded) - { - result = await _userManager.AddLoginAsync(user, info); - if (result.Succeeded) - { - await _signInManager.SignInAsync(user, isPersistent: false); - _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - } - foreach (var error in result.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - } - - LoginProvider = info.LoginProvider; - ReturnUrl = returnUrl; - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml deleted file mode 100644 index cd8e98cf44..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml +++ /dev/null @@ -1,26 +0,0 @@ -@page -@model ForgotPasswordModel -@{ - ViewData["Title"] = "Forgot your password?"; -} - -

@ViewData["Title"]

-

Enter your email.

-
-
-
-
-
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml.cs deleted file mode 100644 index 09d2e72e8c..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPassword.cshtml.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; -using Company.WebApplication1.Services; - -namespace Company.WebApplication1.Pages.Account -{ - public class ForgotPasswordModel : PageModel - { - private readonly UserManager _userManager; - private readonly IEmailSender _emailSender; - - public ForgotPasswordModel(UserManager userManager, IEmailSender emailSender) - { - _userManager = userManager; - _emailSender = emailSender; - } - - [BindProperty] - public InputModel Input { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - public string Email { get; set; } - } - - public async Task OnPostAsync() - { - if (ModelState.IsValid) - { - var user = await _userManager.FindByEmailAsync(Input.Email); - if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) - { - // Don't reveal that the user does not exist or is not confirmed - return RedirectToPage("./ForgotPasswordConfirmation"); - } - - // For more information on how to enable account confirmation and password reset please - // visit https://go.microsoft.com/fwlink/?LinkID=532713 - var code = await _userManager.GeneratePasswordResetTokenAsync(user); - var callbackUrl = Url.ResetPasswordCallbackLink(code, Request.Scheme); - await _emailSender.SendResetPasswordAsync(Input.Email, callbackUrl); - return RedirectToPage("./ForgotPasswordConfirmation"); - } - - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml deleted file mode 100644 index b1139309eb..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@page -@model ForgotPasswordConfirmation -@{ - ViewData["Title"] = "Forgot password confirmation"; -} - -

@ViewData["Title"]

-

- Please check your email to reset your password. -

diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml.cs deleted file mode 100644 index 7d51b89172..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ForgotPasswordConfirmation.cshtml.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Company.WebApplication1.Pages.Account -{ - public class ForgotPasswordConfirmation : PageModel - { - public void OnGet() - { - - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml deleted file mode 100644 index 4eded88208..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@page -@model LockoutModel -@{ - ViewData["Title"] = "Locked out"; -} - -
-

@ViewData["Title"]

-

This account has been locked out, please try again later.

-
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml.cs deleted file mode 100644 index b2a2aa0669..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Lockout.cshtml.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Company.WebApplication1.Pages.Account -{ - public class LockoutModel : PageModel - { - public void OnGet() - { - - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml deleted file mode 100644 index a486f27545..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml +++ /dev/null @@ -1,82 +0,0 @@ -@page -@model LoginModel - -@{ - ViewData["Title"] = "Log in"; -} - -

@ViewData["Title"]

-
-
-
-
-

Use a local account to log in.

-
-
-
- - - -
-
- - - -
-
-
- -
-
-
- -
- -
-
-
-
-
-

Use another service to log in.

-
- @{ - if ((Model.ExternalLogins?.Count ?? 0) == 0) - { -
-

- There are no external authentication services configured. See this article - for details on setting up this ASP.NET application to support logging in via external services. -

-
- } - else - { -
-
-

- @foreach (var provider in Model.ExternalLogins) - { - - } -

-
-
- } - } -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml.cs deleted file mode 100644 index 9fd2f7c784..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Login.cshtml.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class LoginModel : PageModel - { - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public LoginModel(SignInManager signInManager, ILogger logger) - { - _signInManager = signInManager; - _logger = logger; - } - - [BindProperty] - public InputModel Input { get; set; } - - public IList ExternalLogins { get; set; } - - public string ReturnUrl { get; set; } - - [TempData] - public string ErrorMessage { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - public string Email { get; set; } - - [Required] - [DataType(DataType.Password)] - public string Password { get; set; } - - [Display(Name = "Remember me?")] - public bool RememberMe { get; set; } - } - - public async Task OnGetAsync(string returnUrl = null) - { - if (!string.IsNullOrEmpty(ErrorMessage)) - { - ModelState.AddModelError(string.Empty, ErrorMessage); - } - - // Clear the existing external cookie to ensure a clean login process - await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); - - ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); - - ReturnUrl = returnUrl; - } - - public async Task OnPostAsync(string returnUrl = null) - { - ReturnUrl = returnUrl; - - if (ModelState.IsValid) - { - // This doesn't count login failures towards account lockout - // To enable password failures to trigger account lockout, set lockoutOnFailure: true - var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true); - if (result.Succeeded) - { - _logger.LogInformation("User logged in."); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - if (result.RequiresTwoFactor) - { - return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }); - } - if (result.IsLockedOut) - { - _logger.LogWarning("User account locked out."); - return RedirectToPage("./Lockout"); - } - else - { - ModelState.AddModelError(string.Empty, "Invalid login attempt."); - return Page(); - } - } - - // If we got this far, something failed, redisplay form - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml deleted file mode 100644 index 032ecd98cd..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@page -@model LoginWith2faModel -@{ - ViewData["Title"] = "Two-factor authentication"; -} - -

@ViewData["Title"]

-
-

Your login is protected with an authenticator app. Enter your authenticator code below.

-
-
-
- -
-
- - - -
-
-
- -
-
-
- -
-
-
-
-

- Don't have access to your authenticator device? You can - log in with a recovery code. -

- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml.cs deleted file mode 100644 index 7d117d567e..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWith2fa.cshtml.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class LoginWith2faModel : PageModel - { - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public LoginWith2faModel(SignInManager signInManager, ILogger logger) - { - _signInManager = signInManager; - _logger = logger; - } - - [BindProperty] - public InputModel Input { get; set; } - - public bool RememberMe { get; set; } - - public string ReturnUrl { get; set; } - - public class InputModel - { - [Required] - [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Text)] - [Display(Name = "Authenticator code")] - public string TwoFactorCode { get; set; } - - [Display(Name = "Remember this machine")] - public bool RememberMachine { get; set; } - } - - public async Task OnGetAsync(bool rememberMe, string returnUrl = null) - { - // Ensure the user has gone through the username & password screen first - var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); - - if (user == null) - { - throw new ApplicationException($"Unable to load two-factor authentication user."); - } - - ReturnUrl = returnUrl; - RememberMe = rememberMe; - - return Page(); - } - - public async Task OnPostAsync(bool rememberMe, string returnUrl = null) - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); - if (user == null) - { - throw new ApplicationException($"Unable to load two-factor authentication user."); - } - - var authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty); - - var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe, Input.RememberMachine); - - if (result.Succeeded) - { - _logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - else if (result.IsLockedOut) - { - _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id); - return RedirectToPage("./Lockout"); - } - else - { - _logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id); - ModelState.AddModelError(string.Empty, "Invalid authenticator code."); - return Page(); - } - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml deleted file mode 100644 index 4b32c1d8ff..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml +++ /dev/null @@ -1,29 +0,0 @@ -@page -@model LoginWithRecoveryCodeModel -@{ - ViewData["Title"] = "Recovery code verification"; -} - -

@ViewData["Title"]

-
-

- You have requested to log in with a recovery code. This login will not be remembered until you provide - an authenticator app code at log in or disable 2FA and log in again. -

-
-
-
-
-
- - - -
- -
-
-
- - @section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml.cs deleted file mode 100644 index 1293bdc66a..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/LoginWithRecoveryCode.cshtml.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class LoginWithRecoveryCodeModel : PageModel - { - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public LoginWithRecoveryCodeModel(SignInManager signInManager, ILogger logger) - { - _signInManager = signInManager; - _logger = logger; - } - - [BindProperty] - public InputModel Input { get; set; } - - public string ReturnUrl { get; set; } - - public class InputModel - { - [BindProperty] - [Required] - [DataType(DataType.Text)] - [Display(Name = "Recovery Code")] - public string RecoveryCode { get; set; } - } - - public async Task OnGetAsync(string returnUrl = null) - { - // Ensure the user has gone through the username & password screen first - var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); - if (user == null) - { - throw new ApplicationException($"Unable to load two-factor authentication user."); - } - - ReturnUrl = returnUrl; - - return Page(); - } - - public async Task OnPostAsync(string returnUrl = null) - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _signInManager.GetTwoFactorAuthenticationUserAsync(); - if (user == null) - { - throw new ApplicationException($"Unable to load two-factor authentication user."); - } - - var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty); - - var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode); - - if (result.Succeeded) - { - _logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", user.Id); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - if (result.IsLockedOut) - { - _logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id); - return RedirectToPage("./Lockout"); - } - else - { - _logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id); - ModelState.AddModelError(string.Empty, "Invalid recovery code entered."); - return Page(); - } - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml deleted file mode 100644 index 6aa47234d1..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml +++ /dev/null @@ -1,35 +0,0 @@ -@page -@model ChangePasswordModel -@{ - ViewData["Title"] = "Change password"; -} - -

@ViewData["Title"]

-@Html.Partial("_StatusMessage", Model.StatusMessage) -
-
-
-
-
- - - -
-
- - - -
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml.cs deleted file mode 100644 index 07d97806d7..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ChangePassword.cshtml.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class ChangePasswordModel : PageModel - { - private readonly UserManager _userManager; - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public ChangePasswordModel( - UserManager userManager, - SignInManager signInManager, - ILogger logger) - { - _userManager = userManager; - _signInManager = signInManager; - _logger = logger; - } - - [BindProperty] - public InputModel Input { get; set; } - - [TempData] - public string StatusMessage { get; set; } - - public class InputModel - { - [Required] - [DataType(DataType.Password)] - [Display(Name = "Current password")] - public string OldPassword { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "New password")] - public string NewPassword { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm new password")] - [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var hasPassword = await _userManager.HasPasswordAsync(user); - if (!hasPassword) - { - return RedirectToPage("./SetPassword"); - } - - return Page(); - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword); - if (!changePasswordResult.Succeeded) - { - foreach (var error in changePasswordResult.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - return Page(); - } - - await _signInManager.SignInAsync(user, isPersistent: false); - _logger.LogInformation("User changed their password successfully."); - StatusMessage = "Your password has been changed."; - - return RedirectToPage(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml deleted file mode 100644 index 954093ee3b..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@page -@model Disable2faModel -@{ - ViewData["Title"] = "Disable two-factor authentication (2FA)"; - ViewData["ActivePage"] = "TwoFactorAuthentication"; -} - -

@ViewData["Title"]

- - - -
-
- -
-
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml.cs deleted file mode 100644 index be06576f2f..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Disable2fa.cshtml.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class Disable2faModel : PageModel - { - private readonly UserManager _userManager; - private readonly ILogger _logger; - - public Disable2faModel( - UserManager userManager, - ILogger logger) - { - _userManager = userManager; - _logger = logger; - } - - public async Task OnGet() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - if (!await _userManager.GetTwoFactorEnabledAsync(user)) - { - throw new ApplicationException($"Cannot disable 2FA for user with ID '{_userManager.GetUserId(User)}' as it's not currently enabled."); - } - - return Page(); - } - - public async Task OnPostAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var disable2faResult = await _userManager.SetTwoFactorEnabledAsync(user, false); - if (!disable2faResult.Succeeded) - { - throw new ApplicationException($"Unexpected error occurred disabling 2FA for user with ID '{_userManager.GetUserId(User)}'."); - } - - _logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", _userManager.GetUserId(User)); - - return RedirectToPage("./TwoFactorAuthentication"); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml deleted file mode 100644 index 1d68558407..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml +++ /dev/null @@ -1,53 +0,0 @@ -@page -@model EnableAuthenticatorModel -@{ - ViewData["Title"] = "Configure authenticator app"; - ViewData["ActivePage"] = "TwoFactorAuthentication"; -} - -

@ViewData["Title"]

-
-

To use an authenticator app go through the following steps:

-
    -
  1. -

    - Download a two-factor authenticator app like Microsoft Authenticator for - Windows Phone, - Android and - iOS or - Google Authenticator for - Android and - iOS. -

    -
  2. -
  3. -

    Scan the QR Code or enter this key @Model.SharedKey into your two factor authenticator app. Spaces and casing do not matter.

    -
    To enable QR code generation please read our documentation.
    -
    -
    -
  4. -
  5. -

    - Once you have scanned the QR code or input the key above, your two factor authentication app will provide you - with a unique code. Enter the code in the confirmation box below. -

    -
    -
    -
    -
    - - - -
    - -
    -
    -
    -
    -
  6. -
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml.cs deleted file mode 100644 index 025944c90f..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/EnableAuthenticator.cshtml.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Collections.Generic; -using System.Text; -using System.Text.Encodings.Web; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class EnableAuthenticatorModel : PageModel - { - private readonly UserManager _userManager; - private readonly ILogger _logger; - private readonly UrlEncoder _urlEncoder; - - private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6"; - - public EnableAuthenticatorModel( - UserManager userManager, - ILogger logger, - UrlEncoder urlEncoder) - { - _userManager = userManager; - _logger = logger; - _urlEncoder = urlEncoder; - } - - public string SharedKey { get; set; } - - public string AuthenticatorUri { get; set; } - - [BindProperty] - public InputModel Input { get; set; } - - public class InputModel - { - [Required] - [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Text)] - [Display(Name = "Verification Code")] - public string Code { get; set; } - } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - await LoadSharedKeyAndQrCodeUriAsync(user); - if (string.IsNullOrEmpty(SharedKey)) - { - await _userManager.ResetAuthenticatorKeyAsync(user); - await LoadSharedKeyAndQrCodeUriAsync(user); - } - - return Page(); - } - - public async Task OnPostAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - if (!ModelState.IsValid) - { - await LoadSharedKeyAndQrCodeUriAsync(user); - return Page(); - } - - // Strip spaces and hypens - var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty); - - var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync( - user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode); - - if (!is2faTokenValid) - { - ModelState.AddModelError("Input.Code", "Verification code is invalid."); - await LoadSharedKeyAndQrCodeUriAsync(user); - return Page(); - } - - await _userManager.SetTwoFactorEnabledAsync(user, true); - _logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", user.Id); - return RedirectToPage("./GenerateRecoveryCodes"); - } - - private async Task LoadSharedKeyAndQrCodeUriAsync(ApplicationUser user) - { - // Load the authenticator key & QR code URI to display on the form - var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); - if (!string.IsNullOrEmpty(unformattedKey)) - { - SharedKey = FormatKey(unformattedKey); - AuthenticatorUri = GenerateQrCodeUri(user.Email, unformattedKey); - } - } - - private string FormatKey(string unformattedKey) - { - var result = new StringBuilder(); - int currentPosition = 0; - while (currentPosition + 4 < unformattedKey.Length) - { - result.Append(unformattedKey.Substring(currentPosition, 4)).Append(" "); - currentPosition += 4; - } - if (currentPosition < unformattedKey.Length) - { - result.Append(unformattedKey.Substring(currentPosition)); - } - - return result.ToString().ToLowerInvariant(); - } - - private string GenerateQrCodeUri(string email, string unformattedKey) - { - return string.Format( - AuthenticatorUriFormat, - _urlEncoder.Encode("Company.WebApplication1"), - _urlEncoder.Encode(email), - unformattedKey); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml deleted file mode 100644 index ccb66a6a49..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml +++ /dev/null @@ -1,52 +0,0 @@ -@page -@model ExternalLoginsModel -@{ - ViewData["Title"] = "Manage your external logins"; -} - -@Html.Partial("_StatusMessage", Model.StatusMessage) -@if (Model.CurrentLogins?.Count > 0) -{ -

Registered Logins

- - - @foreach (var login in Model.CurrentLogins) - { - - - - - } - -
@login.LoginProvider - @if (Model.ShowRemoveButton) - { -
-
- - - -
-
- } - else - { - @:   - } -
-} -@if (Model.OtherLogins?.Count > 0) -{ -

Add another service to log in.

-
-
-
-

- @foreach (var provider in Model.OtherLogins) - { - - } -

-
-
-} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml.cs deleted file mode 100644 index 804f84b967..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ExternalLogins.cshtml.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class ExternalLoginsModel : PageModel - { - private readonly UserManager _userManager; - private readonly SignInManager _signInManager; - - public ExternalLoginsModel( - UserManager userManager, - SignInManager signInManager) - { - _userManager = userManager; - _signInManager = signInManager; - } - - public IList CurrentLogins { get; set; } - - public IList OtherLogins { get; set; } - - public bool ShowRemoveButton { get; set; } - - [TempData] - public string StatusMessage { get; set; } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - CurrentLogins = await _userManager.GetLoginsAsync(user); - OtherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()) - .Where(auth => CurrentLogins.All(ul => auth.Name != ul.LoginProvider)) - .ToList(); - ShowRemoveButton = user.PasswordHash != null || CurrentLogins.Count > 1; - return Page(); - } - - public async Task OnPostRemoveLoginAsync(string loginProvider, string providerKey) - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey); - if (!result.Succeeded) - { - throw new ApplicationException($"Unexpected error occurred removing external login for user with ID '{user.Id}'."); - } - - await _signInManager.SignInAsync(user, isPersistent: false); - StatusMessage = "The external login was removed."; - return RedirectToPage(); - } - - public async Task OnPostLinkLoginAsync(string provider) - { - // Clear the existing external cookie to ensure a clean login process - await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); - - // Request a redirect to the external login provider to link a login for the current user - var redirectUrl = Url.Page("./ExternalLogins", pageHandler: "LinkLoginCallback"); - var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, _userManager.GetUserId(User)); - return new ChallengeResult(provider, properties); - } - - public async Task OnGetLinkLoginCallbackAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var info = await _signInManager.GetExternalLoginInfoAsync(await _userManager.GetUserIdAsync(user)); - if (info == null) - { - throw new ApplicationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'."); - } - - var result = await _userManager.AddLoginAsync(user, info); - if (!result.Succeeded) - { - throw new ApplicationException($"Unexpected error occurred adding external login for user with ID '{user.Id}'."); - } - - // Clear the existing external cookie to ensure a clean login process - await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); - - StatusMessage = "The external login was added."; - return RedirectToPage(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml deleted file mode 100644 index d05825429f..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@page -@model GenerateRecoveryCodesModel -@{ - ViewData["Title"] = "Recovery codes"; - ViewData["ActivePage"] = "TwoFactorAuthentication"; -} - -

@ViewData["Title"]

- -
-
- @for (var row = 0; row < Model.RecoveryCodes.Count(); row += 2) - { - @Model.RecoveryCodes[row] @Model.RecoveryCodes[row + 1]
- } -
-
\ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs deleted file mode 100644 index 6839d275fc..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/GenerateRecoveryCodes.cshtml.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class GenerateRecoveryCodesModel : PageModel - { - private readonly UserManager _userManager; - private readonly ILogger _logger; - - public GenerateRecoveryCodesModel( - UserManager userManager, - ILogger logger) - { - _userManager = userManager; - _logger = logger; - } - - public string[] RecoveryCodes { get; set; } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - if (!user.TwoFactorEnabled) - { - throw new ApplicationException($"Cannot generate recovery codes for user with ID '{user.Id}' as they do not have 2FA enabled."); - } - - var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); - RecoveryCodes = recoveryCodes.ToArray(); - - _logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", user.Id); - - return Page(); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml deleted file mode 100644 index 78a0383cd3..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml +++ /dev/null @@ -1,45 +0,0 @@ -@page -@model IndexModel -@{ - ViewData["Title"] = "Profile"; -} - -

@ViewData["Title"]

-@Html.Partial("_StatusMessage", Model.StatusMessage) -
-
-
-
-
- - -
-
- - @if (Model.IsEmailConfirmed) - { -
- - -
- } - else - { - - - } - -
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml.cs deleted file mode 100644 index cf02965dc8..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/Index.cshtml.cs +++ /dev/null @@ -1,128 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; -using Company.WebApplication1.Services; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public partial class IndexModel : PageModel - { - private readonly UserManager _userManager; - private readonly SignInManager _signInManager; - private readonly IEmailSender _emailSender; - - public IndexModel( - UserManager userManager, - SignInManager signInManager, - IEmailSender emailSender) - { - _userManager = userManager; - _signInManager = signInManager; - _emailSender = emailSender; - } - - public string Username { get; set; } - - public bool IsEmailConfirmed { get; set; } - - [TempData] - public string StatusMessage { get; set; } - - [BindProperty] - public InputModel Input { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - public string Email { get; set; } - - [Phone] - [Display(Name = "Phone number")] - public string PhoneNumber { get; set; } - } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - Username = user.UserName; - - Input = new InputModel - { - Email = user.Email, - PhoneNumber = user.PhoneNumber - }; - - IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user); - - return Page(); - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - if (Input.Email != user.Email) - { - var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email); - if (!setEmailResult.Succeeded) - { - throw new ApplicationException($"Unexpected error occurred setting email for user with ID '{user.Id}'."); - } - } - - if (Input.PhoneNumber != user.PhoneNumber) - { - var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber); - if (!setPhoneResult.Succeeded) - { - throw new ApplicationException($"Unexpected error occurred setting phone number for user with ID '{user.Id}'."); - } - } - - StatusMessage = "Your profile has been updated"; - return RedirectToPage(); - } - public async Task OnPostSendVerificationEmailAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); - var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); - await _emailSender.SendEmailConfirmationAsync(user.Email, callbackUrl); - - StatusMessage = "Verification email sent. Please check your email."; - return RedirectToPage(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ManageNavPages.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ManageNavPages.cs deleted file mode 100644 index 9f5b7521f0..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ManageNavPages.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Rendering; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public static class ManageNavPages - { - public static string Index => "Index"; - - public static string ChangePassword => "ChangePassword"; - - public static string ExternalLogins => "ExternalLogins"; - - public static string TwoFactorAuthentication => "TwoFactorAuthentication"; - - public static string IndexNavClass(ViewContext viewContext) => PageNavClass(viewContext, Index); - - public static string ChangePasswordNavClass(ViewContext viewContext) => PageNavClass(viewContext, ChangePassword); - - public static string ExternalLoginsNavClass(ViewContext viewContext) => PageNavClass(viewContext, ExternalLogins); - - public static string TwoFactorAuthenticationNavClass(ViewContext viewContext) => PageNavClass(viewContext, TwoFactorAuthentication); - - public static string PageNavClass(ViewContext viewContext, string page) - { - var activePage = viewContext.ViewData["ActivePage"] as string - ?? System.IO.Path.GetFileNameWithoutExtension(viewContext.ActionDescriptor.DisplayName); - return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null; - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml deleted file mode 100644 index a9534ae257..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml +++ /dev/null @@ -1,23 +0,0 @@ -@page -@model ResetAuthenticatorModel -@{ - ViewData["Title"] = "Reset authenticator key"; - ViewData["ActivePage"] = "TwoFactorAuthentication"; -} - -

@ViewData["Title"]

- -
-
- -
-
\ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml.cs deleted file mode 100644 index f0ed397385..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/ResetAuthenticator.cshtml.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class ResetAuthenticatorModel : PageModel - { - UserManager _userManager; - ILogger _logger; - - public ResetAuthenticatorModel( - UserManager userManager, - ILogger logger) - { - _userManager = userManager; - _logger = logger; - } - public async Task OnGet() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - return Page(); - } - - public async Task OnPostAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - await _userManager.SetTwoFactorEnabledAsync(user, false); - await _userManager.ResetAuthenticatorKeyAsync(user); - _logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", user.Id); - - return RedirectToPage("./EnableAuthenticator"); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml deleted file mode 100644 index 3f4544caf4..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml +++ /dev/null @@ -1,35 +0,0 @@ -@page -@model SetPasswordModel -@{ - ViewData["Title"] = "Set password"; - ViewData["ActivePage"] = "ChangePassword"; -} - -

Set your password

-@Html.Partial("_StatusMessage", Model.StatusMessage) -

- You do not have a local username/password for this site. Add a local - account so you can log in without an external login. -

-
-
-
-
-
- - - -
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml.cs deleted file mode 100644 index 33ea8bf3c3..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/SetPassword.cshtml.cs +++ /dev/null @@ -1,93 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class SetPasswordModel : PageModel - { - private readonly UserManager _userManager; - private readonly SignInManager _signInManager; - - public SetPasswordModel( - UserManager userManager, - SignInManager signInManager) - { - _userManager = userManager; - _signInManager = signInManager; - } - - [BindProperty] - public InputModel Input { get; set; } - - [TempData] - public string StatusMessage { get; set; } - - public class InputModel - { - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "New password")] - public string NewPassword { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm new password")] - [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public async Task OnGetAsync() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var hasPassword = await _userManager.HasPasswordAsync(user); - - if (hasPassword) - { - return RedirectToPage("./ChangePassword"); - } - - return Page(); - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - var addPasswordResult = await _userManager.AddPasswordAsync(user, Input.NewPassword); - if (!addPasswordResult.Succeeded) - { - foreach (var error in addPasswordResult.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - return Page(); - } - - await _signInManager.SignInAsync(user, isPersistent: false); - StatusMessage = "Your password has been set."; - - return RedirectToPage(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml deleted file mode 100644 index fabe1999e6..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@page -@model TwoFactorAuthenticationModel -@{ - ViewData["Title"] = "Two-factor authentication (2FA)"; -} - -

@ViewData["Title"]

-@if (Model.Is2faEnabled) -{ - if (Model.RecoveryCodesLeft == 0) - { -
- You have no recovery codes left. -

You must generate a new set of recovery codes before you can log in with a recovery code.

-
- } - else if (Model.RecoveryCodesLeft == 1) - { -
- You have 1 recovery code left. -

You can generate a new set of recovery codes.

-
- } - else if (Model.RecoveryCodesLeft <= 3) - { -
- You have @Model.RecoveryCodesLeft recovery codes left. -

You should generate a new set of recovery codes.

-
- } - - Disable 2FA - Reset recovery codes -} - -
Authenticator app
-@if (!Model.HasAuthenticator) -{ - Add authenticator app -} -else -{ - Configure authenticator app - Reset authenticator app -} - -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml.cs deleted file mode 100644 index e91c080e1c..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/TwoFactorAuthentication.cshtml.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account.Manage -{ - public class TwoFactorAuthenticationModel : PageModel - { - private readonly UserManager _userManager; - private readonly SignInManager _signInManager; - private readonly ILogger _logger; - - public TwoFactorAuthenticationModel( - UserManager userManager, - SignInManager signInManager, - ILogger logger) - { - _userManager = userManager; - _signInManager = signInManager; - _logger = logger; - } - - public bool HasAuthenticator { get; set; } - - public int RecoveryCodesLeft { get; set; } - - [BindProperty] - public bool Is2faEnabled { get; set; } - - public async Task OnGet() - { - var user = await _userManager.GetUserAsync(User); - if (user == null) - { - throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); - } - - HasAuthenticator = await _userManager.GetAuthenticatorKeyAsync(user) != null; - Is2faEnabled = await _userManager.GetTwoFactorEnabledAsync(user); - RecoveryCodesLeft = await _userManager.CountRecoveryCodesAsync(user); - - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_Layout.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_Layout.cshtml deleted file mode 100644 index c3f24b6ef8..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_Layout.cshtml +++ /dev/null @@ -1,23 +0,0 @@ -@{ - Layout = "/Pages/_Layout.cshtml"; -} - -

Manage your account

- -
-

Change your account settings

-
-
-
- @await Html.PartialAsync("_ManageNav") -
-
- @RenderBody() -
-
-
- -@section Scripts { - @RenderSection("Scripts", required: false) -} - diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ManageNav.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ManageNav.cshtml deleted file mode 100644 index 16d50ddfa7..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ManageNav.cshtml +++ /dev/null @@ -1,15 +0,0 @@ -@inject SignInManager SignInManager -@{ - var hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any(); -} - - - diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_StatusMessage.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_StatusMessage.cshtml deleted file mode 100644 index e996841309..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_StatusMessage.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@model string - -@if (!String.IsNullOrEmpty(Model)) -{ - var statusMessageClass = Model.StartsWith("Error") ? "danger" : "success"; - -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ViewImports.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ViewImports.cshtml deleted file mode 100644 index 44fcb384f7..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Manage/_ViewImports.cshtml +++ /dev/null @@ -1 +0,0 @@ -@using Company.WebApplication1.Pages.Account.Manage diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml deleted file mode 100644 index 64f2151518..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml +++ /dev/null @@ -1,37 +0,0 @@ -@page -@model RegisterModel -@{ - ViewData["Title"] = "Register"; -} - -

@ViewData["Title"]

- -
-
-
-

Create a new account.

-
-
-
- - - -
-
- - - -
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml.cs deleted file mode 100644 index 99fb88a1a8..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/Register.cshtml.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Microsoft.Extensions.Logging; -using Company.WebApplication1.Data; -using Company.WebApplication1.Services; - -namespace Company.WebApplication1.Pages.Account -{ - public class RegisterModel : PageModel - { - private readonly SignInManager _signInManager; - private readonly UserManager _userManager; - private readonly ILogger _logger; - private readonly IEmailSender _emailSender; - - public RegisterModel( - UserManager userManager, - SignInManager signInManager, - ILogger logger, - IEmailSender emailSender) - { - _userManager = userManager; - _signInManager = signInManager; - _logger = logger; - _emailSender = emailSender; - } - - [BindProperty] - public InputModel Input { get; set; } - - public string ReturnUrl { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - [Display(Name = "Email")] - public string Email { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - [Display(Name = "Password")] - public string Password { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm password")] - [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - } - - public void OnGet(string returnUrl = null) - { - ReturnUrl = returnUrl; - } - - public async Task OnPostAsync(string returnUrl = null) - { - ReturnUrl = returnUrl; - if (ModelState.IsValid) - { - var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; - var result = await _userManager.CreateAsync(user, Input.Password); - if (result.Succeeded) - { - _logger.LogInformation("User created a new account with password."); - - var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); - var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); - await _emailSender.SendEmailConfirmationAsync(Input.Email, callbackUrl); - - await _signInManager.SignInAsync(user, isPersistent: false); - return LocalRedirect(Url.GetLocalUrl(returnUrl)); - } - foreach (var error in result.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - } - - // If we got this far, something failed, redisplay form - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml deleted file mode 100644 index 85a81b1ef5..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml +++ /dev/null @@ -1,37 +0,0 @@ -@page -@model ResetPasswordModel -@{ - ViewData["Title"] = "Reset password"; -} - -

@ViewData["Title"]

-

Reset your password.

-
-
-
-
-
- -
- - - -
-
- - - -
-
- - - -
- -
-
-
- -@section Scripts { - @await Html.PartialAsync("_ValidationScriptsPartial") -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml.cs deleted file mode 100644 index b0cbc9922b..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPassword.cshtml.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Company.WebApplication1.Data; - -namespace Company.WebApplication1.Pages.Account -{ - public class ResetPasswordModel : PageModel - { - private readonly UserManager _userManager; - - public ResetPasswordModel(UserManager userManager) - { - _userManager = userManager; - } - - [BindProperty] - public InputModel Input { get; set; } - - public class InputModel - { - [Required] - [EmailAddress] - public string Email { get; set; } - - [Required] - [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] - [DataType(DataType.Password)] - public string Password { get; set; } - - [DataType(DataType.Password)] - [Display(Name = "Confirm password")] - [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] - public string ConfirmPassword { get; set; } - - public string Code { get; set; } - } - - public IActionResult OnGet(string code = null) - { - if (code == null) - { - throw new ApplicationException("A code must be supplied for password reset."); - } - else - { - Input = new InputModel - { - Code = code - }; - return Page(); - } - } - - public async Task OnPostAsync() - { - if (!ModelState.IsValid) - { - return Page(); - } - - var user = await _userManager.FindByEmailAsync(Input.Email); - if (user == null) - { - // Don't reveal that the user does not exist - return RedirectToPage("./ResetPasswordConfirmation"); - } - - var result = await _userManager.ResetPasswordAsync(user, Input.Code, Input.Password); - if (result.Succeeded) - { - return RedirectToPage("./ResetPasswordConfirmation"); - } - - foreach (var error in result.Errors) - { - ModelState.AddModelError(string.Empty, error.Description); - } - return Page(); - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml deleted file mode 100644 index a9972d4311..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@page -@model ResetPasswordConfirmationModel -@{ - ViewData["Title"] = "Reset password confirmation"; -} - -

@ViewData["Title"]

-

- Your password has been reset. Please click here to log in. -

diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml.cs deleted file mode 100644 index fccee6c3e7..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/ResetPasswordConfirmation.cshtml.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Company.WebApplication1.Pages.Account -{ - public class ResetPasswordConfirmationModel : PageModel - { - public void OnGet() - { - - } - } -} diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/_ViewImports.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/_ViewImports.cshtml deleted file mode 100644 index 1f50da0bfa..0000000000 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/_ViewImports.cshtml +++ /dev/null @@ -1 +0,0 @@ -@using Company.WebApplication1.Pages.Account diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_LoginPartial.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_LoginPartial.cshtml new file mode 100644 index 0000000000..3cd78ca58a --- /dev/null +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_LoginPartial.cshtml @@ -0,0 +1,25 @@ +@using Microsoft.AspNetCore.Identity + +@inject SignInManager SignInManager +@inject UserManager UserManager + +@if (SignInManager.IsSignedIn(User)) +{ + +} +else +{ + +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/_LoginPartial.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/_LoginPartial.cshtml index 015494e9d1..ed87a8899e 100644 --- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/_LoginPartial.cshtml +++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/_LoginPartial.cshtml @@ -1,35 +1,13 @@ -@*#if (IndividualLocalAuth) *@ -@using Microsoft.AspNetCore.Identity -@using Company.WebApplication1.Data -@inject SignInManager SignInManager -@inject UserManager UserManager -@*#else @using System.Security.Principal -#endif *@ @*#if (IndividualB2CAuth) @using Microsoft.AspNetCore.Authentication @using Microsoft.Extensions.Options @inject IOptions AzureAdB2COptions #endif *@ -@*#if (IndividualLocalAuth) *@ -@if (SignInManager.IsSignedIn(User)) -@*#else @if (User.Identity.IsAuthenticated) -#endif *@ { -@*#if (IndividualLocalAuth) *@ - -@*#elseif (IndividualB2CAuth) +@*#if (IndividualB2CAuth)