Compare commits
No commits in common. 'authentication' and 'dev' have entirely different histories.
authentica
...
dev
7 changed files with 3 additions and 134 deletions
@ -1,46 +0,0 @@
@@ -1,46 +0,0 @@
|
||||
using System.IdentityModel.Tokens.Jwt; |
||||
using System.Security.Claims; |
||||
using System.Text; |
||||
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.IdentityModel.Tokens; |
||||
|
||||
namespace backend.Controllers; |
||||
|
||||
[ApiController] |
||||
[Route("[controller]")]
|
||||
public class AuthController : ControllerBase |
||||
{ |
||||
public IConfiguration _configuration; |
||||
public AuthController(IConfiguration configuration) |
||||
{ |
||||
_configuration = configuration; |
||||
} |
||||
|
||||
[HttpPost("login")] |
||||
public async Task<IActionResult> Login(string username, string password) |
||||
{ |
||||
if (username == "" || password == "") |
||||
{ |
||||
return BadRequest("Invalid username or password"); |
||||
} |
||||
|
||||
if (username == "test" && password == "test") |
||||
{ |
||||
var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:secret"])); |
||||
var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); |
||||
|
||||
var tokeOptions = new JwtSecurityToken( |
||||
issuer: _configuration["Jwt:Issuer"], |
||||
audience: _configuration["Jwt:Audience"], |
||||
claims: new List<Claim>(), |
||||
expires: DateTime.Now.AddDays(1), |
||||
signingCredentials: signinCredentials |
||||
); |
||||
|
||||
var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions); |
||||
return Ok(new { Token = tokenString }); |
||||
} |
||||
|
||||
return BadRequest("Invalid username or password"); |
||||
} |
||||
} |
@ -1,8 +0,0 @@
@@ -1,8 +0,0 @@
|
||||
namespace backend.DTO; |
||||
|
||||
public class UserDTO |
||||
{ |
||||
public string UserName { get; set; } |
||||
public string? Email { get; set; } |
||||
public string Password { get; set; } |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
using MongoDB.Bson.Serialization.Attributes; |
||||
|
||||
namespace backend.Models; |
||||
|
||||
public class UserIdentity |
||||
{ |
||||
[BsonId] |
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] |
||||
public string Id { get; set; } |
||||
public string UserName { get; set; } |
||||
public string Password { get; set; } |
||||
public string Email { get; set; } |
||||
public string Role { get; set; } |
||||
} |
Loading…
Reference in new issue