コード例 #1
0
 public ActionResult GetValidateCode()
 {
     ValidateCode vCode = new ValidateCode();
     string code = vCode.CreateValidateCode(5);
     Session["ValidateCode"] = code;
     byte[] bytes = vCode.CreateValidateGraphic(code);
     return File(bytes, @"image/jpeg");
 }
コード例 #2
0
        /// <summary>
        /// 生成订单号
        /// </summary>
        private void ajaxChargeOrderId()
        {
            this._response = this.JsonResult(1, SsId.Charge);
            string _code     = this.q("code");
            string _realcode = "";

            if (!ValidateCode.CheckValidateCode(_code, ref _realcode))
            {
                this._response = this.JsonResult(0, "验证码错误");
            }
        }
コード例 #3
0
        /// <summary>
        /// 产生验证码图片
        /// </summary>
        /// <returns></returns>
        public ActionResult GetImg()
        {
            int    width    = 100;
            int    height   = 40;
            int    fontsize = 20;
            string code     = string.Empty;

            byte[] bytes = ValidateCode.CreateValidateGraphic(out code, 4, width, height, fontsize);
            Session[AppContent.VALICODE] = code;
            return(File(bytes, @"image/jpeg"));
        }
コード例 #4
0
        public ActionResult GetValidateCodeImg()
        {
            const int width    = 100;
            const int height   = 30;
            const int fontsize = 20;
            string    code     = string.Empty;

            byte[] bytes = ValidateCode.CreateValidateGraphic(out code, 4, width, height, fontsize);
            Session.Add("ValidateCode", code);//设置验证码Session
            return(File(bytes, @"image/jpeg"));
        }
コード例 #5
0
        /// 生成验证码图像对象

        /// </summary>

        /// <returns></returns>

        public ActionResult GetValidateCode()
        {
            ValidateCode vCode = new ValidateCode();

            string code = vCode.CreateValidateCode(4);

            Session["ValidateCode"] = code;

            byte[] bytes = vCode.CreateValidateGraphic(code);

            return(File(bytes, @"image/jpeg"));
        }
コード例 #6
0
        public string GetRandCode()
        {
            var validateObj = new ValidateCode();
            var code        = validateObj.CreateValidateCode(4);

            if (!dicCode.ContainsKey(code))
            {
                dicCode.Add(code, "");
            }
            code = Udp.Security.DESEncrypt.DesEncrypt(code);
            return(code);
        }
コード例 #7
0
        /// <summary>
        /// 获取验证码(一般处理程序入口函数)
        /// </summary>
        /// <param name="context">当前上下文</param>
        public void ProcessRequest(HttpContext context)
        {
            // 创建验证码
            ValidateCode validateCode = new ValidateCode();

            // 获取验证码(字符串),写入session
            context.Session["SomeValidateCode"] = validateCode.GetString();


            // 输出验证码(图片)
            context.Response.BinaryWrite(validateCode.GetByteArray());
        }
コード例 #8
0
ファイル: LoginController.cs プロジェクト: vvull/BlangenOA
        /// <summary>
        /// 显示验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowValidateCode()
        {
            ValidateCode vc = new ValidateCode();
            //产生验证码
            string vcStr = vc.CreateValidateCode(5);

            //存储到Session中
            Session["ValidateCode"] = vcStr;
            //将验证码画到画布上
            byte[] b = vc.CreateValidateGraphic(vcStr);
            return(File(b, "image/jpeg"));
        }
コード例 #9
0
        public FileContentResult GetValidateCodeImage()
        {
            ValidateCode vCode = new ValidateCode();
            string       code  = vCode.CreateValidateCode(5);

            Session["ValidateCode"] = code;
            byte[] bytes  = vCode.CreateValidateGraphic(code);
            string result = String.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(bytes));

            //return File(bytes, @"image/jpeg");
            return(File(bytes, "image/gif"));
        }
コード例 #10
0
        /// <summary>
        /// 验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult VerificationCode()
        {
            ValidateCode validateCode     = new ValidateCode();
            string       verificationCode = validateCode.CreateValidateCode(4);

            //Bitmap _img = validateCode.CreateVerificationImage(verificationCode, 100, 42);
            // _img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] code = validateCode.CreateValidateGraphic(verificationCode, 100, 42);
            Response.BinaryWrite(code);
            TempData["VerificationCode"] = verificationCode.ToUpper();
            return(null);
        }
コード例 #11
0
        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <returns></returns>
        public FileResult GetValidateImg()
        {
            // 创建长度为4的验证字符串
            string verificationCode = ValidateCode.CreateVerificationText(4);

            // 将验证码保存至 TempData,读取一次即销毁
            TempData["VerificationCode"] = verificationCode.ToUpper();

            byte[] bytes = ValidateCode.CreateImage(verificationCode, 80, 30);

            return(File(bytes, @"image/jpeg"));
        }
コード例 #12
0
        /// <summary>
        /// 生成验证码图片对应的base64编码,用于图片显示
        /// </summary>
        /// <returns></returns>
        public JsonResult GetValidateImgBase64()
        {
            // 创建长度为4的验证字符串
            string verificationCode = ValidateCode.CreateVerificationText(4);

            // 将验证码保存至 TempData,读取一次即销毁
            TempData["VerificationCode"] = verificationCode.ToUpper();

            string res = ValidateCode.CreateImageVerifyBase64(verificationCode, 80, 30);

            return(Json(res));
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            ValidateCode validateCode = new ValidateCode();
            string       code         = validateCode.CreateValidateCode(4);

            //将验证码信息存在 Session 中,供其他地方调用
            context.Session["validateCode"] = code;

            //下方法内部封装了返回值
            validateCode.CreateValidateGraphic(code, context);
        }
コード例 #14
0
ファイル: LoginController.cs プロジェクト: xiaopohou/Snai.CMS
        public IActionResult VerifyCode()
        {
            string codeValue = "";
            var    codeImg   = ValidateCode.CreateImage(out codeValue, 6);

            codeValue = codeValue.ToUpper();//验证码不分大小写

            HttpExtension.SetSession(Consts.Session_ValidateCode, codeValue);

            Response.Body.Dispose();
            return(File(codeImg, @"image/png"));
        }
コード例 #15
0
        public ActionResult ShowVCode()
        {
            Common.ValidateCode validateCode = new ValidateCode();
            string strCode = validateCode.CreateValidateCode(4);

            //把验证码放到Session里面去
            Session["VCode"] = strCode;

            byte[] imgBytes = validateCode.CreateValidateGraphic(strCode);

            return(File(imgBytes, "image/jpeg"));
        }
コード例 #16
0
        public HttpResponseMessage ValidateCode()
        {
            var validCode = new ValidateCode();
            var code      = validCode.CreateValidateCode(4);
            //HttpContext.Current.Session["ValidateCode"] = code;
            var bytes = validCode.CreateValidateGraphic(code);
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            result.Content = new ByteArrayContent(bytes);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
            return(result);
        }
コード例 #17
0
        public ActionResult GetValidateCode()
        {
            string code = ValidateCode.CreateValidateCode(4);

            Session["ValidateCode"] = code;
            var codeBytes = ValidateCode.CreateValidateGraphic(code);

            Response.OutputStream.Write(codeBytes, 0, codeBytes.Length);
            Response.ContentType = "Image/jpeg";
            Response.Flush();
            Response.End();
            return(null);
        }
コード例 #18
0
        public ActionResult GetValidateCode(string time)
        {
            var id1 = Session.SessionID;
            //string validatecode = SessionHelper.Get("ValidateCode");
            ValidateCode vCode = new ValidateCode();
            string       code  = vCode.CreateRandomCode(6);

            Session["LoginValidateCode"] = code;
            SessionHelper.SetSession("ValidateCode", code);
            byte[] bytes = vCode.CreateValidateGraphic(code);

            return(File(bytes, @"image/jpeg"));
        }
コード例 #19
0
        /// <summary>
        /// Create a validate code/images and return it
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowValidationCode()
        {
            ValidateCode validateCode = new ValidateCode();
            string       strCode      = validateCode.CreateValidateCode(4);

            // 验证码放到Session中
            Session["validationCode"] = strCode;


            byte[] imgBytes = validateCode.CreateValidateGraphic(strCode);

            return(File(imgBytes, @"image/jpeg"));
        }
コード例 #20
0
ファイル: AccountController.cs プロジェクト: songtaojie/Blog
        /// <summary>
        /// 显示验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowValidateCode()
        {
            ValidateCode validate = new ValidateCode()
            {
                MultValue = 2,
                NPhase    = Math.PI
            };
            string code = validate.GetRandomNumberString(4);

            Session[ConstInfo.VCode] = code;
            byte[] bytes = validate.CreateValidateGraphic(code);
            return(File(bytes, "image/jpeg"));
        }
コード例 #21
0
        /// <summary>
        /// 验证码的实现
        /// </summary>
        /// <returns></returns>
        public ActionResult CheckCode()
        {
            //首先实例化验证码的类
            ValidateCode validateCode = new ValidateCode();
            //生成验证码指定的长度
            string code = validateCode.CreateValidateCode(5);

            //将验证码赋值给Session变量
            Session["ValidateCode"] = code;
            //创建验证码的图片
            byte[] bytes = validateCode.CreateValidateGraphic(code);
            //最后将验证码返回
            return(File(bytes, @"image/jpeg"));
        }
コード例 #22
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";
            ValidateCode vliateCode = new ValidateCode();
            string       code       = vliateCode.CreateValidateCode(4);//产生验证码

            context.Session["validateCode"] = code;
            byte[] buffer = vliateCode.CreateValidateGraphic(code);//将验证码画到画布上.
            context.Response.BinaryWrite(buffer);
            //ms.
            //File(buffer, "image/jpeg");
            //return  File(buffer, "image/jpeg");
            //context.Response.Write("Hello World");
        }
コード例 #23
0
ファイル: LoginManager.cs プロジェクト: wiejunyu/PussCore
        /// <summary>
        /// 邮箱获取验证码
        /// </summary>
        /// <param name="CodeKey">验证码</param>
        /// <param name="Email">邮箱</param>
        /// <returns></returns>
        public async Task <string> EmailGetCode(string CodeKey, string Email)
        {
            //读写分离强制走主库
            DbContext.Db.Ado.IsDisableMasterSlaveSeparation = true;

            DateTime dt = DateTime.Now.Date;
            //批量删除今天之前的验证码
            var  t5     = DbContext.Db.Deleteable <Code>().Where(x => x.time < dt).ExecuteCommand();
            Code cModel = await CodeManager.GetSingleAsync(x => x.email == Email && x.time > dt && x.type == (int)CodeType.Email);

            //判断验证码是否超出次数
            if (cModel != null ? cModel.count >= 6 : false)
            {
                throw new AppException("发送超出次数");
            }
            //获得验证码
            string code = new ValidateCode().CreateValidateCode(6);//生成验证码,传几就是几位验证码
            //发送邮件
            Cms_Sysconfig sys = await Cms_SysconfigManager.GetSingleAsync(x => x.Id == 1);

            if (!EmailService.MailSending(Email, "宇宙物流验证码", $"您在宇宙物流的验证码是:{code},10分钟内有效", sys.Mail_From, sys.Mail_Code, sys.Mail_Host))
            {
                throw new AppException("发送失败");
            }
            #region 保存验证码统计
            if (cModel == null)
            {
                cModel = new Code()
                {
                    type  = (int)CodeType.Email,
                    email = Email,
                    time  = DateTime.Now,
                    count = 1
                };
                CodeManager.Insert(cModel);
            }
            else
            {
                cModel.count++;
            }
            #endregion
            cModel.code = code;
            //保存验证码进缓存
            await RedisService.SetAsync(CommentConfig.MailCacheCode + CodeKey, cModel, 10);

            //读写分离取消强制走主库
            DbContext.Db.Ado.IsDisableMasterSlaveSeparation = false;
            return("验证码发送成功");
        }
コード例 #24
0
        public HttpResponseMessage GetCode(int?width, int?height, int?fontSize)
        {
            int    widths   = width.HasValue ? width.Value : 100;
            int    heights  = height.HasValue ? height.Value : 40;
            int    fontsize = fontSize.HasValue ? fontSize.Value : 20;
            string code     = string.Empty;

            byte[] bytes = ValidateCode.CreateValidateGraphic(out code, 4, widths, heights, fontsize);
            HttpContext.Current.Session["verifycode"] = code;
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            result.Content = new ByteArrayContent(bytes);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(result);
        }
コード例 #25
0
ファイル: TempService.cs プロジェクト: EmilyEdna/KilyCore
        public string CreateInviteCode()
        {
            EnterpriseInviteCode code = new EnterpriseInviteCode();
            var Province = Kily.Set <SystemProvince>().ToList();

            foreach (var item in Province)
            {
                code.InviteCode  = $"{item.Code}-{DateTime.Now.Millisecond}-{ValidateCode.CreateValidateCode()}";
                code.UseTypePath = item.Id.ToString();
                code.EffectiveSt = DateTime.Parse("2019-09-16");
                code.EffectiveEt = DateTime.Parse("2019-10-15");
                Insert(code);
            }
            return(ServiceMessage.INSERTSUCCESS);
        }
コード例 #26
0
        public void ProcessRequest(HttpContext context)
        {
            Random r = new Random();
            string c = string.Format("{0}{1}{2}{3}",
                                     r.Next(0, 9).ToString(),
                                     r.Next(0, 9).ToString(),
                                     r.Next(0, 9).ToString(),
                                     r.Next(0, 9).ToString());

            context.Response.Cookies.Add(new HttpCookie("captche", c));
            ValidateCode code = new ValidateCode();

            code.Chaos = true;
            code.CreateImageOnPage(c, context);
        }
コード例 #27
0
ファイル: LoginController.cs プロジェクト: IOT001/IOT1.0-me
        /// <summary>
        /// 获得验证码
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public HttpResponseMessage getCode()
        {
            //生成验证码
            ValidateCode vCode = new ValidateCode();
            string       code  = vCode.CreateValidateCode(5);

            UserSession.ValidateCode = code;
            byte[] bytes = vCode.CreateValidateGraphic(code);

            var result = new HttpResponseMessage(HttpStatusCode.OK);

            result.Content = new ByteArrayContent(bytes);
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            return(result);
        }
コード例 #28
0
        public static string GetValidateCode(int number)
        {
            //number :验证码的位数
            //amount :生成的验证码个数
            var amount = 200;
            int a;
            var valiCodes = new List <ValidateCode>();
            var codeArray = new string[amount];
            var rd        = new Random();
            var i         = 0;

            do
            {
                string[] source =
                {
                    "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J",
                    "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
                };
                var code = "";

                for (var j = 0; j < number; j++)
                {
                    code += source[rd.Next(0, source.Length)];
                }

                a = 0;
                foreach (var valicode in valiCodes)
                {
                    if (valicode.Name == code)
                    {
                        a = 1;
                        break;
                    }
                }
                if (a != 1)
                {
                    var valicode = new ValidateCode();
                    valicode.Name = code;
                    codeArray[i]  = code;
                    valiCodes.Add(valicode);
                    i++;
                }
            } while (i != amount);
            Thread.Sleep(10);
            var singleCode = codeArray[rd.Next(0, codeArray.Length)];

            return(singleCode);
        }
コード例 #29
0
        /// <summary>
        /// 发送验证邮件
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="DeviceID"></param>
        /// <returns></returns>
        public Boolean SendEmail(String Email, String DeviceID)
        {
            try
            {
                if (Regex.IsMatch(Email, @"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", RegexOptions.IgnoreCase))
                {
                    int        value      = new Random().Next(1000, 10000); //生成大于等于1000,小于10000的随机数
                    String     userName   = "******";
                    String     pwd        = "rasgprchoxfgbjab";
                    String     host       = "smtp.qq.com";
                    SmtpClient smtpClient = new SmtpClient();
                    smtpClient.Credentials = new NetworkCredential(userName, pwd);
                    smtpClient.Host        = host;

                    //如果是gmail 则需要将EnableSsl设置为True,163则设置为False
                    //smtpClient.EnableSsl = false;
                    smtpClient.EnableSsl = true;

                    MailMessage mailMsg = new MailMessage();
                    mailMsg.Priority   = MailPriority.High;
                    mailMsg.From       = new MailAddress(userName);
                    mailMsg.Subject    = "邮箱验证";
                    mailMsg.Body       = value.ToString();
                    mailMsg.IsBodyHtml = true;
                    mailMsg.To.Add(new MailAddress(Email));
                    smtpClient.Send(mailMsg);
                    smtpClient = null;

                    ValidateCode validateCode = new ValidateCode();
                    validateCode.CREATEDATE  = DateTime.Now;
                    validateCode.DEVICEID    = DeviceID;
                    validateCode.PHONENUMBER = Email;
                    validateCode.VCODE       = value.ToString();
                    _unitOfWork.RegisterNew(validateCode);
                    _unitOfWork.Commit();
                    return(true);
                }
                else
                {
                    throw new Exception("错误的邮箱");
                }
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                throw ex;
            }
        }
コード例 #30
0
ファイル: LoginController.cs プロジェクト: xiaolin8/AMS
 /// <summary>
 /// 返回验证码图片
 /// </summary>
 public ActionResult getCheckCode()
 {
     //首先实例化验证码的类
     ValidateCode validateCode = new ValidateCode();
     //生成验证码指定的长度
     string code = validateCode.GetRandomString(4);
     //将验证码赋值给Session变量
     //Session["ValidateCode"] = code;
     this.TempData["ValidateCode"] = code;//TempData是一个字典类,作用是在Action执行过程之间传值
     //简单的说,你可以在执行某个Action的时候,将数据存放在TempData中,那么在下一次Action执行过程中可以使用TempData中的数据
     //参考:http://developer.51cto.com/art/200904/118494.htm
     //创建验证码的图片
     byte[] bytes = validateCode.CreateImage(code);
     //最后将验证码返回
     return File(bytes, @"image/jpeg");
 }
コード例 #31
0
        /// <summary>
        /// 生成验证码,把验证信息存放的session中
        /// </summary>
        /// <returns></returns>
        public ActionResult GetImgCode(string id)
        {
            string code = string.Empty;

            byte[] bytes = ValidateCode.CreateValidateGraphic(out code);
            if (id == "register")
            {
                CacheHelper.Session["registercode"] = code.ToLower();
            }
            else if (id == "login")
            {
                CacheHelper.Session["logincode"] = code.ToLower();
            }

            return(File(bytes, @"image/jpeg"));
        }
コード例 #32
0
        public ActionResult ShowValiDateCode()
        {
            //Random rd = new Random();
            //int[] k = new int[]{};
            //for (int i = 0; i < 4; i++)
            //{
            //    k[i] = rd.Next(1, 10);
            //}
            ValidateCode vdc  = new ValidateCode();
            string       code = vdc.CreateValidateCode(4);

            Session["ValiDateCode"] = code;
            byte[] buff = vdc.CreateValidateGraphic(code);

            return(File(buff, "image/jpeg"));
        }
コード例 #33
0
ファイル: UserService.Account.cs プロジェクト: panjiyang/Bode
        /// <summary>
        /// 获取用户注册验证码
        /// </summary>
        /// <param name="phoneNo">手机号</param>
        /// <param name="codeType"></param>
        /// <returns>业务操作结果</returns>
        public async Task<OperationResult> GetSmsValidateCode(string phoneNo, CodeType codeType)
        {
            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var codeEntity = new ValidateCode()
            {
                PhoneNo = phoneNo,
                Code = validateCode,
                CodeType = codeType
            };
            await ValidateCodeRepo.InsertAsync(codeEntity);

            //发送手机短信
            var smsContent = "您本次的验证码为" + validateCode + ",工作人员不会向您索要此验证码,请勿向任何人泄露。[右行养车]";
            Sms.Send(phoneNo,1, smsContent);


            return new OperationResult(OperationResultType.Success, "验证码发送成功", validateCode);
        }
コード例 #34
0
        public ValidateCodeSettings()
        {
            ValidateCodes = new ValidateCodeCollection();
            ValidateCodes.Add(new ValidateCode("ManageLogin", true, "ValidateCode_Style1"));

            ValidateCodes.Add(new ValidateCode("Register", true, "ValidateCode_Style1"));

            ValidateCode loginV = new ValidateCode("Login", true, "ValidateCode_Style1");
            loginV.LimitedCount = 3;
            loginV.LimitedTime = 60 * 60;
            ValidateCodes.Add(loginV);

            ValidateCode v = new ValidateCode("CreateTopic", true, "ValidateCode_Style1");
            v.LimitedCount = 5;
            v.LimitedTime = 60;

            ValidateCodes.Add(v);

            v = new ValidateCode("ReplyTopic", true, "ValidateCode_Style1");
            v.LimitedCount = 5;
            v.LimitedTime = 60;

            ValidateCodes.Add(v);
        }
コード例 #35
0
ファイル: UserService.Account.cs プロジェクト: wx5050520/Bode
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="codeKey">验证码Key</param>
        /// <param name="validateType">验证方式</param>
        /// <param name="codeType">验证码类型</param>
        /// <param name="sendAction">发送委托</param>
        /// <returns>业务操作结果</returns>
        private async Task<OperationResult> SendValidateCode(string codeKey, ValidateType validateType, CodeType codeType, Action<string> sendAction)
        {
            codeKey.CheckNotNull("codeKey");
            sendAction.CheckNotNull("sendAction");

            string validateCode = new ValidateCoder().GetCode(6, ValidateCodeType.Number);
            var codeEntity = new ValidateCode()
            {
                CodeKey = codeKey,
                Code = validateCode,
                ValidateType = validateType,
                CodeType = codeType
            };
            await ValidateCodeRepo.InsertAsync(codeEntity);

            sendAction(validateCode);
            return new OperationResult(OperationResultType.Success, "验证码发送成功", "");
        }
コード例 #36
0
        private void SaveValidateStyle()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();

            string actiontype = _Request.Get("actiontype", Method.Get, string.Empty);

            string validateCodeStyle = _Request.Get("validateCodeStyle",Method.Post,string.Empty);

            bool isInvalidActionType = true;

            foreach (ValidateCodeAction action in ValidateCodeManager.GetAllValidateCodeActions())
            {
                if (string.Compare(action.Type, actiontype, true) == 0)
                {
                    isInvalidActionType = false;
                    break;
                }
            }

            if (isInvalidActionType == true)
            {
                msgDisplay.AddError(new InvalidParamError("actiontype").Message);
            }


            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            bool hasAdd = false;

            foreach (ValidateCode validateCode in AllSettings.Current.ValidateCodeSettings.ValidateCodes)
            {
                if (string.Compare(validateCode.ActionType, actiontype, true) == 0)
                {
                    ValidateCode tempValidateCode = (ValidateCode)validateCode.Clone();

                    tempValidateCode.ValidateCodeType = validateCodeStyle;

                    tempValidateCodes.Add(tempValidateCode);

                    hasAdd = true;
                }
                else
                {
                    tempValidateCodes.Add(validateCode);
                }
            }

            if (hasAdd == false)
            {
                ValidateCode validateCode = new ValidateCode();

                validateCode.ValidateCodeType = validateCodeStyle;
                validateCode.ActionType = actiontype;

                tempValidateCodes.Add(validateCode);
            }


            try
            {
                using (new ErrorScope())
                {

                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    Success = SettingManager.SaveSettings(setting);

                    if (!Success)
                    {
                        CatchError<ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        Return(true);
                    }

                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
コード例 #37
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ValidateCode vc = new ValidateCode();
     Session["ValidateCode"] = vc.DrawImage();
 }
コード例 #38
0
        private void SaveValidateCode()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay("Limited");

            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            int i = 0;

            foreach (ValidateCodeAction action in ValidateCodeActionList)
            {
                ValidateCode validateCode = new ValidateCode();
                validateCode.Enable = _Request.Get<bool>("enable." + action.Type, Method.Post, false);
                validateCode.ActionType = action.Type;

                string valueString = _Request.Get("LimitedTime."+action.Type,Method.Post,string.Empty);

                int limitedTime = 0;

                string error = string.Empty;

                if (valueString.Trim() != string.Empty)
                {
                    if (!int.TryParse(valueString, out limitedTime))
                    {
                        error = Lang_Error.ValidateCode_LimitedTimeError;
                    }
                    else if (limitedTime < 0)
                        error = Lang_Error.ValidateCode_LimitedTimeError;
                }

                int timeType = _Request.Get<int>("limitedTimeType." + action.Type, Method.Post, 0);

                TimeUnit timeUnit = (TimeUnit)timeType;

                validateCode.LimitedTime = (int)DateTimeUtil.GetSeconds(limitedTime,timeUnit);


                valueString = _Request.Get("LimitedCount." + action.Type, Method.Post, string.Empty);

                int limitedCount = 0;

                if (valueString.Trim() != string.Empty)
                {
                    if (!int.TryParse(valueString, out limitedCount))
                    {
                        error = error + Lang_Error.ValidateCode_LimitedCountError;
                    }
                    else if (limitedCount < 0)
                        error = error + Lang_Error.ValidateCode_LimitedCountError;
                }
                if (error != string.Empty)
                {
                    msgDisplay.AddError("limited", i, error);
                    i++;
                    continue;
                }

                i++;

                validateCode.LimitedCount = limitedCount;


                ValidateCode tempValidateCode = AllSettings.Current.ValidateCodeSettings.ValidateCodes.GetValue(action.Type);

                if (tempValidateCode != null)
                {
                    validateCode.ExceptRoleIds = tempValidateCode.ExceptRoleIds;
                    validateCode.ValidateCodeType = tempValidateCode.ValidateCodeType;
                }

                tempValidateCodes.Add(validateCode);
            }


            if (msgDisplay.HasAnyError())
                return;

            try
            {
                using (new ErrorScope())
                {

                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    bool success = SettingManager.SaveSettings(setting);

                    if (!success)
                    {
                        CatchError<ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        //msgDisplay.ShowInfo(this);
                    }

                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }
コード例 #39
0
        private void SaveValidateRole()
        {
            MessageDisplay msgDisplay = CreateMessageDisplay();

            string actiontype = _Request.Get("actiontype", Method.Get, string.Empty);


            string roleIDString = _Request.Get("validateCodeRole", Method.Post, string.Empty);

            if (roleIDString.Length == 0)
                return;


            bool isInvalidActionType = true;

            foreach (ValidateCodeAction action in ValidateCodeManager.GetAllValidateCodeActions())
            {
                if (string.Compare(action.Type, actiontype, true) == 0)
                {
                    if (action.CanSetExceptRoleId == false)
                    {
                        msgDisplay.AddError(string.Format(Lang_Error.ValidateCode_ValidateCodeActionCannotSetExceptRoleID, action.Name));
                        return;
                    }
                    isInvalidActionType = false;
                    break;
                }
            }

            if (isInvalidActionType == true)
            {
                msgDisplay.AddError(new InvalidParamError("actiontype").Message);
            }


            StringList exceptRoleIDs = new StringList();

            foreach (string roleID in roleIDString.Split(','))
            {
                exceptRoleIDs.Add(roleID);
            }


            ValidateCodeCollection tempValidateCodes = new ValidateCodeCollection();

            bool hasAdd = false;

            foreach (ValidateCode validateCode in AllSettings.Current.ValidateCodeSettings.ValidateCodes)
            {
                if (string.Compare(validateCode.ActionType, actiontype, true) == 0)
                {
                    ValidateCode tempValidateCode = (ValidateCode)validateCode.Clone();

                    tempValidateCode.ExceptRoleIds = exceptRoleIDs;

                    tempValidateCodes.Add(tempValidateCode);

                    hasAdd = true;
                }
                else
                {
                    tempValidateCodes.Add(validateCode);
                }
            }

            if (hasAdd == false)
            {
                ValidateCode validateCode = new ValidateCode();

                validateCode.ExceptRoleIds = exceptRoleIDs;
                validateCode.ActionType = actiontype;

                tempValidateCodes.Add(validateCode);
            }


            try
            {
                using (new ErrorScope())
                {

                    ValidateCodeSettings setting = (ValidateCodeSettings)AllSettings.Current.ValidateCodeSettings.Clone();

                    setting.ValidateCodes = tempValidateCodes;

                    bool success = SettingManager.SaveSettings(setting);

                    if (!success)
                    {
                        CatchError<ErrorInfo>(delegate(ErrorInfo error)
                        {
                            msgDisplay.AddError(error);
                        });
                    }
                    else
                    {
                        Return(true);
                    }

                }
            }
            catch (Exception ex)
            {
                msgDisplay.AddError(ex.Message);
            }
        }