diff --git a/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs b/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs index edd2390af9..54146dd1ca 100644 --- a/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs +++ b/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs @@ -27,6 +27,14 @@ namespace Volo.Abp.Account.Web ) ); + options.FileSets.Add( + new EmbeddedFileSet( + "/Pages/", + GetType().GetTypeInfo().Assembly, + "Volo.Abp.Account.Web.Pages" + ) + ); + options.FileSets.Add( new EmbeddedFileSet( "/", diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LoginController.cs b/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LoginController.cs deleted file mode 100644 index affdbca2c5..0000000000 --- a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LoginController.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp.Account.Web.Areas.Account.Models.Login; -using Volo.Abp.Identity; -using Volo.Abp.Ui; - -namespace Volo.Abp.Account.Web.Areas.Account.Controllers -{ - [Area("Account")] - public class LoginController : AccountControllerBase - { - private readonly SignInManager _signInManager; - - public LoginController(SignInManager signInManager) - { - _signInManager = signInManager; - } - - public IActionResult Index() - { - return View(); - } - - [HttpPost] - public async Task Index(LoginModel loginModel, string returnUrl = "", string returnUrlHash = "") - { - if (!ModelState.IsValid) - { - throw new NotImplementedException(); - } - - var result = await _signInManager.PasswordSignInAsync( - loginModel.UserNameOrEmailAddress, - loginModel.Password, - loginModel.RememberMe, - true - ); - - if (!result.Succeeded) - { - throw new UserFriendlyException("Login failed!"); //TODO: Handle other cases, do not throw exception - } - - return RedirectSafely(returnUrl, returnUrlHash); - } - } -} diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs b/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs index a315286f27..e1620ed342 100644 --- a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs +++ b/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs @@ -1,15 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Identity; namespace Volo.Abp.Account.Web.Areas.Account.Controllers { [Area("Account")] - public class LogoutController : AccountControllerBase + public class LogoutController : AbpController { private readonly SignInManager _signInManager; @@ -22,7 +20,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers { await _signInManager.SignOutAsync(); - return RedirectToAction("Index", "Login"); + return RedirectToPage("/Account/Login"); } } } diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/RegisterController.cs b/src/Volo.Abp.Account.Web/Areas/Account/Controllers/RegisterController.cs deleted file mode 100644 index 01328dd173..0000000000 --- a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/RegisterController.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp.Account.Web.Areas.Account.Models.Register; -using Volo.Abp.Identity; - -namespace Volo.Abp.Account.Web.Areas.Account.Controllers -{ - [Area("Account")] - public class RegisterController : AccountControllerBase - { - private readonly IdentityUserManager _userManager; - private readonly SignInManager _signInManager; - - public RegisterController(IdentityUserManager userManager, SignInManager signInManager) - { - _userManager = userManager; - _signInManager = signInManager; - } - - public IActionResult Index() - { - return View(); - } - - [HttpPost] - //TODO: [ValidateAntiForgeryToken] - public async Task Index(RegisterModel registerModel, string returnUrl = "", string returnUrlHash = "") - { - if (!ModelState.IsValid) - { - throw new NotImplementedException(); - } - - var user = new IdentityUser(GuidGenerator.Create(), registerModel.UserName); - - var result = await _userManager.CreateAsync(user, registerModel.Password); - - if (!result.Succeeded) - { - throw new NotImplementedException(); - } - - await _userManager.SetEmailAsync(user, registerModel.EmailAddress); - - await _signInManager.SignInAsync(user, isPersistent: false); - - return RedirectSafely(returnUrl, returnUrlHash); - } - } -} diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Models/Login/LoginModel.cs b/src/Volo.Abp.Account.Web/Areas/Account/Models/Login/LoginModel.cs deleted file mode 100644 index a72c3e6f32..0000000000 --- a/src/Volo.Abp.Account.Web/Areas/Account/Models/Login/LoginModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Volo.Abp.Account.Web.Areas.Account.Models.Login -{ - public class LoginModel - { - [Required] - [MaxLength(255)] - public string UserNameOrEmailAddress { get; set; } - - [Required] - [MaxLength(32)] - public string Password { get; set; } - - public bool RememberMe { get; set; } - } -} \ No newline at end of file diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Models/Register/RegisterModel.cs b/src/Volo.Abp.Account.Web/Areas/Account/Models/Register/RegisterModel.cs deleted file mode 100644 index 6990c80cbf..0000000000 --- a/src/Volo.Abp.Account.Web/Areas/Account/Models/Register/RegisterModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Volo.Abp.Account.Web.Areas.Account.Models.Register -{ - public class RegisterModel - { - [Required] - [MaxLength(32)] - public string UserName { get; set; } - - [Required] - [EmailAddress] - [MaxLength(255)] - public string EmailAddress { get; set; } - - [Required] - [MaxLength(32)] - public string Password { get; set; } - } -} \ No newline at end of file diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountControllerBase.cs b/src/Volo.Abp.Account.Web/Pages/Account/AccountModelBase.cs similarity index 90% rename from src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountControllerBase.cs rename to src/Volo.Abp.Account.Web/Pages/Account/AccountModelBase.cs index 47ab906343..6398b98f7b 100644 --- a/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountControllerBase.cs +++ b/src/Volo.Abp.Account.Web/Pages/Account/AccountModelBase.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.RazorPages; using Volo.Abp.Ui; -namespace Volo.Abp.Account.Web.Areas.Account.Controllers +namespace Volo.Abp.Account.Web.Pages.Account { - public abstract class AccountControllerBase : AbpController + public abstract class AccountModelBase : AbpPageModel { protected RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null) { diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Views/Login/Index.cshtml b/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml similarity index 77% rename from src/Volo.Abp.Account.Web/Areas/Account/Views/Login/Index.cshtml rename to src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml index 155af50a68..24e84bfdab 100644 --- a/src/Volo.Abp.Account.Web/Areas/Account/Views/Login/Index.cshtml +++ b/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml @@ -1,6 +1,8 @@ -
+@page +@model Volo.Abp.Account.Web.Pages.Account.LoginModel +
-
+
@@ -17,9 +19,9 @@
- +
\ No newline at end of file diff --git a/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs new file mode 100644 index 0000000000..a854ac5347 --- /dev/null +++ b/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -0,0 +1,72 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Identity; +using Volo.Abp.Ui; +using Volo.Abp.Uow; + +namespace Volo.Abp.Account.Web.Pages.Account +{ + public class LoginModel : AccountModelBase + { + public string ReturnUrl { get; set; } //TODO: Try to automatically bind from querystring! + + public string ReturnUrlHash { get; set; } //TODO: Try to automatically bind from querystring! + + private readonly SignInManager _signInManager; + + public LoginModel(SignInManager signInManager) + { + _signInManager = signInManager; + } + + public void OnGet(string returnUrl = "", string returnUrlHash = "") + { + ReturnUrl = returnUrl; + ReturnUrlHash = returnUrl; + } + + //TODO: Bind input to a property instead of getting as parameter..? + [UnitOfWork] //TODO: Will be removed when we implement action filter + public virtual async Task OnPostAsync(PostInput input, string returnUrl = "", string returnUrlHash = "") + { + ReturnUrl = returnUrl; + ReturnUrlHash = returnUrl; + + if (!ModelState.IsValid) + { + throw new NotImplementedException(); + } + + var result = await _signInManager.PasswordSignInAsync( + input.UserNameOrEmailAddress, + input.Password, + input.RememberMe, + true + ); + + if (!result.Succeeded) + { + throw new UserFriendlyException("Login failed!"); //TODO: Handle other cases, do not throw exception + } + + //TODO: Use LocalRedirect and Url.GetLocalUrl methods instead of a custom one! + return RedirectSafely(returnUrl, returnUrlHash); + } + + public class PostInput + { + [Required] + [MaxLength(255)] + public string UserNameOrEmailAddress { get; set; } + + [Required] + [MaxLength(32)] + public string Password { get; set; } + + public bool RememberMe { get; set; } + } + } +} diff --git a/src/Volo.Abp.Account.Web/Areas/Account/Views/Register/Index.cshtml b/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml similarity index 86% rename from src/Volo.Abp.Account.Web/Areas/Account/Views/Register/Index.cshtml rename to src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml index f0d62fbdf4..b072302928 100644 --- a/src/Volo.Abp.Account.Web/Areas/Account/Views/Register/Index.cshtml +++ b/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml @@ -1,6 +1,8 @@ -
+@page +@model Volo.Abp.Account.Web.Pages.Account.RegisterModel +
-
+
diff --git a/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs new file mode 100644 index 0000000000..299e8cc478 --- /dev/null +++ b/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -0,0 +1,74 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Identity; +using Volo.Abp.Uow; + +namespace Volo.Abp.Account.Web.Pages.Account +{ + public class RegisterModel : AccountModelBase + { + public string ReturnUrl { get; set; } //TODO: Try to automatically bind from querystring! + + public string ReturnUrlHash { get; set; } //TODO: Try to automatically bind from querystring! + + private readonly IdentityUserManager _userManager; + private readonly SignInManager _signInManager; + + public RegisterModel(IdentityUserManager userManager, SignInManager signInManager) + { + _userManager = userManager; + _signInManager = signInManager; + } + + public void OnGet(string returnUrl = "", string returnUrlHash = "") + { + ReturnUrl = returnUrl; + ReturnUrlHash = returnUrl; + } + + //TODO: Bind input to a property instead of getting as parameter..? + [UnitOfWork] //TODO: Will be removed when we implement action filter + public virtual async Task OnPostAsync(PostInput input, string returnUrl = "", string returnUrlHash = "") + { + if (!ModelState.IsValid) + { + throw new NotImplementedException(); + } + + var user = new IdentityUser(GuidGenerator.Create(), input.UserName); + + var result = await _userManager.CreateAsync(user, input.Password); + + if (!result.Succeeded) + { + throw new NotImplementedException(); + } + + await _userManager.SetEmailAsync(user, input.EmailAddress); + + await _signInManager.SignInAsync(user, isPersistent: false); + + //TODO: Use LocalRedirect and Url.GetLocalUrl methods instead of a custom one! + return RedirectSafely(returnUrl, returnUrlHash); + } + + public class PostInput + { + [Required] + [MaxLength(32)] + public string UserName { get; set; } + + [Required] + [EmailAddress] + [MaxLength(255)] + public string EmailAddress { get; set; } + + [Required] + [MaxLength(32)] + public string Password { get; set; } + } + } +} diff --git a/src/Volo.Abp.Account.Web/Properties/launchSettings.json b/src/Volo.Abp.Account.Web/Properties/launchSettings.json new file mode 100644 index 0000000000..6ea8ca0918 --- /dev/null +++ b/src/Volo.Abp.Account.Web/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:53098/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Volo.Abp.Account.Web": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:53099/" + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj b/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj index cff7fb67a5..092e66ec3a 100644 --- a/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj +++ b/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj @@ -1,4 +1,4 @@ - + @@ -11,10 +11,11 @@ false false Volo.Abp.Account.Web + Library - + diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj b/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj index 9de9226814..0eada12839 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj @@ -23,8 +23,4 @@ - - - -