Esempio n. 1
0
        public HttpResponseBase SaveSecretSet()
        {
            string json = string.Empty;
            SecretAccountSet sas = new SecretAccountSet();
            try
            {
                sasMgr = new SecretAccountSetMgr(mySqlConnectionString);
                SecretAccountSetQuery sasq = new SecretAccountSetQuery();
                sasq.IsPage = false;
                bool issame = false;
                if (!string.IsNullOrEmpty(Request.Params["id"]))
                {
                    sas.id = int.Parse(Request.Params["id"]);
                    sasq.id = sas.id;
                }
                SecretAccountSet sasModel = sasMgr.Select(sasq);
                if (!string.IsNullOrEmpty(Request.Params["user_id"]))
                {
                    sas.user_id = uint.Parse(Request.Params["user_id"]);
                }
                string opassword = Request.Params["osecret_password"];
                string npassword = Request.Params["nsecret_password"];
                string password = string.Empty;
                string oldpwd = string.Empty;
                if (!string.IsNullOrEmpty(Request.Params["secret_limit"]))
                {
                    sas.secret_limit = Convert.ToInt32(Request.Params["secret_limit"]);
                }

                if (sasModel != null)
                {
                    sas.pwd_status = Convert.ToInt32(sasModel.pwd_status);
                }
                sas.updatedate = sas.createdate;
                //新密碼
                if (!string.IsNullOrEmpty(npassword))
                {
                    HashEncrypt hmd5 = new HashEncrypt();
                    password = hmd5.SHA256Encrypt(npassword);
                    sas.secret_pwd = password;
                    sas.pwd_status = 0;
                }
                if (string.IsNullOrEmpty(Request.Params["reset"]))
                {
                    //舊密碼
                    if (!string.IsNullOrEmpty(opassword))
                    {
                        HashEncrypt hmd5 = new HashEncrypt();
                        oldpwd = hmd5.SHA256Encrypt(opassword);
                    }
                    if (sasModel != null)
                    {
                        if (oldpwd == sasModel.secret_pwd)
                        {
                            issame = true;
                        }
                    }
                    IPAddress ip = new IPAddress(0);
                    if (IPAddress.TryParse(Request.Params["ipfrom"], out ip))
                    {
                        sas.ipfrom = ip.ToString();
                        if (!string.IsNullOrEmpty(Request.Params["id"]))
                        {
                            if (issame || Request.Params["nsecret_password"] == "")
                            {

                                if (sasMgr.Update(sas) > 0)
                                {
                                    json = "{success:true,msg:'修改成功!'}";
                                }
                                else
                                {
                                    json = "{success:false,msg:'修改失敗!'}";
                                }
                            }
                            else
                            {
                                json = "{success:false,msg:'原始密碼輸入錯誤!'}";
                            }
                        }
                        else
                        {
                            sas.secret_count = 0;
                            sas.user_login_attempts = 0;
                            sas.createdate = DateTime.Now;
                            sas.status = 0;
                            sas.pwd_status = 0;
                            if (sasMgr.SelectByUserIP(sas) == null)
                            {
                                if (sasMgr.Insert(sas) > 0)
                                {
                                    json = "{success:true,msg:'保存成功!'}";
                                }
                                else
                                {
                                    json = "{success:false,msg:'保存失敗!'}";
                                }
                            }
                            else
                            {
                                json = "{success:false,msg:'相同的用戶和IP不能重複添加!'}";
                            }
                        }
                    }
                    else
                    {
                        json = "{success:false,msg:'请输入正确的IP地址!'}";
                    }
                }
                else
                {
                    sas.pwd_status = 0;
                    if (sasMgr.Update(sas) > 0)
                    {
                        json = "{success:true}";
                    }
                    else
                    {
                        json = "{success:false}";
                    }
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:'操作失敗!'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 2
0
        /// <summary>
        /// 對賬號解鎖重設
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult UnlockAndReset()
        {
            string jsonStr = string.Empty;
            try
            {
                sasMgr = new SecretAccountSetMgr(mySqlConnectionString);
                _muMgr = new ManageUserMgr(mySqlConnectionString);
                int id = Convert.ToInt32(Request.Params["id"]);
                int activeValue = Convert.ToInt32(Request.Params["active"]);
                SecretAccountSet sas = new SecretAccountSet();
                sas.id = id;
                SecretAccountSet oldsas = sasMgr.Select(sas);//獲得用戶的密保信息
                if (oldsas.secret_limit == oldsas.secret_count && oldsas.secret_limit != 0)
                {
                    sas.status = 0;
                }
                else
                {
                    sas.status = 1;
                }
                sas.pwd_status = oldsas.pwd_status;
                sas.user_login_attempts = 0;
                if (sasMgr.Update(sas) > 0)
                {
                    return Json(new { success = "true" });
                }
                else
                {
                    return Json(new { success = "false" });
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                return Json(new { success = "false" });
            }



        }
Esempio n. 3
0
        /// <summary>
        /// 更改活動使用狀態
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult UpdateActive()
        {
            string jsonStr = string.Empty;
            try
            {
                sasMgr = new SecretAccountSetMgr(mySqlConnectionString);
                int id = Convert.ToInt32(Request.Params["id"]);
                int activeValue = Convert.ToInt32(Request.Params["active"]);
                SecretAccountSet model = new SecretAccountSet();
                model.id = id;
                model.status = activeValue;
                model.updatedate = DateTime.Now;
                model.pwd_status = sasMgr.Select(new SecretAccountSet { id = model.id }).pwd_status;
                if (sasMgr.Update(model) > 0)
                {
                    return Json(new { success = "true" });
                }
                else
                {
                    return Json(new { success = "false" });
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                return Json(new { success = "false" });
            }

        }