public async Task <IActionResult> register([FromBody] SimulationUserCreateDTO user)
        {
            await write_latest();

            if (user.Username == "" || user.Username is null)
            {
                return(BadRequest("You have to enter a username"));
            }
            if (!user.Email.Contains('@'))
            {
                return(BadRequest("You have to enter a valid email address"));
            }
            if (user.Pwd == "" || user.Pwd is null)
            {
                return(BadRequest("You have to enter a password"));
            }

            var exist = await UserRepo.ReadAsync(user.Username);

            if (exist is not null)
            {
                return(BadRequest("The username is already taken"));
            }

            await UserRepo.CreateAsync(new UserCreateDTO { Username = user.Username, Email = user.Email, Password1 = user.Pwd, Password2 = user.Pwd });

            return(Ok("You were succesfully registered and can login now"));
        }
Example #2
0
        public async Task <IActionResult> register([FromBody] SimulationUserCreateDTO user)
        {
            logger.LogInformation($"SIMULATION: A user is registering");
            if (!reqFromSimulator(out var result))
            {
                return(result);
            }
            await write_latest();

            var res = await UserRepo.CreateAsync(new UserCreateDTO { Username = user.Username, Email = user.Email, Password1 = user.Pwd, Password2 = user.Pwd });

            switch (res)
            {
            case MISSING_PASSWORD:
                logger.LogError("SIMULATION: No password received");
                return(BadRequest("You have to enter a password"));

            case MISSING_USERNAME:
                logger.LogError("SIMULATION: No username received");
                return(BadRequest("You have to enter a username"));

            case INVALID_EMAIL:
                logger.LogError("SIMULATION: Email is invalid");
                return(BadRequest("You have to enter a valid email address"));

            case PASSWORD_MISMATCH:
                logger.LogError("SIMULATION: Password mismatch");
                return(BadRequest("Passwords are not matching"));

            case USERNAME_TAKEN:
                logger.LogError("SIMULATION: Username already taken");
                return(BadRequest("The username is already taken"));

            case EMAIL_TAKEN:
                logger.LogError("SIMULATION: Email already taken");
                return(BadRequest("The email is already taken"));

            case SUCCESS:
            default:
                MinitwitController.TotalUsers.IncTo(UserRepo.GetTotalUsers());
                return(NoContent());
            }
        }