Exemple #1
0
        public IActionResult AddUser([FromForm] UserModel userModel)
        {
            if (logic.IsUsernameExists(userModel.UserName))
            {
                return(BadRequest("Username already taken"));
            }

            userModel.Password = HashPasswordHelper.HashPasswordSHA512(userModel.Password);


            logic.AddUser(userModel);

            userModel.JwtToken = jwtHelper.GetJwtToken(userModel.UserName, userModel.Role);

            userModel.Password = null;

            return(Created("api/users/" + userModel.ID, userModel));
        }
 public UserModel GetUserByCredentials(CredentialsModel credentials)
 {
     return(DB.Users.Select(u => new UserModel(u)).ToList().SingleOrDefault(u => u.UserName == credentials.Username && u.Password == HashPasswordHelper.HashPasswordSHA512(credentials.Password)));
 }