コード例 #1
0
        public async Task <IActionResult> Register(DtoRegister user)
        {
            var hashedUser = new User()
            {
                Username  = user.Username,
                Email     = user.Email,
                Password  = _iauth.Hashing(user.Password),
                FirstName = user.FirstName,
                LastName  = user.LastName,
                TeamId    = user.TeamId
            };

            //checking if username or email is unique
            var emailCheck = await _icheck.CheckEmail(hashedUser.Email);

            var usernameCheck = await _icheck.CheckUsername(hashedUser.Username);

            if (emailCheck && usernameCheck)
            {
                return(BadRequest("Email and Username is already taken"));
            }
            else if (emailCheck)
            {
                return(BadRequest("Email is already taken"));
            }
            else if (usernameCheck)
            {
                return(BadRequest("Username is already taken"));
            }

            await _context.User.AddAsync(hashedUser);

            await _context.SaveChangesAsync();

            return(Ok(hashedUser));
        }