コード例 #1
0
        public async Task <ActionResult> CreateUser(NewUserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("New", model));
            }

            var foundUser = UserService.GetUser(model.Username, model.EmailAddress);

            if (foundUser != null)
            {
                ModelState.AddModelError("Username", "A user with this username or email address is already registered.");
                return(View("New", model));
            }

            if (model.Password != model.PasswordConfirmation)
            {
                ModelState.AddModelError("Password", "Passwords did not match.");
                return(View("New", model));
            }

            AuthenticatedUser user;

            try
            {
                user = await AuthService.Register(model.Username, model.EmailAddress, model.FullName, CredentialBuilder.CreatePbkdf2Password(model.Password));
            }
            catch (EntityException ex)
            {
                ModelState.AddModelError("Register", ex.Message);
                return(View("New", model));
            }

            return(SafeRedirect(Url.AdminUsers()));
        }