Пример #1
0
        public async Task <ActionResult> SignUpAsync([FromBody] UserModel user)
        {
            try
            {
                UserModel userResult = await database.GetUser(user.username);

                if (userResult != null)
                {
                    return(BadRequest("User name is already taken!"));
                }

                string passwordHash = BCrypt.Net.BCrypt.HashPassword(user.password);
                await database.PostUser(user.username, passwordHash);

                return(Ok());
            } catch (Exception)
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task <UserModel> GetCurrentUserAsync(string jwt)
        {
            try
            {
                DatabaseUserConnector database   = new DatabaseUserConnector();
                JWTService            jWTService = new JWTService();

                var       token = jWTService.Verify(jwt);
                UserModel user  = await database.GetUser(token.Issuer);

                if (user == null)
                {
                    throw new Exception();
                }
                return(user);
            }
            catch
            {
                throw new Exception();
            }
        }