Exemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] AppUser user)
        {
            if (!ModelState.IsValid)
            {
                Trace.TraceInformation("Failed registration with invalid data");
                return(BadRequest(ModelState));
            }
            try
            {
                var registered = await commands.Register(user.UserName, user.Password);

                var helper = new JWTHelper(options);

                return(Created("N/A", helper.GetJwt(user.UserName)));
            }
            catch (ArgumentException)
            {
                var errors = new Dictionary <string, string>();
                errors.Add("error", $"Username {user.UserName} is already in use, please try another name");
                return(BadRequest(errors));
            }
        }