-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a15bf4
commit 57b7ebc
Showing
10 changed files
with
906 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace MoviesApi.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class AccountController : ControllerBase | ||
{ | ||
private readonly UserManager<AppUser> _userManager; | ||
public AccountController(UserManager<AppUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
[HttpPost] | ||
public async Task<IActionResult> RegisterNewUser(dtoNewUser dtouser) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
//map dto with appuser | ||
AppUser appUser = new() | ||
{ | ||
UserName = dtouser.userName, | ||
Email = dtouser.email, | ||
}; | ||
IdentityResult result = await _userManager.CreateAsync(appUser, dtouser.password); | ||
if (result.Succeeded) | ||
{ | ||
return Ok("Success"); | ||
} | ||
else | ||
{ | ||
foreach (var item in result.Errors) | ||
{ | ||
ModelState.AddModelError("", item.Description); | ||
} | ||
} | ||
} | ||
return BadRequest(ModelState); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace MoviesApi.Dtos | ||
{ | ||
public class dtoNewUser | ||
{ | ||
[Required] | ||
public string userName { get; set; } = string.Empty; | ||
|
||
[Required] | ||
public string password { get; set; } | ||
|
||
[Required] | ||
public string email { get; set; } | ||
|
||
public string? phoneNumber { get; set; } | ||
} | ||
} |
Oops, something went wrong.