Esempio n. 1
0
        public async Task <IActionResult> SignUp([FromBody] SignUpVm signUp)
        {
            var us = await _usersService.isUserNameExcist(signUp.Username);

            if (us)
            {
                return(BadRequest(new JsonResult("نام کاربری تکراری است")));
            }
            var q = await _usersService.AddNewUserAsync(signUp);

            return(await Login(q));
        }
Esempio n. 2
0
        public async Task <AuthenticationResult> AddNewRegisterAsync(AddUserRequest users, string password)
        {
            var user = await _usersService.FindByUsernameAsync(users.userName);

            if (user != null)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "User with this username already exist" }
                });
            }

            var userEmail = await _usersService.FindByEmailAsync(users.email);

            if (userEmail != null)
            {
                return(new AuthenticationResult
                {
                    Errors = new[] { "User with this email already exist" }
                });
            }


            var hashPassword = BCrypt.Net.BCrypt.HashPassword(password);
            var createUser   = await _usersService.AddNewUserAsync(users, hashPassword);

            var newUser = new User()
            {
                email    = users.email,
                userName = users.userName,
            };

            if (!createUser.Succeeded)
            {
                return(new AuthenticationResult
                {
                    Errors = createUser.Errors.Select(x => x)
                });
            }

            newUser.id = createUser.Id;
            return(GenerateAuthenticationResult(newUser));
        }