Beispiel #1
0
        public async Task <IHttpActionResult> Register(RegisterUserMessage message)
        {
            await Task.Delay(3000);

            // verify if login credentials are correct
            if (!message.IsValid)
            {
                return(BadRequest("The Register User has some invalid data."));
            }

            // if user exists, throw
            var usernameUser = await userManager.FindByNameAsync(message.Username);

            if (usernameUser != null)
            {
                return(BadRequest("There is already a User registered with these credentials."));
            }

            // create a new User
            string     passwordHash = new PasswordHasher().HashPassword(message.Password);
            CustomUser customUser   = CustomUser.Create(Guid.NewGuid().ToString(), message.Username, message.Email,
                                                        passwordHash, DateTime.Now.ToString()
                                                        );

            // register
            await userManager.CreateAsync(customUser);

            return(Ok("User has been registered."));
        }