-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from nixhantb/feature/nishantb/authentication
Feature/nishantb/authentication
- Loading branch information
Showing
57 changed files
with
4,887 additions
and
1,182 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 |
---|---|---|
|
@@ -51,4 +51,3 @@ artifacts/ | |
|
||
#Ignore File holding secrects | ||
jwtkey.key | ||
Migrations |
133 changes: 0 additions & 133 deletions
133
Server/JobLeet.WebApi/JobLeet.Api/Controllers/Accounts/V1/BaseAccountsController.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
Server/JobLeet.WebApi/JobLeet.Api/Controllers/Accounts/V1/LoginUserController.cs
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
Server/JobLeet.WebApi/JobLeet.Api/Controllers/Accounts/V1/RegisterUserController.cs
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
Server/JobLeet.WebApi/JobLeet.Api/Controllers/Accounts/V1/RoleController.cs
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
Server/JobLeet.WebApi/JobLeet.Api/Controllers/Identity/Accounts/AccountsController.cs
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,89 @@ | ||
using JobLeet.WebApi.JobLeet.Api.Models.Identity.Accounts; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace JobLeet.WebApi.JobLeet.Api.Controllers.Identity.Accounts | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class AccountController : ControllerBase | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly SignInManager<IdentityUser> _signInManager; | ||
private readonly ILogger<AccountController> _logger; | ||
|
||
public AccountController( | ||
UserManager<IdentityUser> userManager, | ||
SignInManager<IdentityUser> signInManager, | ||
ILogger<AccountController> logger | ||
) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
_logger = logger; | ||
} | ||
|
||
[HttpPost("register")] | ||
public async Task<IActionResult> Register([FromBody] RegisterModel model) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var user = new IdentityUser { UserName = model.Email, Email = model.Email }; | ||
var result = await _userManager.CreateAsync(user, model.Password); | ||
|
||
if (result.Succeeded) | ||
{ | ||
_logger.LogInformation("User created a new account with password."); | ||
// Send email confirmation link | ||
return Ok( | ||
new | ||
{ | ||
message = "Registration successful, please check your email for confirmation.", | ||
} | ||
); | ||
} | ||
|
||
return BadRequest(result.Errors); | ||
} | ||
|
||
return BadRequest("Invalid data."); | ||
} | ||
|
||
[HttpPost("login")] | ||
public async Task<IActionResult> Login([FromBody] LoginModel model) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var result = await _signInManager.PasswordSignInAsync( | ||
model.Email, | ||
model.Password, | ||
model.RememberMe, | ||
lockoutOnFailure: true | ||
); | ||
// @2FA | ||
if (result.Succeeded) | ||
{ | ||
_logger.LogInformation("User logged in."); | ||
return Ok(new { message = "Login successful" }); | ||
} | ||
|
||
if (result.IsLockedOut) | ||
{ | ||
return BadRequest("Account is locked out."); | ||
} | ||
|
||
return BadRequest("Invalid login attempt."); | ||
} | ||
|
||
return BadRequest("Invalid login attempt."); | ||
} | ||
|
||
[HttpPost("logout")] | ||
public async Task<IActionResult> Logout() | ||
{ | ||
await _signInManager.SignOutAsync(); | ||
_logger.LogInformation("User logged out."); | ||
return Ok(new { message = "Logout successful" }); | ||
} | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
Server/JobLeet.WebApi/JobLeet.Api/Middlewares/JwtMiddleware/JwtMiddleWare.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.