Exemplo n.º 1
0
        public IHttpActionResult AddUser([FromBody] RegisterUserRequest registerRequest)
        {
            if (registerRequest.Login == null ||
                registerRequest.Password == null ||
                registerRequest.Email == null)
            {
                return(Content(HttpStatusCode.BadRequest, new ErrorResponse(Errors.EMPTY_ONE_OR_MORE_FIELD)));
            }

            if (registerRequest.Login.Count() <= 6)
            {
                return(Content(HttpStatusCode.BadRequest, new ErrorResponse(Errors.INCORRECT_LOGIN_LENGHT)));
            }

            if (registerRequest.Password.Count() < 6 || registerRequest.Password.Count() > 20)
            {
                return(Content(HttpStatusCode.BadRequest, new ErrorResponse(Errors.INCORRECT_PASSWORD_LENGHT)));
            }

            int indexOfDog = registerRequest.Email.LastIndexOf('@');

            if (indexOfDog == -1 || registerRequest.Email.Count() < 5 || indexOfDog >= registerRequest.Email.LastIndexOf('.'))
            {
                return(Content(HttpStatusCode.BadRequest, new ErrorResponse(Errors.INCORRECT_EMAIL)));
            }

            var result = _authenticationManager.AddUser(registerRequest);

            if (result == Errors.OK)
            {
                return(Content(HttpStatusCode.OK, "User has been added"));
            }
            return(Content(HttpStatusCode.BadRequest, new ErrorResponse(result)));
        }