Ejemplo n.º 1
0
        public async Task <IActionResult> RegisterUser([FromBody] UserRegistration newUser, CancellationToken ct = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid user registration details"));
            }
            User user = await _userService.CreateNewUserAsync(newUser);

            if (user == null)
            {
                return(BadRequest("An Error Occurred"));
            }
            return(Ok(user));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RequestPassResetEmail(string email, CancellationToken ct = default)
        {
            User user = await _userService.GetByIdAsync(await _userService.GetUUIDFromEmail(email, ct));

            if (user == null)
            {
                return(BadRequest());
            }

            string token = await _authenticationService.AddResetHash(user, ct);

            _emailService.SendPassRestEmail(user, token);
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AuthenticateUser([FromBody] AuthenticatingUser authUser, bool needsTokens = true, CancellationToken ct = default)
        {
            //TODO: require email confirmation
            try
            {
                User user = await _authenticationService.Authenticate(authUser, needsTokens, ct);

                if (user == null)
                {
                    return(NotFound("Invalid login attempt"));
                }
                return(Ok(user));
            }
            catch (AuthenticationException ex) {
                return(BadRequest(ex.Message));
            }
        }