diff options
Diffstat (limited to 'Backend/Api/Api/Controllers/AuthController.cs')
-rw-r--r-- | Backend/Api/Api/Controllers/AuthController.cs | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/Backend/Api/Api/Controllers/AuthController.cs b/Backend/Api/Api/Controllers/AuthController.cs index d835d97..cbd5eb8 100644 --- a/Backend/Api/Api/Controllers/AuthController.cs +++ b/Backend/Api/Api/Controllers/AuthController.cs @@ -1,5 +1,6 @@ using Api.Interfaces; using Api.Models; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Api.Controllers @@ -8,12 +9,14 @@ namespace Api.Controllers public class AuthController : Controller { private readonly IUserService _userService; - public AuthController(IUserService userService) + private readonly IJwtService _jwtService; + public AuthController(IUserService userService,IJwtService jwtService) { _userService = userService; + _jwtService = jwtService; } - [HttpPost("register")] + [HttpPost("registerdeprecated")] 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 @@ -47,19 +50,26 @@ namespace Api.Controllers } return BadRequest("Pogresno uneti podaci"); } - [HttpPost("registeractual")] + [HttpPost("register")] 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); + switch (msg) + { + case "User Registered": + return Ok(msg); + default: + return BadRequest(msg); + } } [HttpPost("verify")] public async Task<ActionResult<string>> VerifyEmail([FromBody] VerifyUser creds) { + var vrfchk = new Login(); + vrfchk.email = creds.email; + vrfchk.password = creds.password; + if (await _userService.CheckVerification(vrfchk)) + return Ok("User already verified"); var uspeh = await _userService.VerifyUser(creds); if (!uspeh) return BadRequest("Kod netacan ili istekao"); @@ -73,5 +83,31 @@ namespace Api.Controllers return BadRequest("Kod netacan ili istekao"); return Ok("Sifra uspesno resetovana"); } + [HttpPost("forgotpass")] + public async Task<ActionResult<string>> ForgotPass([FromBody] JustMail justMail) + { + if (await _userService.ForgotPassword(justMail)) + return Ok("Email poslat"); + return BadRequest("Email nema registrovan nalog"); + } + [HttpGet("verifytoken/{token}")] + public async Task<ActionResult<string>> VerifyEmailToken(string token) + { + var username =_jwtService.EmailTokenToClaim(token,"username"); + string html; + if (username == null) + { + html = await System.IO.File.ReadAllTextAsync(@"./Assets/VerifyFailed.html"); + return base.Content(html, "text/html"); + } + else + { + html = await System.IO.File.ReadAllTextAsync(@"./Assets/VerifySuccess.html"); + html = html.Replace("{{name}}", username); + + await _userService.VerifyFromToken(token); + return base.Content(html, "text/html"); + } + } } } |