mirror of https://github.com/abpframework/abp.git
14 changed files with 201 additions and 159 deletions
@ -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<IdentityUser> _signInManager; |
|||
|
|||
public LoginController(SignInManager<IdentityUser> signInManager) |
|||
{ |
|||
_signInManager = signInManager; |
|||
} |
|||
|
|||
public IActionResult Index() |
|||
{ |
|||
return View(); |
|||
} |
|||
|
|||
[HttpPost] |
|||
public async Task<IActionResult> 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); |
|||
} |
|||
} |
|||
} |
|||
@ -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<IdentityUser> _signInManager; |
|||
|
|||
public RegisterController(IdentityUserManager userManager, SignInManager<IdentityUser> signInManager) |
|||
{ |
|||
_userManager = userManager; |
|||
_signInManager = signInManager; |
|||
} |
|||
|
|||
public IActionResult Index() |
|||
{ |
|||
return View(); |
|||
} |
|||
|
|||
[HttpPost] |
|||
//TODO: [ValidateAntiForgeryToken]
|
|||
public async Task<IActionResult> 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); |
|||
} |
|||
} |
|||
} |
|||
@ -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; } |
|||
} |
|||
} |
|||
@ -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; } |
|||
} |
|||
} |
|||
@ -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<IdentityUser> _signInManager; |
|||
|
|||
public LoginModel(SignInManager<IdentityUser> 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<IActionResult> 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; } |
|||
} |
|||
} |
|||
} |
|||
@ -1,6 +1,8 @@ |
|||
<div class="row"> |
|||
@page |
|||
@model Volo.Abp.Account.Web.Pages.Account.RegisterModel |
|||
<div class="row"> |
|||
<div class="col-md-3"> |
|||
<form asp-action="Index" method="post"> |
|||
<form method="post"> |
|||
<div class="form-group"> |
|||
<label for="UserName">Username</label> |
|||
<input type="text" class="form-control" id="UserName" name="UserName" required> |
|||
@ -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<IdentityUser> _signInManager; |
|||
|
|||
public RegisterModel(IdentityUserManager userManager, SignInManager<IdentityUser> 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<IActionResult> 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; } |
|||
} |
|||
} |
|||
} |
|||
@ -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/" |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue