コード例 #1
0
        public async Task <IActionResult> Register([FromBody] Views.RegisterRequest input)
        {
            try
            {
                var res = await _authService.Register(input);

                return(Ok(res));
            }
            catch
            {
                return(BadRequest());
            }
        }
コード例 #2
0
        public async Task <Views.RegisterResponse> Register(Views.RegisterRequest input)
        {
            // Check if data has been provided and that passwords match
            if (string.IsNullOrEmpty(input.Email) || string.IsNullOrEmpty(input.Password) || input.Password != input.PasswordVerify)
            {
                throw new Exception();
            }

            // Find user with email in context
            var existingUser = _context.Users.SingleOrDefault(x => x.Email == input.Email);

            // Check if existing user exists
            if (existingUser != null)
            {
                throw new Exception();
            }

            var newUser = new Entities.User
            {
                Email        = input.Email,
                Password     = input.Password,
                FirstName    = input.FirstName,
                LastName     = input.LastName,
                CreatedAt    = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
                Activated    = false,
            };
            await _context.AddAsync(newUser);

            await _context.SaveChangesAsync();

            return(new Views.RegisterResponse
            {
                Email = newUser.Email
            });
        }