Пример #1
0
        //REGISTER - create;
        public User Register(UserRegsistration creds)
        {
            //generate userId
            //hash the pass
            string hash = BCrypt.Net.BCrypt.HashPassword(creds.Password);
            string id   = Guid.NewGuid().ToString();

            int success = _db.Execute(@"
            INSERT INTO users (id, username, email, hash)
            VALUES (@id, @username, @email, @hash);
            ", new
            {
                id,
                username = creds.Username,
                email    = creds.Email,
                hash,
            });

            if (success != 1)
            {
                return(null);
            }

            return(new User()
            {
                Username = creds.Username,
                Email = creds.Email,
                Hash = null,
                Id = id
            });
        }
Пример #2
0
        public async Task <User> Register([FromBody] UserRegsistration creds)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }
            User user = _repo.Register(creds);

            if (user == null)
            {
                return(null);
            }
            user.SetClaims();
            await HttpContext.SignInAsync(user._principal);

            return(user);
        }