コード例 #1
0
        public ActionResult Settings()
        {
            var svc     = new AppService();
            var setting = svc.GetSettings();

            if (setting != null)
            {
                var settingModel = new LocalSettingModel
                {
                    SettingId    = setting.SettingId,
                    FolderPath   = setting.FolderPath,
                    BackupFolder = setting.BackupFolder,
                    BackupName   = setting.BackupName
                };

                return(View(settingModel));
            }
            else
            {
                var settingModel = new LocalSettingModel
                {
                    SettingId = Guid.NewGuid()
                };

                return(View(settingModel));
            }


            //return View();
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: fccoul/InterfaceDDI
        //public ActionResult Settings()
        public ActionResult Settings(ManageMessageId?message)
        {
            UserProfile _user;
            int         IDCurrentUser = WebSecurity.GetUserId(User.Identity.Name);

            using (UsersContext db = new UsersContext())
            {
                _user = db.UserProfiles.Where(w => w.UserId == IDCurrentUser).FirstOrDefault();
            }

            //MembershipUser mship = Membership.GetUser(_user.UserName,false);
            //string pass = mship.GetPassword();

            ViewBag.Email = _user.EmailID;
            LocalSettingModel sett = new LocalSettingModel();

            sett.Email = _user.EmailID;

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Votre mot de passe été modifié."
               : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
               : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
               : "";
            ViewBag.HasLocalPassword = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
            ViewBag.ReturnUrl        = Url.Action("Manage");

            return(View(sett));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: fccoul/InterfaceDDI
        public ActionResult Settings(LocalSettingModel model)
        {
            bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));

            ViewBag.HasLocalPassword = hasLocalAccount;
            ViewBag.ReturnUrl        = Url.Action("Settings");
            if (hasLocalAccount)
            {
                if (ModelState.IsValid)
                {
                    // ChangePassword will throw an exception rather than return false in certain failure scenarios.
                    bool changePasswordSucceeded;
                    try
                    {
                        changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
                    }
                    catch (Exception)
                    {
                        changePasswordSucceeded = false;
                    }


                    if (changePasswordSucceeded)
                    {
                        //-------------Email
                        UserProfile _user;
                        bool        emailUpdated  = false;
                        int         IDCurrentUser = WebSecurity.GetUserId(User.Identity.Name);
                        using (UsersContext db = new UsersContext())
                        {
                            _user         = db.UserProfiles.Where(w => w.UserId == IDCurrentUser).FirstOrDefault();
                            _user.EmailID = model.Email;

                            db.SaveChanges();
                            emailUpdated = true;
                        }
                        //------------------------
                        if (!emailUpdated)
                        {
                            ModelState.AddModelError("", "Echec Mise à jour de l'adresse electronique !");
                        }
                        else
                        {
                            return(RedirectToAction("Settings", new { Message = ManageMessageId.ChangePasswordSuccess }));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Le mot de passe actuel est incorrect ou le nouveau mot de passe n'est pas valide.");
                        // ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                    }
                }
            }


            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #4
0
        public ActionResult Settings(LocalSettingModel model)
        {
            if (ModelState.IsValid)
            {
                var svc     = new AppService();
                var setting = new LocalSetting
                {
                    SettingId    = model.SettingId,
                    FolderPath   = model.FolderPath,
                    BackupFolder = model.BackupFolder,
                    BackupName   = model.BackupName
                };


                svc.SaveSetting(setting);

                return(RedirectToAction("Index"));
            }

            return(View());
        }