public static string ChangePassword(Manager manager, string oldPassword, string newPassword,
     string confirmPassword, string ipstring)
 {
     if (string.IsNullOrEmpty(oldPassword))
     {
         return ResponseCode.Managaer.OldPasswordNullOrEmpty;
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return ResponseCode.Managaer.NewPasswordNullOrEmpty;
     }
     if (newPassword != confirmPassword)
     {
         return ResponseCode.Managaer.ConfirmPasswordError;
     }
     Manager manage = managerRepository.GetById(manager.Id);
     if (manage != null)
     {
         if (!manage.MatchPassword(oldPassword))
         {
             return ResponseCode.Managaer.OldPasswordError;
         }
         PwdChangeRecord pwdChangeRecord = PwdChangeRecordFactory.Create(manager.Id, manager.RealName,
             oldPassword,
             newPassword, ipstring, manage.RealName);
         manage.Password = newPassword;
         manage.EncryptPassword();
         managerRepository.Save(manage);
         pwdChangeRecordRepository.Save(pwdChangeRecord);
         manager = manage;
         return ResponseCode.Ok;
     }
     return ResponseCode.NotFoundData;
 }
 public static void SaveManagerCookie(Manager manager, bool remember)
 {
     if (remember)
     {
         CookieManager.SetCookie(CookieConst.COOKIE_MANAMGER,
             EncryptTools.EncryptDES(manager.GetManagerCookieString(), EncryptKey), DateTime.Now.AddDays(14));
     }
     else
     {
         CookieManager.SetCookie(CookieConst.COOKIE_MANAMGER,
            EncryptTools.EncryptDES(manager.GetManagerCookieString(), EncryptKey));
     }
 }
示例#3
0
 public static Manager GetFromCookieString(string cookieString)
 {
     if (string.IsNullOrEmpty(cookieString)) return null;
     Hashtable cookieTable = JsonConvert.DeserializeObject<Hashtable>(cookieString);
     if (cookieTable == null) return null;
     Manager manager = new Manager
     {
         Id = int.Parse(cookieTable["id"].ToString()),
         UserName = cookieTable["mn"].ToString(),
         ParentId = long.Parse(cookieTable["pId"].ToString()),
         RealName = cookieTable["rnm"].ToString(),
         Company = cookieTable["cp"].ToString(),
         ManagerType = (ManagerTypeEnum)short.Parse(cookieTable["managerId"].ToString())
     };
     return manager;
 }
        public static string Save(Manager currentManager, Manager manager)
        {
            if (string.IsNullOrEmpty(manager.UserName))
            {
                return ResponseCode.Managaer.UserNullOrEmpty;
            }
            if (string.IsNullOrEmpty(manager.BindEmail))
            {
                return ResponseCode.Managaer.BindEmailIsNullOrEmpty;
            }

            if (string.IsNullOrEmpty(manager.Password))
            {
                return ResponseCode.Managaer.PasswordNullOrEmpty;
            }
            if (manager.Language == 0)
            {
                return ResponseCode.Managaer.LanguageNullOrEmpty;
            }
            if (string.IsNullOrEmpty(manager.RealName))
            {
                return ResponseCode.Managaer.RealNameNullOrEmpty;
            }
            if (string.IsNullOrEmpty(manager.Company))
            {
                return ResponseCode.Managaer.CompanyNullOrEmpty;
            }
            if (!Utils.CheckTools.IsValidEmail(manager.BindEmail))
            {
                return ResponseCode.Managaer.IsNotEmail;
            }
            if (currentManager.ManagerType == ManagerTypeEnum.Common && currentManager.ParentId != 0)
            {
                return ResponseCode.Managaer.ComonChildNoPermission;
            }
            if (currentManager.ManagerType == ManagerTypeEnum.Common && manager.ManagerType == ManagerTypeEnum.Super)
            {
                return ResponseCode.Managaer.CommonPermission;
            }
            if (currentManager.ManagerType == ManagerTypeEnum.Super && currentManager.ParentId != 0 &&
                manager.ManagerType == ManagerTypeEnum.Super)
            {
                return ResponseCode.Managaer.SuperChildNoPermission;
            }
            if (currentManager.ManagerType == ManagerTypeEnum.Super && manager.ManagerType == ManagerTypeEnum.Common &&
                manager.Id == 0)
            {
                manager.ParentId = 0;
            }
            if (managerRepository.IsExist(manager))
            {
                return ResponseCode.Managaer.UserNameHasExist;
            }

            managerRepository.Save(manager);
            return ResponseCode.Ok;
        }
 public static void ResetPassword(long id, Manager currentManager, string ipString)
 {
     Manager manager = managerRepository.GetById(id);
     if (manager != null)
     {
         PwdChangeRecord pwdChangeRecord = PwdChangeRecordFactory.Create(id, manager.RealName, "重置密码",
             "123456", ipString, currentManager.RealName);
         manager.Password = "******";
         manager.EncryptPassword();
         managerRepository.Save(manager);
         pwdChangeRecordRepository.Save(pwdChangeRecord);
     }
 }
 //站体分析登录验证
 public static string LoginWebSiteAnalysis(string username, string pwd, out Manager resultmanager)
 {
     Manager manager = managerRepository.GetManagerByUserName(username);
     resultmanager = manager;
     if (manager == null)
     {
         return ResponseCode.Managaer.UserNameError;
     }
     if (!manager.MatchPassword(pwd))
     {
         return ResponseCode.Managaer.UserPasswordError;
     }
     if (manager.ManagerType == ManagerTypeEnum.Super)
     {
         return ResponseCode.Managaer.MangerNoPermission;
     }
     return ResponseCode.Ok;
 }
 public static string Login(string userName, string password, out Manager resultManager)
 {
     Manager manager = managerRepository.GetManagerByUserName(userName);
     resultManager = manager;
     if (manager == null)
     {
         return ResponseCode.Managaer.UserNameError;
     }
     if (!manager.MatchPassword(password))
     {
         return ResponseCode.Managaer.UserPasswordError;
     }
     return ResponseCode.Ok;
 }