public ActionResult Delete(AskDeleteModel model)
        {
            if (ModelState.IsValid)
            {
                StorageAccount storageAccount = _storageAccountService.Load(model.StorageAccountId);
                if (storageAccount == null)
                {
                    ModelState.AddModelError("id", ValidationResources.StorageAccountNotFoundError);
                    return(View("AskDelete"));
                }

                Identity identity = User.Identity;

                if (storageAccount.UserId != identity.UserId)
                {
                    ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError);
                    return(View("AskDelete"));
                }

                _storageAccountService.DeleteStorageAccount(storageAccount.Id);

                TempData.AddRequestSuccessMessage(string.Format(CultureInfo.CurrentCulture, SuccessMessagesResources.StorageAccountDeletedFormat, storageAccount.AccountName));

                if (Url.IsLocalUrl(model.ReturnUrl))
                {
                    return(Redirect(model.ReturnUrl));
                }

                return(RedirectToAction("StorageAccounts", "User", new { Id = identity.UserId }));
            }
            return(View("AskDelete", model));
        }
        public ActionResult Edit([ModelBinder(typeof(StorageAccountSettingsModelBinder))] object model)
        {
            if (ModelState.IsValid)
            {
                int  storageAccountId;
                long stamp;

                if (!int.TryParse(Request.Form[Constants.StorageAccountIdFormKey], NumberStyles.Integer, CultureInfo.InvariantCulture, out storageAccountId))
                {
                    ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountNotFoundError);
                    return(View());
                }

                if (!long.TryParse(Request.Form[Constants.StampFormKey], NumberStyles.Integer, CultureInfo.InvariantCulture, out stamp))
                {
                    ModelState.AddModelError("storage_account_id", ValidationResources.BadRequestError);
                    return(View());
                }

                //account and plugin should be valid, they were checked by model binder
                StorageAccount account = _storageAccountService.Load(storageAccountId);

                Identity identity = (Identity)HttpContext.User.Identity;
                if (identity.UserId != account.UserId)
                {
                    ModelState.AddModelError("forbidden", ValidationResources.NoPermissionsError);
                    return(View());
                }

                IStoragePlugin storagePlugin = _storagePluginsService.GetStoragePlugin(account.StoragePluginId);

                try
                {
                    storagePlugin.ApplyConfiguration(storageAccountId, DateTime.FromBinary(stamp), model);
                    TempData.AddRequestSuccessMessage(string.Format(CultureInfo.CurrentCulture, SuccessMessagesResources.StorageAccountUpdatedFormat, account.AccountName));
                    return(RedirectToAction("Edit"));
                }
                catch (StaleObjectException)
                {
                    ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountStalled);
                }
                catch (ObjectNotExistsException)
                {
                    ModelState.AddModelError("storage_account_id", ValidationResources.StorageAccountNotFoundError);
                }
            }
            return(View(model));
        }
예제 #3
0
        public ActionResult ChangePassword(ProfilePasswordModel passwordModel)
        {
            Identity identity = User.Identity;

            if (ModelState.IsValid)
            {
                try
                {
                    _membershipService.ChangePassword(identity.UserId, passwordModel.NewPassword, passwordModel.OldPassword, DateTime.FromBinary(passwordModel.Stamp));
                    TempData.AddRequestSuccessMessage(SuccessMessagesResources.PasswordChangedInfo);
                    return(RedirectToAction("Edit"));
                }
                catch (StaleUserException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountStalled);
                }
                catch (UserNotExistsException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountNotFound);
                }
                catch (PasswordsMismatchException)
                {
                    ModelState.AddModelError("profile", ValidationResources.OldPasswordsMismatchError);
                }
                catch (InvalidPasswordException)
                {
                    ModelState.AddModelError("NewPassword", ValidationResources.RegInvalidPassword);
                }
            }

            //smth went wrong
            ProfileBaseModel baseModel = null;
            ProfileModel     model     = new ProfileModel
            {
                BaseModel     = InitBaseProfileModel(ref baseModel, _userService.Load(identity.UserId)),
                PasswordModel = InitProfilePasswordModel(ref passwordModel, null)
            };
            var resultAction = Condition()
                               .DoIfNotAjax(() => View("Edit", model))
                               .DoIfAjax(() => Json(new AjaxResult
            {
                MainPanelHtml = this.RenderViewToString("~/Views/Account/Controls/ProfileControl.ascx", model)
            }, JsonRequestBehavior.AllowGet));

            return(resultAction);
        }
예제 #4
0
        public ActionResult Edit(ProfileBaseModel baseModel)
        {
            if (ModelState.IsValid)
            {
                Identity identity = User.Identity;

                try
                {
                    _membershipService.UpdateUser(identity.UserId, baseModel.UserName, baseModel.Locale, baseModel.TimeZone, DateTime.FromBinary(baseModel.Stamp), identity);
                    TempData.AddRequestSuccessMessage(SuccessMessagesResources.ProfileUpdateSuccessMessage);
                    return(RedirectToAction("Edit"));
                }
                catch (StaleUserException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountStalled);
                }
                catch (InvalidUserNameException)
                {
                    ModelState.AddModelError("UserName", ValidationResources.RegInvalidUserName);
                }
                catch (UserNotExistsException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountNotFound);
                }
            }

            ProfilePasswordModel passwdModel = null;

            baseModel = InitBaseProfileModel(ref baseModel, null);
            ProfileModel model = new ProfileModel
            {
                BaseModel     = baseModel,
                PasswordModel = InitProfilePasswordModel(ref passwdModel, null)
            };
            var resultAction = Condition()
                               .DoIfNotAjax(() => View(model))
                               .DoIfAjax(() => Json(new AjaxResult
            {
                MainPanelHtml = this.RenderViewToString("~/Views/Account/Controls/ProfileControl.ascx", model)
            }, JsonRequestBehavior.AllowGet));

            return(resultAction);
        }