public async Task <IActionResult> GetUsers() { var users = await _auth.Users(); List <ReturnFullDetailsOfUser> fullDetailsOfUsers = new List <ReturnFullDetailsOfUser>(); foreach (var user in users) { 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, Role = user.Role, IsAuthorized = user.IsAuthorized }; fullDetailsOfUsers.Add(userToReturn); } return(Ok(fullDetailsOfUsers)); }
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()); } }