Ejemplo n.º 1
0
        public bool RemoveUser(string userId)
        {
            if (!AppUserState.IsAdmin)
            {
                throw new UnauthorizedAccessException("Unauthorized Access: You have to be signed in as an administrator in delete snippets.");
            }

            using (var userBus = new busUser())
            {
                return(userBus.Delete(userId));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Register(FormCollection formVars)
        {
            string id = formVars["Id"];

            if (!string.IsNullOrEmpty(formVars["btnDeleteAccount"]))
            {
                if (string.IsNullOrEmpty(AppUserState.UserId))
                {
                    return(View("Register", ViewModel));
                }

                if (!busUser.Delete(AppUserState.UserId))
                {
                    ViewModel.ErrorDisplay.ShowError("Unable to delete this account: " + busUser.ErrorMessage);
                }
                else
                {
                    IdentitySignout();
                    return(RedirectToAction("New", "Snippet"));
                }

                return(View("Register", ViewModel));
            }

            ViewData["IsNew"] = false;

            string confirmPassword = formVars["confirmPassword"];

            bool isNew = false;
            User user  = null;

            if (string.IsNullOrEmpty(id) || busUser.Load(id) == null)
            {
                user = busUser.NewEntity();
                ViewData["IsNew"] = true;

                // not validated yet
                user.InActive = true;
                isNew         = true;
            }
            else
            {
                user = busUser.Entity;
            }

            UpdateModel <User>(busUser.Entity,
                               new string[] { "Name", "Email", "Password", "Theme" });

            if (ModelState.Count > 0)
            {
                ErrorDisplay.AddMessages(ModelState);
            }

            if (string.IsNullOrEmpty(user.OpenId) &&
                confirmPassword != user.Password)
            {
                ErrorDisplay.AddMessage("Please make sure both password values match.", "confirmPassword");
            }


            if (ErrorDisplay.DisplayErrors.Count > 0)
            {
                return(View("Register", ViewModel));
            }

            if (!busUser.Validate())
            {
                ErrorDisplay.Message = "Please correct the following:";
                ErrorDisplay.AddMessages(busUser.ValidationErrors);
                return(View("Register", ViewModel));
            }

            if (!busUser.Save())
            {
                ErrorDisplay.ShowError("Unable to save User: "******"Register", ViewModel));
            }

            AppUserState appUserState = new AppUserState();

            appUserState.FromUser(user);
            IdentitySignin(appUserState, appUserState.UserId);

            if (isNew)
            {
                SetAccountForEmailValidation();

                ErrorDisplay.HtmlEncodeMessage = false;
                ErrorDisplay.ShowMessage(
                    @"Thank you for creating an account...
<hr />
<p>Before you can post and save new CodePastes we need to
verify your email address.</p>
<p>We just sent you an email with a confirmation
code. Please follow the instructions in the email 
to validate your email address.</p>");

                return(View("Register", ViewModel));
            }


            return(RedirectToAction("New", "Snippet", null));
        }