Exemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] RegiserViewModel data)
        {
            if (userRepository.DoesUsernameExist(data.Username))
            {
                return(BadRequest("Sorry this username has already been used"));
            }

            if (userRepository.DoesEmailExist(data.Email))
            {
                return(BadRequest("Sorry this email address has already been used"));
            }

            var result = await userRepository.Create(data.Username, data.Email, data.Password);

            if (result == null)
            {
                logger.Log(LogLevel.Error, "User: "******" hasn't been registered");
                return(BadRequest("Sorry you can't be registered at the moment"));
            }

            var emailResult = await email.SendCofirmationEmail(result.Username,
                                                               result.Email,
                                                               result.EmailConfirmationToken);

            if (emailResult != HttpStatusCode.OK)
            {
                logger.Log(LogLevel.Error, "User: "******"registration email hasn't been sent");
            }

            return(Created("api/v1/users/register", "You've been registered"));
        }