public ActionResult ChangePassword(Models.ChangePasswordViewModel model)
        {
            if (model.OldPassword.Trim() == "")
            {
                return(View(model));
            }

            var myAccount         = DB_GEN_Repo.GetUser(model.UserID);   // DB_GEN.GenProxyAccount.Find(model.UserID.Trim());
            var myProxyAccount    = hluser_Repo.GetUser(model.UserID);   // hluser.passwd.Find(model.UserID.Trim());
            var myMedProxyAccount = MedProxy_Repo.GetUser(model.UserID); // MedProxy.passwd.Find(model.UserID.Trim());

            if ((myAccount == null) || (myProxyAccount == null) || (myMedProxyAccount == null))
            {
                return(View("AccountNotFound"));
            }

            string OldPasswordMD5 = DB_GEN_Repo.GetMD5(model.OldPassword); // DB_GEN.GetMD5(model.OldPassword).First().ToUpper();

            if (myAccount.chXData != OldPasswordMD5)
            {
                return(View("PasswordIncorrect"));
            }

            if (model.NewPassword != model.NewPasswordConfirm)
            {
                return(View("PasswordInconfirm"));
            }

            string NewPasswordMD5 = DB_GEN_Repo.GetMD5(model.NewPassword); //DB_GEN.GetMD5(model.NewPassword).First().ToUpper();

            myAccount.chXData        = NewPasswordMD5;
            myAccount.dtLastModified = DateTime.Now;
            myAccount.chXDataHosp    = "Web";
            DB_GEN_Repo.UnitOfWork.Commit(); //DB_GEN.SaveChanges();

            myProxyAccount.password = NewPasswordMD5.ToLower();
            myProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Update by web";
            hluser_Repo.UnitOfWork.Commit(); //hluser.SaveChanges();

            myMedProxyAccount.password = NewPasswordMD5.ToLower();
            myMedProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Update by web";
            MedProxy_Repo.UnitOfWork.Commit(); // MedProxy.SaveChanges();

            return(View("PasswordChanged"));
        }
示例#2
0
        public ActionResult ResetPassword(string UserID)
        {
            //TODO 為了相容於六碼ID,所以目前所有UserID都有先trim過,後面有空要改為repo樣式來統一整個邏輯
            var myAccount = DB_GEN_Repo.GetUser(UserID); // DB_GEN.GenProxyAccount.Find(UserID.Trim());

            if (myAccount == null)
            {
                return(View("AccountNotFound"));
            }

            if (myAccount.chEMail.Trim().Length == 0)
            {
                TempData["Message"] = string.Format("上網帳號{0}的信箱地址為空白,無法寄發新密碼通知信,取消密碼重置,請更正信箱地址", myAccount.chUserID);
                return(View("EMailEmpty"));
            }

            Random rand         = new Random(DateTime.Now.Millisecond);
            string randPassword = "******" + Convert.ToString(rand.Next(10000000, 99999999)).Substring(0, 4);
            //ViewData.Add("NewPassword", randPassword);

            string NewPasswordMD5 = DB_GEN_Repo.GetMD5(randPassword); //DB_GEN.GetMD5(randPassword).First().ToUpper();

            myAccount.chXData        = NewPasswordMD5;
            myAccount.dtLastModified = DateTime.Now;
            myAccount.chXDataHosp    = "Web";

            DB_GEN_Repo.UnitOfWork.Commit();                  // DB_GEN.SaveChanges();

            var myProxyAccount = hluser_Repo.GetUser(UserID); // hluser.passwd.Find(UserID.Trim());

            if (myProxyAccount == null)
            {
                return(View("AccountNotFound"));
            }

            myProxyAccount.password = NewPasswordMD5.ToLower();
            myProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Reset by web";
            hluser_Repo.UnitOfWork.Commit();                       // hluser.SaveChanges();

            var myMedProxyAccount = MedProxy_Repo.GetUser(UserID); // MedProxy.passwd.Find(UserID.Trim());

            if (myMedProxyAccount == null)
            {
                return(View("AccountNotFound"));
            }
            myMedProxyAccount.password = NewPasswordMD5.ToLower();
            myMedProxyAccount.comment  = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "; Reset by web";
            MedProxy_Repo.UnitOfWork.Commit(); // MedProxy.SaveChanges();

            var mailContent = new StringBuilder();

            mailContent.AppendLine(string.Format("您的上網帳號:{0}", myAccount.chUserID));
            mailContent.AppendLine(string.Format("已於{0}重置密碼", DateTime.Now.ToString()));
            mailContent.AppendLine(string.Format("新密碼為:{0}", randPassword));
            mailContent.AppendLine(string.Format("請盡快至右方連結變更密碼: {0}", @"http://10.2.0.173/AccountSync/ProxyAccount"));

            var email = new Models.EMail.EMailEntities();

            email.SendMail(myAccount.chEMail, "", "", "密碼已重置", mailContent.ToString());

            return(RedirectToAction("AccountList"));
        }