public async Task <IActionResult> ResetPasswordAsync([FromForm] UserParmsDto userParms) { try { await _auth.ResetPassword(userParms.UserName, userParms.Password, true); return(Ok(new { res = "Password reset success" })); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(new { res = "Error resetting password" })); } }
public async Task <IActionResult> ForgetPasswordAsync([FromForm] UserParmsDto userParms) { try { if (!await _auth.UserExists(userParms.UserName)) { return(BadRequest(new { res = "Username not exists" })); } var result = await _auth.ResetPassword(userParms.UserName, userParms.Password, false); if (result) { return(Ok(new { res = "Password reset success" })); } return(BadRequest(new { res = "Error resetting password" })); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(new { res = "Error resetting password" })); } }
public async Task <IActionResult> Login([FromForm] UserParmsDto userParms) { try { var User = await _auth.Login(userParms.UserName, userParms.Password); if (User == null) { return(Unauthorized(new { res = "Username or password is incorrect" })); } if (User.IsAuthorized == false) { return(Unauthorized(new { res = "You are not authorized by admin" })); } var file = _auth.FileFactory(User); var fileobj = File(file, "image/png", "profilePic.png"); var userToReturn = new ReturnFullDetailsOfUser() { Id = User.Id, UserName = User.UserName, ProfilePic = fileobj, Token = GenerateJwtToken(User).Result, Role = User.Role }; return(Ok(userToReturn)); } catch (Exception e) { Console.WriteLine(e); return(Unauthorized()); } }