Exemplo n.º 1
0
        public ActionResult Create()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, "Not authorized to manage users"))
                return new HttpUnauthorizedResult();

            var model = new UserCreateViewModel();
            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult CreatePOST(UserCreateViewModel createModel)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, "Not authorized to manage users"))
                return new HttpUnauthorizedResult();

            if (ModelState.IsValid)
            {
                if (!_userService.VerifyUserUnicity(createModel.UserName, createModel.Email))
                {
                    ModelState.AddModelError("UserName", "User with that username and/or email already exists.");
                }
            }

            if (ModelState.IsValid)
            {
                var user = _membershipService.CreateUser(new CreateUserParams(
                                                   createModel.UserName,
                                                   createModel.Password,
                                                   createModel.Email, true));
                Services.Notifier.Information("User created");
                return RedirectToAction("Index");
            }

            Services.TransactionManager.Cancel();
            return View(createModel);
        }