Пример #1
0
        public async Task <IActionResult> Register([FromBody] RegisterDto registerDto)
        {
            // 1 使用用户名创建用户对象
            var user = new ApplicationUser()
            {
                UserName = registerDto.Email,
                Email    = registerDto.Email
            };

            // 2 hash密码,保存用户
            var result = await _userManager.CreateAsync(user, registerDto.Password);

            if (!result.Succeeded)
            {
                return(BadRequest());
            }

            // 3 初始化购物车
            var shoppingCart = new ShoppingCart()
            {
                Id     = Guid.NewGuid(),
                UserId = user.Id
            };
            await _touristRouteRepository.CreateShoppingCart(shoppingCart);

            await _touristRouteRepository.SaveAsync();

            // 4 return
            return(Ok());
        }
Пример #2
0
        [HttpPost("register")] // 用户注册 API
        public async Task <IActionResult> Register([FromBody] RegisterDto registerDto)
        {
            // 这里登陆密码要求必须有一个大写字母和一个小写字母,这是框架系统规定的密码最低强度
            // 1. 使用用户名创建用户对象
            var user = new ApplicationUser()
            {
                UserName = registerDto.Email,
                Email    = registerDto.Email
            };
            // 2. hash 密码,保存用户,即将用户登陆密码加密散列
            var result = await _userManager.CreateAsync(user, registerDto.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }
            // 3. 初始化购物车
            var shoppingCart = new ShoppingCart()
            {
                Id     = Guid.NewGuid(),
                UserId = user.Id
            };
            await _touristRouteRepository.CreateShoppingCart(shoppingCart);

            await _touristRouteRepository.SaveAsync();

            // 4. return
            return(Ok());
        }
        public async Task <IActionResult> Register([FromBody] RegisterDto registerDto)
        {
            // 1 Create user object with user name
            var user = new ApplicationUser()
            {
                UserName = registerDto.Email,
                Email    = registerDto.Email
            };

            // 2 hash password, save user
            var result = await _userManager.CreateAsync(user, registerDto.Password);

            if (!result.Succeeded)
            {
                return(BadRequest());
            }

            // 3 Initialize shopping cart
            var shoppingCart = new ShoppingCart()
            {
                Id     = Guid.NewGuid(),
                UserId = user.Id
            };
            await _touristRouteRepository.CreateShoppingCart(shoppingCart);

            await _touristRouteRepository.SaveAsync();

            // 4 return
            return(Ok());
        }
        public async Task <IActionResult> Register([FromBody] RegisterDto registerDto)
        {
            // create user object
            var user = new ApplicationUser()
            {
                UserName = registerDto.Email,
                Email    = registerDto.Email,
            };

            // hash password
            var result = await _userManager.CreateAsync(user, registerDto.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            // create a shopping cart for user
            var shoppingCart = new ShoppingCart()
            {
                Id     = Guid.NewGuid(),
                UserId = user.Id,
            };
            await _touristRouteRepository.CreateShoppingCart(shoppingCart);

            await _touristRouteRepository.SaveAsync();

            // return dto
            return(Ok());
        }