diff options
author | Tamara Jerinic <tamara.jerinic@gmail.com> | 2022-11-01 13:08:01 +0000 |
---|---|---|
committer | Tamara Jerinic <tamara.jerinic@gmail.com> | 2022-11-01 13:08:01 +0000 |
commit | 9376e25847ad481618f9d3e448f9a06e0809e8ac (patch) | |
tree | ebf8781816173f39b9ada8528e2eb55c784f267f /Backend/Api/Api/Controllers/AuthController.cs | |
parent | 41eb14e56a1f0e59347d5d37cb39406ec1ee810a (diff) | |
parent | 55cdd5a31e9da8c50d1971861dca75fadfb63dc4 (diff) |
Merge branch 'develop' into 'master'
Merge dev->master
See merge request BrzoDoLokacije2022/odyssey/brzodolokacije!1
Diffstat (limited to 'Backend/Api/Api/Controllers/AuthController.cs')
-rw-r--r-- | Backend/Api/Api/Controllers/AuthController.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Backend/Api/Api/Controllers/AuthController.cs b/Backend/Api/Api/Controllers/AuthController.cs new file mode 100644 index 0000000..d835d97 --- /dev/null +++ b/Backend/Api/Api/Controllers/AuthController.cs @@ -0,0 +1,77 @@ +using Api.Interfaces; +using Api.Models; +using Microsoft.AspNetCore.Mvc; + +namespace Api.Controllers +{ + [Route("api/auth/")] + public class AuthController : Controller + { + private readonly IUserService _userService; + public AuthController(IUserService userService) + { + _userService = userService; + } + + [HttpPost("register")] + public async Task<ActionResult<string>> Register([FromBody] Register creds) + { + //this is beyond scuffed and will be cleaned up later, when users,login and controllers are made + User novi = new User(); + novi.email = creds.email; + novi.password = creds.password; + novi.username = creds.username; + novi.name = creds.name; + novi.verified = true; + novi.creationDate = DateTime.Now.ToUniversalTime(); + novi._id = ""; + + int ret= await _userService.createUser(novi); + if (ret == -1) + return BadRequest("email already exists"); + if (ret == -2) + return BadRequest("username already exists"); + + return Ok(); + } + [HttpPost("login")] + public async Task<ActionResult<string>> Login([FromBody] Login creds) + { + var id = await _userService.UserIdFromJwt(); + if (id != null) return Forbid(); + + var jwt= await _userService.Login(creds); + if (jwt != null) + { + return Ok(jwt); + } + return BadRequest("Pogresno uneti podaci"); + } + [HttpPost("registeractual")] + public async Task<ActionResult<string>> RegisterActual([FromBody] Register creds) + { + var msg = await _userService.Register(creds); + if (msg == "Email Exists") + return Forbid(msg); + if (msg == "Username Exists") + return Forbid(msg); + return Ok(msg); + } + [HttpPost("verify")] + public async Task<ActionResult<string>> VerifyEmail([FromBody] VerifyUser creds) + { + var uspeh = await _userService.VerifyUser(creds); + if (!uspeh) + return BadRequest("Kod netacan ili istekao"); + return Ok("Uspesno verifikovan"); + } + [HttpPost("resetpass")] + public async Task<ActionResult<string>> ResetPass([FromBody] ResetPass creds) + { + var uspeh = await _userService.ResetPassword(creds); + if (!uspeh) + return BadRequest("Kod netacan ili istekao"); + return Ok("Sifra uspesno resetovana"); + } + } +} |