/// <summary>
        /// 站点设置
        /// </summary>
        /// <returns></returns>
        public ActionResult webSiteSet()
        {
            #region 访问权限
            var           user                = (Maticsoft.Model.User_Info)ViewBag.curentUser;
            var           curentUser          = _iuserService.getUserByID(user.Id);
            var           ManagePermission    = curentUser.UserGroup.ManagePermission;
            List <string> managePermissionstr = new List <string>(ManagePermission.Split(','));
            var           managePermission    = managePermissionstr.Select(x => Convert.ToInt32(x)).ToList();

            if (curentUser.UserGroupID != 1)
            {
                if (!managePermission.Contains((int)SortEnum.sortClass.webSet))
                {
                    return(new RedirectResult("/Home/deny"));
                }
            }
            #endregion


            //UntilMethod.getAppSettingValue("indexPicAddress");

            var model = new WebSiteViewModel();
            model.lockLogin        = int.Parse(UntilMethod.getAppSettingValue("lockLogin"));
            model.OpenSSl          = Convert.ToBoolean(UntilMethod.getAppSettingValue("OpenSSl"));
            model.overdueHoru      = int.Parse(UntilMethod.getAppSettingValue("overdueHoru"));
            model.passWordLength   = int.Parse(UntilMethod.getAppSettingValue("passWordLength"));
            model.verificationCode = Convert.ToBoolean(UntilMethod.getAppSettingValue("verificationCode"));
            model.lcokTimeLenth    = int.Parse(UntilMethod.getAppSettingValue("lcokTimeLenth"));
            return(View(model));
        }
        public ActionResult _SetPassWord()
        {
            var user       = (Maticsoft.Model.User_Info)ViewBag.curentUser;
            var curentUser = _iuserService.getUserByID(user.Id);


            var length = int.Parse(UntilMethod.getAppSettingValue("passWordLength").ToString());

            try
            {
                var oldPwd      = Request["oldPwd"].ToString().Trim();
                var newPwd      = Request["NewPwd"].ToString().Trim();
                var udictionary = TempData["uToken"];


                #region 验证新密码规则
                var regex = new Regex(@"(?=.*[0-9])(?=.*[a-zA-Z])(?=([\x21-\x7e]+)[^a-zA-Z0-9]).{" + length + ",15}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                if (regex.IsMatch(newPwd))
                {
                    #region 数据安全性校验
                    var utoken = Request["token"].ToString();
                    if (udictionary.ToString() != utoken)
                    {
                        return(Json(new { state = "error", mes = "非法操作!" }));
                    }
                    #endregion



                    #region 原密码验证
                    if (curentUser.UserPassword == UntilMethod.Md5Encrypt(oldPwd))
                    {
                        curentUser.UserPassword = UntilMethod.Md5Encrypt(newPwd);
                        curentUser.passWordTime = DateTime.Now;
                        _iuserService.UpdateUser(curentUser);
                        return(Json(new { state = "success" }));
                    }
                    else
                    {
                        return(Json(new { state = "error", mes = "与原密码不匹配" }));
                    }
                    #endregion
                }
                else
                {
                    return(Json(new { state = "error", mes = "密码格式不符,请输入" + length + "-15位,并含有数字字母和特殊字符" }));
                }
                #endregion
            }
            catch (Exception ex)
            {
                return(Json(new { state = "error", mes = "发生错误" }));
            }
        }
        public ActionResult _ChangePassword()
        {
            var length = int.Parse(UntilMethod.getAppSettingValue("passWordLength").ToString());

            try
            {
                var oldPwd      = Request["oldPwd"].ToString().Trim();
                var newPwd      = Request["NewPwd"].ToString().Trim();
                var udictionary = TempData["uNameToken"] as Dictionary <string, string>;
                var uID         = "";

                #region 验证新密码规则
                var regex = new Regex(@"(?=.*[0-9])(?=.*[a-zA-Z])(?=([\x21-\x7e]+)[^a-zA-Z0-9]).{" + length + ",15}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                if (regex.IsMatch(newPwd))
                {
                    #region 数据安全性校验
                    var utoken = Request["token"].ToString();
                    if (!udictionary.ContainsKey(utoken))
                    {
                        return(Json(new { state = "error", mes = "非法操作!" }));
                    }
                    #endregion

                    uID = udictionary[utoken];
                    var curentUser = _iuserService.GetUserByName(uID);

                    #region 原密码验证
                    if (curentUser.UserPassword == UntilMethod.Md5Encrypt(oldPwd))
                    {
                        curentUser.UserPassword = UntilMethod.Md5Encrypt(newPwd);
                        curentUser.passWordTime = DateTime.Now;
                        _iuserService.UpdateUser(curentUser);
                        return(Json(new { state = "success" }));
                    }
                    else
                    {
                        TempData["uNameToken"] = udictionary;
                        return(Json(new { state = "error", mes = "与原密码不匹配" }));
                    }
                    #endregion
                }
                else
                {
                    TempData["uNameToken"] = udictionary;
                    return(Json(new { state = "error", mes = "密码格式不符,请输入" + length + "-15位,并含有数字字母和特殊字符" }));
                }
                #endregion
            }
            catch (Exception ex)
            {
                return(Json(new { state = "error", mes = "发生错误" }));
            }
        }
        public HCHttpsRequirementAttribute(SslRequirement sslRequirement)
        {
            if (Convert.ToBoolean(UntilMethod.getAppSettingValue("OpenSSl")))
            {
                this.SslRequirement = SslRequirement.Yes;
            }
            else
            {
                this.SslRequirement = SslRequirement.NoMatter;
            }


            //this.SslRequirement = sslRequirement;
        }
Example #5
0
        public ActionResult AddUser(CxUser model)
        {
            #region 访问权限
            var           user1               = (Maticsoft.Model.User_Info)ViewBag.curentUser;
            var           curentUser          = _iuserService.getUserByID(user1.Id);
            var           ManagePermission    = curentUser.UserGroup.ManagePermission;
            List <string> managePermissionstr = new List <string>(ManagePermission.Split(','));
            var           managePermission    = managePermissionstr.Select(x => Convert.ToInt32(x)).ToList();
            if (!managePermission.Contains((int)SortEnum.sortClass.userManage))
            {
                return(new RedirectResult("/Home/deny"));
                //return Json(new { state = "Error", mes = "发生错误" });
            }
            #endregion


            #region 安全校验
            var unitiM = new UntilMethod();

            var serverToken = TempData["addToken"].ToString();
            var ClientToken = Request["addToken"] == null ? "" : Request["addToken"].ToString();
            if (unitiM.DecryptDES(ClientToken, "jack") != serverToken)
            {
                TempData["addToken"] = serverToken;
                return(new RedirectResult("/Home/deny"));
            }
            #endregion

            #region 解密
            model.UserName     = unitiM.DecryptDES(model.UserName, "jack");
            model.UserPassword = unitiM.DecryptDES(model.UserPassword, "jack");
            #endregion


            var length = int.Parse(UntilMethod.getAppSettingValue("passWordLength").ToString());

            #region 密码强度校验
            var regex = new Regex(@"(?=.*[0-9])(?=.*[a-zA-Z])(?=([\x21-\x7e]+)[^a-zA-Z0-9]).{" + length + ",15}", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            if (!regex.IsMatch(model.UserPassword))
            {
                return(Json(new { state = "Error", mes = "密码格式不符,请输入" + length + "-15位,并含有数字字母和特殊字符" }));
            }


            #endregion

            try
            {
                if (model.UserID > 0)//更新
                {
                    var user = _iuserService.getUserByID(model.UserID);
                    user.UserPassword = UntilMethod.Md5Encrypt(model.UserPassword);
                    user.RealName     = model.RealName;
                    user.UserGroupID  = model.UserGroupID;
                    user.passWordTime = DateTime.Now;
                    user.Effective    = model.Effective;
                    _iuserService.UpdateUser(user);
                    AddOpLog("用户修改,修改账户:" + user.UserName.ToString() + " 角色:" + user.UserGroup.GroupName);
                }
                else//新增
                {
                    #region 用户名重复校验
                    var CheckUser = getUser(model.UserName);
                    if (CheckUser != null)
                    {
                        return(Json(new { state = "Error", mes = "用户名已存在" }));
                    }
                    #endregion

                    #region 获取密码过期时常
                    var overdueTimeLenth = -int.Parse(UntilMethod.getAppSettingValue("overdueHoru").ToString());
                    #endregion

                    model.isAdmin      = true;
                    model.UserPassword = UntilMethod.Md5Encrypt(model.UserPassword);
                    //model.passWordTime = DateTime.Now;

                    model.passWordTime = DateTime.Now.AddDays(overdueTimeLenth);

                    _iuserService.AddUser(model);
                    var addUserGroup = _iuserGroupService.GetByID(model.UserGroupID);
                    AddOpLog("用户新增,新增账户:" + model.UserName.ToString() + " 角色:" + addUserGroup.GroupName);
                }
                return(Json(new { state = "OK", mes = "" }));
            }
            catch (Exception ex)
            {
                return(Json(new { state = "Error", mes = "发生错误" }));
            }
        }