private Match ValidateCustomPattern(string custPattern) { try { Match m = null; lock (fullPatternCache) { if (fullPatternCache.TryGetValue(custPattern, out m)) { return(m); } m = MyRegex.Match(custPattern); if (!m.Success) { throw new FormatException(); } fullPatternCache.Add(custPattern, m); } return(m); } catch { throw new FormatException(); } }
public static List <string> Scan(string input, string pattern) { return(MyRegex.Matches(input, pattern) .Cast <Match>() .Select(m => (m.Groups.Count == 2) ? m.Groups[1].Value : m.Value) .ToList()); }
private static string[] VariablesFromString(string markup) { return(markup.Split(',').Select(var => { Match match = MyRegex.Match(var, string.Format(R.Q(@"\s*({0})\s*"), Liquid.QuotedFragment)); return (match.Success && !string.IsNullOrEmpty(match.Groups[1].Value)) ? match.Groups[1].Value : null; }).ToArray()); }
public static string FromShortHand(string @string) { if (@string == null) { return(@string); } Match match = MyRegex.Match(@string, Liquid.CommentShorthand); return(match.Success ? string.Format(@"{{% comment %}}{0}{{% endcomment %}}", match.Groups[1].Value) : @string); }
/// <summary> /// 完善手机 /// </summary> /// <param name="mobile"></param> /// <param name="code"></param> /// <returns></returns> public ActionResult PostMobile(string mobile, string code) { if (!MyRegex.IsPhone(mobile)) { return(JsonResult(APIErrCode.PhoneFormatError, "手机格式错误")); } var authenticationUser = BLLAuthentication.GetAuthenticationUser(); var obj = new XCache().Get("Code" + authenticationUser.openid);//写入缓存 if (obj == null) { return(JsonResult(APIErrCode.CheckCodeErr, "验证码已过期")); } if (obj.ToString().ToUpper() != code.Trim().ToUpper()) { return(JsonResult(APIErrCode.CheckCodeErr, "验证码错误")); } ht_user user = BLLUser.GetUserByOpenid(authenticationUser.openid); if (user == null) { user = new ht_user(); user.addtime = DateTime.Now; user.username = user.openid; user.openid = authenticationUser.openid; user.salt = Utils.GetSalt(); user.password = EncryptUtil.DesEncrypt("123456", user.salt); user.points = 0; user.money = 0; if (authenticationUser.parent_id.HasValue) { user.parent_id = authenticationUser.parent_id; ht_user parentUser = BLLUser.GetUserById(authenticationUser.parent_id.Value); if (parentUser != null && parentUser.parent_id.HasValue) { user.pparent_id = parentUser.parent_id; } } } user.mobile = mobile; user.avatar = authenticationUser.avatar; user.nickname = authenticationUser.nickname; if (BLLUser.PostUser(user) > 0) { BLLAuthentication.LoginAuthenticationTicket(user); return(JsonResult(APIErrCode.Success, "提交成功")); } return(JsonResult(APIErrCode.CheckCodeErr, "提交失败")); }
public void Search() { List <ResultRow> resultMatch = new List <ResultRow>(); List <ResultRow> results = new List <ResultRow>(); foreach (Model.Story story in stories.getStories()) { foreach (Model.Chapter chap in story.getChapters()) { MyRegex regex = new MyRegex(); regex.InputString = input; regex.Content = chap.content; Match match = regex.GenerateRegexAllMatch(); if (match != null) { int start = match.Index; int len = match.Value.Length; ResultRow item = new ResultRow(); item.index_story = story.idt - 1; item.index_chap = story.getChapters().IndexOf(chap); item.start = start; item.len = len; item.resulttext = story.name + " - " + chap.name + ": " + match.Value; resultMatch.Add(item); } else { List <Result> result = regex.FuzzyMethod(); foreach (Result rs in result) { int start = rs.begin; int len = rs.end - rs.begin; ResultRow item = new ResultRow(); item.index_story = story.idt - 1; item.index_chap = story.getChapters().IndexOf(chap); item.start = start; item.len = len; item.resulttext = story.name + " - " + chap.name + ": (" + rs.numberRhythmsMatch + ")" + chap.content.Substring(start, len); results.Add(item); } } } } listBox1.Invoke((MethodInvoker) delegate() { listBox1.DataSource = resultMatch.Count > 0 ? resultMatch : results; }); progress.Invoke((MethodInvoker) delegate() { progress.Dispose(); }); }
public string FullPath(string templatePath) { if (templatePath == null || !Regex.IsMatch(templatePath, @"^[^.\/][a-zA-Z0-9_\/]+$")) { throw new FileSystemException( Liquid.ResourceManager.GetString("LocalFileSystemIllegalTemplateNameException"), templatePath); } var basePath = templatePath.Contains("/") ? Path.Combine(Root, Path.GetDirectoryName(templatePath)) : Root; var fileName = string.Format("_{0}.liquid", Path.GetFileName(templatePath)); var fullPath = MyRegex.Replace(Path.Combine(basePath, fileName), @"\\|/", "."); return(fullPath); }
private ParseEntity GetParsedTokens(Match m) { // Handle each match group var head = new ParseEntity(".", m, null); var list = head.children = new List <ParseEntity>(); foreach (var gn in MyRegex.GetGroupNames()) { if (gn != "OPT" && gn != "0") { var g = m.Groups[gn]; if (g.Success) { foreach (Capture c in g.Captures) { list.Add(new ParseEntity(gn, c, head)); } } } } list.Sort((p1, p2) => p1.start - p2.start); // Put in groupings foreach (Capture c in m.Groups["OPT"].Captures) { var f = list.FindIndex(p1 => p1.start > c.Index); var l = list.FindLastIndex(p1 => p1.start + p1.length < c.Index + c.Length); var p = new ParseEntity(null, c, head) { children = list.GetRange(f, l - f + 1) }; list.RemoveRange(f, l - f + 1); p.children.ForEach(delegate(ParseEntity pe) { pe.parent = p; }); list.Insert(f, p); } #if DEBUG for (var i = 0; i < list.Count; i++) { Debug.WriteLine(string.Format("Match {3} = \"{1}\" ({0}:{2})", list[i].start, list[i].value, list[i].length, list[i].name)); } #endif return(head); }
public static void Test() { MyRegex original = new MyRegex { Regex = "\\b[1-3]{1}\\b#Must be a value of 1 to 3" }; string xml = SerializerHelper <MyRegex> .Serialize(original); Console.WriteLine("--- SERIALIZE ---"); Console.WriteLine(xml); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("--- DESERIALIZE ---"); MyRegex deSerial = SerializerHelper <MyRegex> .DeSerialize(xml); Console.WriteLine("Equals? " + (deSerial.Regex.Equals(original.Regex))); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Console.ReadKey();"); Console.ReadKey(); }
/**/ /**/ /**/ /**/ /**/ /**/ /**/ /// <summary> ///将汉字转换成为拼音 ///作者: ///完成于: /// </summary> static Regex MyRegex = new Regex("^[一-龥]$"); //汉字的正则表达式.eg: if(MyRegex.IsMatch(chrstr.ToString())) private static readonly int[] pyvalue = new int[] { -20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036, -20032, -20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, -19741, -19739, -19728, -19725, -19715, -19540, -19531, -19525, -19515, -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, -19263, -19261, -19249, -19243, -19242, -19238, -19235, -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977, -18961, -18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490, -18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, -17970, -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703, -17701, -17697, -17692, -17683, -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, -17185, -16983, -16970, -16942, -16915, -16733, -16708, -16706, -16689, -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, -16419, -16412, -16407, -16403, -16401, -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, -16155, -15959, -15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, -15652, -15640, -15631, -15625, -15454, -15448, -15436, -15435, -15419, -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, -15183, -15180, -15165, -15158, -15153, -15150, -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, -14941, -14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857, -14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594, -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345, -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, -14092, -14090, -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, -13894, -13878, -13870, -13859, -13847, -13831, -13658, -13611, -13601, -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, -13359, -13356, -13343, -13340, -13329, -13326, -13318, -13147, -13138, -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, -12875, -12871, -12860, -12858, -12852, -12849, -12838, -12831, -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, -12346, -12320, -12300, -12120, -12099, -12089, -12074, -12067, -12058, -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, -11536, -11358, -11340, -11339, -11324, -11303, -11097, -11077, -11067, -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014, -10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309, -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254 }; private static readonly string[] pystr = new string[] { "a", "ai", "an", "ang", "ao", "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", "bian", "biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", "can", "cang", "cao", "ce", "ceng", "cha", "chai", "chan", "chang", "chao", "che", "chen", "cheng", "chi", "chong", "chou", "chu", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan", "cui", "cun", "cuo", "da", "dai", "dan", "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong", "dou", "du", "duan", "dui", "dun", "duo", "e", "en", "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu", "ga", "gai", "gan", "gang", "gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", "guo", "ha", "hai", "han", "hang", "hao", "he", "hei", "hen", "heng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo", "ji", "jia", "jian", "jiang", "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", "kan", "kang", "kao", "ke", "ken", "keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai", "lan", "lang", "lao", "le", "lei", "leng", "li", "lia", "lian", "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", "lv", "luan", "lue", "lun", "luo", "ma", "mai", "man", "mang", "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu", "na", "nai", "nan", "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", "niao", "nie", "nin", "ning", "niu", "nong", "nu", "nv", "nuan", "nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pu", "qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", "re", "ren", "reng", "ri", "rong", "rou", "ru", "ruan", "rui", "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", "seng", "sha", "shai", "shan", "shang", "shao", "she", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", "shui", "shun", "shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo", "ta", "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao", "tie", "ting", "tong", "tou", "tu", "tuan", "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu", "xi", "xia", "xian", "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", "yan", "yang", "yao", "ye", "yi", "yin", "ying", "yo", "yong", "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan", "zang", "zao", "ze", "zei", "zen", "zeng", "zha", "zhai", "zhan", "zhang", "zhao", "zhe", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui", "zhun", "zhuo", "zi", "zong", "zou", "zu", "zuan", "zui", "zun", "zuo" }; /**/ /// <summary> /// 转化汉字的全部拼音 /// </summary> /// <param name="chrstr"></param> /// <returns></returns> public static string Convert(string chrstr) { byte[] array = new byte[2]; string returnstr = ""; int chrasc; int i1; int i2; char[] nowchar = chrstr.ToCharArray(); for (int j = 0; j < nowchar.Length; j++) { if (MyRegex.IsMatch(nowchar[j].ToString())) { array = System.Text.Encoding.UTF8.GetBytes(nowchar[j].ToString()); i1 = (short)(array[0]); i2 = (short)(array[1]); chrasc = i1 * 256 + i2 - 65536; if (chrasc > 0 && chrasc < 160) { returnstr += nowchar[j]; } else { for (int i = (pyvalue.Length - 1); i >= 0; i--) { if (pyvalue[i] <= chrasc) { returnstr += pystr[i]; break; } } } } else { returnstr += nowchar[j].ToString(); } } return(returnstr); }
/// <summary> /// 获取验证码 /// </summary> /// <returns></returns> public ActionResult GetCode(string mobile) { if (!MyRegex.IsPhone(mobile)) { return(JsonResult(APIErrCode.PhoneFormatError, "手机格式错误")); } AuthenticationUser authenticationUser = BLLAuthentication.GetAuthenticationUser(); string code = HT.Utility.Utils.Number(6); return(JsonResult(APIErrCode.Success, "获取验证码成功", code)); string sms_expire = BLLConfig.Get("sms_expire"); int expire = Convert.ToInt32(sms_expire); string msg = ""; if (BLLSendSms.SendMsg(mobile, code, "mobile", expire, out msg)) { new XCache().Add("Code" + authenticationUser.openid, code, expire);//写入缓存 return(JsonResult(APIErrCode.Success, "获取验证码成功", code)); } return(JsonResult(APIErrCode.OperateFail, msg)); }
private void HomePage_Load(object sender, EventArgs e) { resize(); Model.Stories stories = Model.MyDatabase.getStories(); List <Model.Story> list = stories.getStories(); liststory.DataSource = list; MyRegex regex = new MyRegex(); regex.InputString = "Phong Điền Khí"; regex.Content = "tiền bối Phong Thanh ... gã khi Điền Bá .. bên tông phái"; Match match = regex.GenerateRegexAllMatch(); if (match != null) { MessageBox.Show(match.Value); } else { List <Result> results = regex.FuzzyMethod(); } }
public void Search() { List <string> results = new List <string>(); Model.Stories stories = Model.MyDatabase.getStories(); foreach (Model.Story story in stories.getStories()) { foreach (Model.Chapter chap in story.getChapters()) { MyRegex regex = new MyRegex(); regex.InputString = input; regex.Content = chap.content; Match match = regex.GenerateRegexAllMatch(); if (match != null) { MessageBox.Show("Tìm thấy tại " + story.name + " - " + chap.name); this.Dispose(); return; } else { List <Result> result = regex.FuzzyMethod(); foreach (Result rs in result) { int start = rs.begin; int len = rs.end - rs.begin; results.Add(story.name + " - " + chap.name + ": (" + rs.numberRhythmsMatch + ")" + chap.content.Substring(start, len)); } } } } listBox1.DataSource = results; this.Show(); }
public void ProcessRequest(HttpContext context) { string phone = context.Request["phone"]; string code = context.Request["code"]; #region 判断手机格式 if (!MyRegex.PhoneNumLogicJudge(phone)) { apiResp.code = (int)APIErrCode.PhoneFormatError; apiResp.msg = "手机格式错误"; bllSms.ContextResponse(context, apiResp); return; } #endregion #region 判断手机是否已被使用,且是否是当前账号 UserInfo model = bllUser.GetUserInfoByPhone(phone); if (model != null) { if (model.UserID != CurrentUserInfo.UserID) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机号码已被其他账号使用,请联系管理员"; bllSms.ContextResponse(context, apiResp); return; } //if (model.IsPhoneVerify == 1) //{ // apiResp.code = (int)APIErrCode.OperateFail; // apiResp.msg = "手机号码已验证"; // bllSms.ContextResponse(context, apiResp); // return; //} } #endregion #region 判断验证码是否正确 SmsVerificationCode sms = bllSms.GetLastSmsVerificationCode(phone); if (sms.VerificationCode != code) { apiResp.code = (int)APIErrCode.CheckCodeErr; apiResp.msg = "验证码错误"; bllSms.ContextResponse(context, apiResp); return; } #endregion CurrentUserInfo.Phone = phone; CurrentUserInfo.IsPhoneVerify = 1; CompanyWebsite_Config nWebsiteConfig = bllWebSite.GetCompanyWebsiteConfig(); if (nWebsiteConfig.MemberStandard == 1) { if (CurrentUserInfo.AccessLevel < 1) { CurrentUserInfo.AccessLevel = 1; CurrentUserInfo.MemberStartTime = DateTime.Now; } //CurrentUserInfo.MemberApplyStatus = 9; } if (bllUser.Update(CurrentUserInfo)) { apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "手机验证完成"; } else { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "验证失败"; } bllSms.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { List <TableFieldMapping> formField = bllTableFieldMap.GetTableFieldMapByWebsite(bllTableFieldMap.WebsiteOwner, "ZCJ_UserInfo", null, null, context.Request["mapping_type"]); formField = formField.Where(p => p.IsReadOnly == 0 && p.IsDelete == 0 && p.Field != "AutoID").ToList(); if (formField.Count == 0) { apiResp.msg = "没有可编辑字段"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } List <string> limitFields = new List <string>() { "UserID", "Phone", "WXOpenId" }; #region 默认信息检查 姓名 string autoID = context.Request["AutoID"]; if (string.IsNullOrWhiteSpace(autoID) || autoID == "0") { apiResp.msg = "用户未找到"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } UserInfo curUser = bllTableFieldMap.GetByKey <UserInfo>("AutoID", autoID); if (curUser == null) { apiResp.msg = "用户未找到"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } #endregion List <string> pms = new List <string>(); #region 构造修改字段 TableFieldMapping userIDField = formField.FirstOrDefault(p => p.Field.Equals("UserID")); if (userIDField != null) { string val = context.Request[userIDField.Field]; if (!string.IsNullOrWhiteSpace(val)) { List <UserInfo> oUserList = bllTableFieldMap.GetColList <UserInfo>(int.MaxValue, 1, string.Format("UserID='{0}' And AutoID != {1} ", val, autoID), "AutoID,UserID"); if (oUserList.Count > 0) { apiResp.msg = "账号已被使用"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } pms.Add(string.Format("{0}='{1}'", userIDField.Field, val)); } } TableFieldMapping phoneField = formField.FirstOrDefault(p => p.Field.Equals("Phone")); if (phoneField != null) { string val = context.Request[phoneField.Field]; if (!string.IsNullOrWhiteSpace(val)) { List <UserInfo> oUserList = bllTableFieldMap.GetColList <UserInfo>(int.MaxValue, 1, string.Format("Phone='{0}' And WebsiteOwner='{2}' And AutoID != {1} And IsSubAccount!='1'", val, autoID, bllTableFieldMap.WebsiteOwner), "AutoID,Phone"); if (oUserList.Count > 0) { apiResp.msg = "手机号已被使用"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } pms.Add(string.Format("{0}='{1}'", phoneField.Field, val)); } } TableFieldMapping wXOpenIdField = formField.FirstOrDefault(p => p.Field.Equals("WXOpenId")); if (wXOpenIdField != null) { string val = context.Request[wXOpenIdField.Field]; if (!string.IsNullOrWhiteSpace(val)) { List <UserInfo> oUserList = bllTableFieldMap.GetColList <UserInfo>(int.MaxValue, 1, string.Format("WXOpenId='{0}' And WebsiteOwner='{2}' And AutoID != {1} ", val, autoID, bllTableFieldMap.WebsiteOwner), "AutoID,Phone"); if (oUserList.Count > 0) { apiResp.msg = "WXOpenId已被使用"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } pms.Add(string.Format("{0}='{1}'", wXOpenIdField.Field, val)); } } foreach (TableFieldMapping item in formField.Where(p => !limitFields.Contains(p.Field))) { string val = context.Request[item.Field]; if (string.IsNullOrWhiteSpace(val) && item.FieldIsNull == 1) { apiResp.msg = item.MappingName + "不能为空"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); return; } if (string.IsNullOrWhiteSpace(val)) { pms.Add(string.Format("{0}=Null", item.Field)); } else { if (!string.IsNullOrWhiteSpace(item.FormatValiFunc)) { #region 检查数据格式 //检查数据格式 if (item.FormatValiFunc == "number") { if (!MyRegex.IsNumber(val)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "phone")//email检查 { if (!MyRegex.PhoneNumLogicJudge(val)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "email")//email检查 { if (!MyRegex.EmailLogicJudge(val)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "url") //url检查 { System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址 System.Text.RegularExpressions.Match match = regUrl.Match(val); if (!match.Success) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } #endregion } pms.Add(string.Format("{0}='{1}'", item.Field, val)); } } #endregion if (bllTableFieldMap.Update(new UserInfo(), ZentCloud.Common.MyStringHelper.ListToStr(pms, "", ","), string.Format("AutoID={0}", autoID)) > 0) { apiResp.status = true; apiResp.msg = "编辑完成"; apiResp.code = (int)APIErrCode.IsSuccess; bllUser.AddUserScoreDetail(curUser.UserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.UpdateMyInfo), bllUser.WebsiteOwner, null, null); // TableFieldMapping tagNameField = formField.FirstOrDefault(p => p.Field.Equals("TagName")); if (tagNameField != null && context.Request["TagName"] != null) { foreach (var tag in context.Request["TagName"].Split(',')) { if (bllUser.GetCount <ZentCloud.BLLJIMP.Model.MemberTag>(string.Format(" WebsiteOwner='{0}' And TagName='{1}' And TagType='Member'", bllUser.WebsiteOwner, tag)) == 0) { ZentCloud.BLLJIMP.Model.MemberTag model = new BLLJIMP.Model.MemberTag(); model.CreateTime = DateTime.Now; model.WebsiteOwner = bllUser.WebsiteOwner; model.TagType = "Member"; model.TagName = tag; model.Creator = currentUserInfo.UserID; if (!bllUser.Add(model)) { apiResp.msg = "新增标签失败"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); } } } } // } else { apiResp.msg = "编辑失败"; apiResp.code = (int)APIErrCode.OperateFail; } bllTableFieldMap.ContextResponse(context, apiResp); }
private void ToOss3(DataTable dt) { StringBuilder sb = new StringBuilder(); foreach (DataRow dr in dt.Rows) { try { string htmlField = dr[txt2].ToString(); if (string.IsNullOrWhiteSpace(htmlField)) { continue; } List <string> srcList = MyRegex.GetPadImg(htmlField); if (srcList.Count == 0) { continue; } foreach (var item in srcList) { string oldFile = MyRegex.GetPadSrcUrl(item); string oldFile1 = ""; if (oldFile.StartsWith(OssHelper.GetDomain())) { SetTextErrorMessage("已经在Oss服务器:" + oldFile); continue; } else if (oldFile.StartsWith("/")) { oldFile1 = oldFile; } else { bool haveLocalSrc = false; string nowWebDomain = ""; for (int i = 0; i < txtLikeWebDomain.Length; i++) { if (oldFile.IndexOf(txtLikeWebDomain[i]) > 0) { haveLocalSrc = true; nowWebDomain = txtLikeWebDomain[i]; break; } } if (!haveLocalSrc) { SetTextErrorMessage("不是本站图片:" + oldFile); continue; } oldFile1 = oldFile.Substring(oldFile.IndexOf(nowWebDomain) + nowWebDomain.Length - 1); } SetTextErrorMessage(oldFile1); string url = ""; DataSet ds = DbHelperSQL.Query(string.Format("SELECT TOP 1 OldPath,NewPath FROM {0} WHERE OldPath='{1}' ", "FileToOssLog", oldFile1)); if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count == 1) { url = ds.Tables[0].Rows[0]["NewPath"].ToString(); } if (string.IsNullOrWhiteSpace(url)) { ds = DbHelperSQL.Query(string.Format("SELECT TOP 1 OldPath,NewPath FROM {0} WHERE OldPath='{1}' ", "FileToOssLog", oldFile)); if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count == 1) { url = ds.Tables[0].Rows[0]["NewPath"].ToString(); } } if (string.IsNullOrWhiteSpace(url)) { string LocalPath = txt5 + oldFile1.Replace("/", @"\"); string extension = Path.GetExtension(oldFile1).ToLower(); if (!File.Exists(LocalPath)) { SetTextErrorMessage("文件不存在:" + LocalPath); continue; } byte[] fileByte = File.ReadAllBytes(LocalPath); if (fileByte.Length == 0) { SetTextErrorMessage("文件大小为空:" + LocalPath); continue; } url = OssHelper.UploadFileFromByte(OssHelper.GetBucket(""), baseDir + oldFile1, fileByte, extension); } DataSet ds1 = DbHelperSQL.Query( string.Format("SELECT 1 FROM {0} WHERE [TableKeyID]='{1}' AND [TableName]='{2}' AND [FieldName]='{3}' AND [OldPath]='{4}'" , "FileToOssLog", dr[txt4].ToString(), txt1, txt2, oldFile)); if (ds1 != null && ds1.Tables.Count != 0 && ds1.Tables[0].Rows.Count == 0) { sb.AppendFormat("INSERT INTO {0} ([TableKeyID],[TableName],[FieldName],[OldPath],[NewPath]) ", "FileToOssLog"); sb.AppendFormat("VALUES ('{0}','{1}','{2}','{3}','{4}') ;", dr[txt4].ToString(), txt1, txt2, oldFile, url); } } } catch (Exception ex) { SetTextErrorMessage(ex.Message); } finally { now++; SetTextMessage(); } } try { if (!string.IsNullOrWhiteSpace(sb.ToString())) { DbHelperSQL.ExecuteSql(sb.ToString()); } } catch (Exception ex) { SetTextErrorMessage(ex.Message); } }
/// <summary> /// Set the input validation. /// </summary> /// <param name="_validator">A Validator param.</param> /// <returns></returns> public IMyTextBox setInputValidation(Validator.Validator _validator) { myRegex = _validator.getMyRegex(); return(this); }
private Validator(MyRegex _regex) { this.regex = _regex; }
public void ProcessRequest(HttpContext context) { string code = context.Request["code"]; string Phone = context.Request["Phone"]; UserInfo CurrentUserInfo = bllUser.GetCurrentUserInfo(); #region 检查是否已登录 if (CurrentUserInfo != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "本功能仅供新用户使用"; bllUser.ContextResponse(context, apiResp); return; } #endregion #region 检查是否微信服务号 if (context.Session["currWXOpenId"] == null) { apiResp.code = (int)APIErrCode.UserIsNotLogin; apiResp.msg = "本功能仅供微信服务号使用"; bllUser.ContextResponse(context, apiResp); return; } #endregion string wxOpenId = context.Session["currWXOpenId"].ToString(); CurrentUserInfo = bllUser.GetUserInfoByOpenId(wxOpenId); if (CurrentUserInfo != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "OpenId已被绑定"; bllUser.ContextResponse(context, apiResp); return; } #region 判断手机格式 if (!MyRegex.PhoneNumLogicJudge(Phone)) { apiResp.code = (int)APIErrCode.PhoneFormatError; apiResp.msg = "手机格式错误"; bllUser.ContextResponse(context, apiResp); return; } #endregion #region 判断手机是否已被使用 UserInfo model = bllUser.GetUserInfoByPhone(Phone); if (model != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机号码已被其他账号使用,请联系管理员"; bllSms.ContextResponse(context, apiResp); return; } #endregion #region 判断验证码是否正确 SmsVerificationCode sms = bllSms.GetLastSmsVerificationCode(Phone); if (sms == null || sms.VerificationCode != code) { apiResp.code = (int)APIErrCode.CheckCodeErr; apiResp.msg = "验证码错误"; bllSms.ContextResponse(context, apiResp); return; } #endregion List <TableFieldMapping> listFieldList = bllTableFieldMap.GetTableFieldMapByWebsite(bllTableFieldMap.WebsiteOwner, "ZCJ_UserInfo", null, null, "0", null); List <string> defFields = new List <string>() { "AutoID", "UserID", "Password", "UserType", "TrueName", "Phone" }; #region 账号检查 未登录时检查已有账号 CurrentUserInfo = bllUser.GetUserInfoByAllPhone(Phone); if (CurrentUserInfo != null) { List <string> tempFields = new List <string>() { "Phone1", "Phone2", "Phone3" }; List <GetCompleteField.ResultField> resultList = new List <GetCompleteField.ResultField>(); #region 取姓名 TableFieldMapping AcountTrueNameField = listFieldList.FirstOrDefault(p => p.Field.Equals("TrueName")); if (AcountTrueNameField == null) { resultList.Add(new GetCompleteField.ResultField { field = "TrueName", field_name = "姓名", type = "txt", no_null = 1, value = CurrentUserInfo.TrueName, read_only = 0 }); } else { resultList.Add(new GetCompleteField.ResultField { field = "TrueName", field_name = AcountTrueNameField.MappingName, type = "txt", no_null = AcountTrueNameField.FieldIsNull, value = CurrentUserInfo.TrueName, read_only = AcountTrueNameField.IsReadOnly }); } #endregion #region 取手机 if (!string.IsNullOrWhiteSpace(CurrentUserInfo.Phone1)) { TableFieldMapping AcountPhone1Field = listFieldList.FirstOrDefault(p => p.Field.Equals("Phone1")); if (AcountPhone1Field == null) { resultList.Add(new GetCompleteField.ResultField { field = "TrueName", field_name = "手机", type = "txt", no_null = 1, value = CurrentUserInfo.Phone1, read_only = 0 }); } else { resultList.Add(new GetCompleteField.ResultField { field = "TrueName", field_name = AcountPhone1Field.MappingName, type = "txt", no_null = AcountPhone1Field.FieldIsNull, value = CurrentUserInfo.Phone1, read_only = AcountPhone1Field.IsReadOnly }); } } if (!string.IsNullOrWhiteSpace(CurrentUserInfo.Phone2)) { TableFieldMapping AcountPhone2Field = listFieldList.FirstOrDefault(p => p.Field.Equals("Phone2")); if (AcountPhone2Field == null) { resultList.Add(new GetCompleteField.ResultField { field = "Phone2", field_name = "手机", type = "txt", no_null = 1, value = CurrentUserInfo.Phone2, read_only = 0 }); } else { resultList.Add(new GetCompleteField.ResultField { field = "Phone2", field_name = AcountPhone2Field.MappingName, type = "txt", no_null = AcountPhone2Field.FieldIsNull, value = CurrentUserInfo.Phone2, read_only = AcountPhone2Field.IsReadOnly }); } } if (!string.IsNullOrWhiteSpace(CurrentUserInfo.Phone3)) { TableFieldMapping AcountPhone3Field = listFieldList.FirstOrDefault(p => p.Field.Equals("Phone3")); if (AcountPhone3Field == null) { resultList.Add(new GetCompleteField.ResultField { field = "Phone3", field_name = "手机", type = "txt", no_null = 1, value = CurrentUserInfo.Phone3, read_only = 0 }); } else { resultList.Add(new GetCompleteField.ResultField { field = "Phone3", field_name = AcountPhone3Field.MappingName, type = "txt", no_null = AcountPhone3Field.FieldIsNull, value = CurrentUserInfo.Phone3, read_only = AcountPhone3Field.IsReadOnly }); } } #endregion #region 取其他信息 JObject tCurUser = JObject.FromObject(CurrentUserInfo); foreach (var item in listFieldList.Where(p => !defFields.Contains(p.Field) && !tempFields.Contains(p.Field))) { if (tCurUser[item.Field] == null) { continue; } if (string.IsNullOrWhiteSpace(tCurUser[item.Field].ToString())) { continue; } string FieldType = string.IsNullOrWhiteSpace(item.FieldType) ? "txt" : item.FieldType; resultList.Add(new GetCompleteField.ResultField { field = item.Field, field_name = item.MappingName, type = FieldType, no_null = item.FieldIsNull, value = tCurUser[item.Field].ToString(), read_only = item.IsReadOnly }); } #endregion apiResp.code = (int)APIErrCode.HaveHistoryAcount; apiResp.msg = "注册手机已存在账号"; apiResp.result = new { have_acount = true, id = CurrentUserInfo.AutoID, info_list = resultList }; bllSms.ContextResponse(context, apiResp); return; } else { CurrentUserInfo = new UserInfo(); string guidString = Guid.NewGuid().ToString(); CurrentUserInfo.UserID = string.Format("WXUser{0}", guidString); //Guid CurrentUserInfo.Password = guidString.Substring(0, 8); //Guid CurrentUserInfo.WXHeadimgurl = string.Format("http://{0}", context.Request.Url.Authority) + "/img/persion.png"; CurrentUserInfo.WebsiteOwner = bllUser.WebsiteOwner; CurrentUserInfo.UserType = 2; CurrentUserInfo.WXOpenId = wxOpenId; CurrentUserInfo.Regtime = DateTime.Now; CurrentUserInfo.LastLoginDate = DateTime.Now; } #endregion //string oldPhone = CurrentUserInfo.Phone; CurrentUserInfo = bllTableFieldMap.ConvertRequestToModel <UserInfo>(CurrentUserInfo); //if(CurrentUserInfo.IsPhoneVerify == 1) CurrentUserInfo.Phone = oldPhone; #region 默认信息检查 姓名 TableFieldMapping TrueNameField = listFieldList.FirstOrDefault(p => p.Field.Equals("TrueName")); if ((TrueNameField == null || TrueNameField.FieldIsNull == 1) && string.IsNullOrWhiteSpace(CurrentUserInfo.TrueName)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善姓名"; bllTableFieldMap.ContextResponse(context, apiResp); return; } #endregion JObject jtCurUser = JObject.FromObject(CurrentUserInfo); foreach (var item in listFieldList.Where(p => p.FieldIsNull == 1 && !defFields.Contains(p.Field)).OrderBy(p => p.Sort)) { if (jtCurUser[item.Field] == null) { continue; } if (string.IsNullOrWhiteSpace(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善" + item.MappingName; bllTableFieldMap.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(item.FormatValiFunc)) { #region 检查数据格式 //检查数据格式 if (item.FormatValiFunc == "number") { if (!MyRegex.IsNumber(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "phone")//email检查 { if (!MyRegex.PhoneNumLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "email")//email检查 { if (!MyRegex.EmailLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "url") //url检查 { System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址 System.Text.RegularExpressions.Match match = regUrl.Match(jtCurUser[item.Field].ToString()); if (!match.Success) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } #endregion } } CurrentUserInfo.IsPhoneVerify = 1; CompanyWebsite_Config nWebsiteConfig = bllWebSite.GetCompanyWebsiteConfig(); if (nWebsiteConfig.MemberStandard == 2) { if (CurrentUserInfo.AccessLevel < 1) { CurrentUserInfo.AccessLevel = 1; CurrentUserInfo.MemberStartTime = DateTime.Now; } //CurrentUserInfo.MemberApplyStatus = 9; } else if (nWebsiteConfig.MemberStandard == 3) { CurrentUserInfo.MemberApplyStatus = 1; CurrentUserInfo.MemberApplyTime = DateTime.Now; } if (bllUser.Add(CurrentUserInfo)) { apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "提交完成"; context.Session[ZentCloud.Common.SessionKey.UserID] = CurrentUserInfo.UserID; context.Session[ZentCloud.Common.SessionKey.LoginStatu] = 1; //设置登录状态 } else { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; } bllUser.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { string id = context.Request["id"]; string Phone = context.Request["Phone"]; UserInfo CurrentUserInfo = bllUser.GetCurrentUserInfo(); #region 检查是否已登录 if (CurrentUserInfo != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "本功能仅供新用户使用"; bllUser.ContextResponse(context, apiResp); return; } #endregion #region 检查是否微信服务号 if (context.Session["currWXOpenId"] == null) { apiResp.code = (int)APIErrCode.UserIsNotLogin; apiResp.msg = "本功能仅供微信服务号使用"; bllUser.ContextResponse(context, apiResp); return; } #endregion string wxOpenId = context.Session["currWXOpenId"].ToString(); CurrentUserInfo = bllUser.GetUserInfoByOpenId(wxOpenId); if (CurrentUserInfo != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "OpenId已被绑定"; bllUser.ContextResponse(context, apiResp); return; } #region 判断手机格式 if (!MyRegex.PhoneNumLogicJudge(Phone)) { apiResp.code = (int)APIErrCode.PhoneFormatError; apiResp.msg = "手机格式错误"; bllUser.ContextResponse(context, apiResp); return; } #endregion #region 判断手机是否已被使用 UserInfo model = bllUser.GetUserInfoByPhone(Phone); if (model != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机号码已被其他账号使用,请联系管理员"; bllUser.ContextResponse(context, apiResp); return; } #endregion CurrentUserInfo = bllUser.GetUserInfoByAutoID(Convert.ToInt32(id), bllUser.WebsiteOwner); if (CurrentUserInfo == null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "绑定账号未找到"; bllUser.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(CurrentUserInfo.WXOpenId) && CurrentUserInfo.WXOpenId != wxOpenId) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "账号已有其他微信绑定"; bllUser.ContextResponse(context, apiResp); return; } List <string> pmsString = new List <string>(); pmsString.Add(string.Format("Phone='{0}'", Phone)); pmsString.Add(string.Format("WXOpenId='{0}'", wxOpenId)); pmsString.Add(string.Format("IsPhoneVerify='{0}'", 1)); CompanyWebsite_Config nWebsiteConfig = bllWebSite.GetCompanyWebsiteConfig(); if (nWebsiteConfig.MemberStandard == 3) { pmsString.Add(string.Format("MemberApplyStatus='{0}'", 1)); pmsString.Add(string.Format("MemberApplyTime='{0}'", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } else { if (CurrentUserInfo.AccessLevel < 1) { CurrentUserInfo.AccessLevel = 1; CurrentUserInfo.MemberStartTime = DateTime.Now; } pmsString.Add(string.Format("AccessLevel='{0}'", CurrentUserInfo.AccessLevel)); pmsString.Add(string.Format("MemberStartTime='{0}'", CurrentUserInfo.MemberStartTime.ToString("yyyy-MM-dd HH:mm:ss"))); //CurrentUserInfo.MemberApplyStatus = 9; } if (bllUser.Update(new UserInfo(), ZentCloud.Common.MyStringHelper.ListToStr(pmsString, "", ","), string.Format("AutoID={0}", CurrentUserInfo.AutoID.ToString())) > 0) { apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "提交完成"; context.Session[ZentCloud.Common.SessionKey.UserID] = CurrentUserInfo.UserID; context.Session[ZentCloud.Common.SessionKey.LoginStatu] = 1; //设置登录状态 } else { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; } bllUser.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { UserInfo nUser = new UserInfo(); nUser = bllTableFieldMap.ConvertRequestToModel <UserInfo>(nUser); nUser.UserID = string.Format("PCUser{0}", Guid.NewGuid().ToString());//Guid nUser.Password = ZentCloud.Common.Rand.Str_char(12); nUser.UserType = 2; nUser.WebsiteOwner = bllTableFieldMap.WebsiteOwner; nUser.LastLoginDate = DateTime.Now; List <TableFieldMapping> formField = bllTableFieldMap.GetTableFieldMapByWebsite(bllTableFieldMap.WebsiteOwner, "ZCJ_UserInfo", null, null, context.Request["mapping_type"]); formField = formField.Where(p => p.IsReadOnly == 0 && p.IsDelete == 0 && p.Field != "AutoID" && p.Field != "UserID").ToList(); List <string> defFields = new List <string>() { "AutoID", "UserID", "Password", "UserType", "TrueName", "Phone", "WebsiteOwner" }; JObject jtCurUser = JObject.FromObject(nUser); List <JProperty> listPropertys = jtCurUser.Properties().ToList(); foreach (var item in formField.Where(p => p.FieldIsNull == 1 && !defFields.Contains(p.Field)).OrderBy(p => p.Sort)) { if (!listPropertys.Exists(p => p.Name.Equals(item.Field))) { continue; } if (string.IsNullOrWhiteSpace(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善" + item.MappingName; bllTableFieldMap.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(item.FormatValiFunc)) { #region 检查数据格式 //检查数据格式 if (item.FormatValiFunc == "number") { if (!MyRegex.IsNumber(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "phone")//email检查 { if (!MyRegex.PhoneNumLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "email")//email检查 { if (!MyRegex.EmailLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "url") //url检查 { System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址 System.Text.RegularExpressions.Match match = regUrl.Match(jtCurUser[item.Field].ToString()); if (!match.Success) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } #endregion } } if (bllTableFieldMap.Add(nUser)) { if (!string.IsNullOrEmpty(nUser.TagName)) { foreach (var tag in nUser.TagName.Split(',')) { if (bllUser.GetCount <ZentCloud.BLLJIMP.Model.MemberTag>(string.Format(" WebsiteOwner='{0}' And TagName='{1}' And TagType='Member'", bllUser.WebsiteOwner, tag)) == 0) { ZentCloud.BLLJIMP.Model.MemberTag model = new BLLJIMP.Model.MemberTag(); model.CreateTime = DateTime.Now; model.WebsiteOwner = bllUser.WebsiteOwner; model.TagType = "Member"; model.TagName = tag; model.Creator = currentUserInfo.UserID; if (!bllUser.Add(model)) { apiResp.msg = "新增标签失败"; apiResp.code = (int)APIErrCode.OperateFail; bllTableFieldMap.ContextResponse(context, apiResp); } } } } apiResp.status = true; apiResp.msg = "新增完成"; apiResp.code = (int)APIErrCode.IsSuccess; } else { apiResp.msg = "新增失败"; apiResp.code = (int)APIErrCode.OperateFail; } bllTableFieldMap.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { JuActivityInfo ninfo = new JuActivityInfo(); ninfo.WebsiteOwner = bll.WebsiteOwner; ninfo.UserID = currentUserInfo.UserID; ninfo.ArticleType = context.Request["ArticleType"]; #region 字段检查 ArticleCategoryTypeConfig typeConfig = bllArticleCategory.GetArticleCategoryTypeConfig(bllArticleCategory.WebsiteOwner, ninfo.ArticleType); if (typeConfig.TimeSetMethod == 1 || typeConfig.TimeSetMethod == 2) { ninfo.UserLongitude = context.Request["UserLongitude"]; ninfo.UserLatitude = context.Request["UserLatitude"]; } List <TableFieldMapping> listFieldList = bllTableFieldMap.GetTableFieldMapByWebsite(bllTableFieldMap.WebsiteOwner, "ZCJ_JuActivityInfo", ninfo.ArticleType, null, "0", null); List <string> DefFields = new List <string>() { "JuActivityID" }; JObject jtCurUser = JObject.FromObject(ninfo); List <string> listPropertys = jtCurUser.Properties().Select(p => p.Name).ToList(); foreach (var item in listFieldList.Where(p => !DefFields.Contains(p.Field) && listPropertys.Contains(p.Field)).OrderBy(p => p.Sort)) { string nValue = context.Request[item.Field]; if (item.FieldIsNull == 1 && string.IsNullOrWhiteSpace(nValue)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善" + item.MappingName; bllTableFieldMap.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(item.FormatValiFunc)) { #region 检查数据格式 //检查数据格式 if (item.FormatValiFunc == "number") { if (!MyRegex.IsNumber(nValue)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "phone")//email检查 { if (!MyRegex.PhoneNumLogicJudge(nValue)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "email")//email检查 { if (!MyRegex.EmailLogicJudge(nValue)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "url") //url检查 { System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址 System.Text.RegularExpressions.Match match = regUrl.Match(nValue); if (!match.Success) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } #endregion } ninfo = bll.ConvertToModel <JuActivityInfo>(ninfo, item.Field, nValue); } #endregion ninfo.JuActivityID = int.Parse(bll.GetGUID(BLLJIMP.TransacType.AddOutlets)); if (bll.Add(ninfo)) { apiResp.status = true; apiResp.msg = "提交成功"; apiResp.code = (int)APIErrCode.IsSuccess; } else { apiResp.msg = "提交失败"; apiResp.code = (int)APIErrCode.OperateFail; } bll.ContextResponse(context, apiResp); }
public void ProcessRequest(HttpContext context) { string phone = context.Request["phone"]; string smsContent = context.Request["smscontent"]; string check_user = context.Request["check_user"]; string limit_user = context.Request["limit_user"]; #region 判断手机格式 if (!MyRegex.PhoneNumLogicJudge(phone)) { apiResp.code = (int)APIErrCode.PhoneFormatError; apiResp.msg = "手机格式错误"; bllSms.ContextResponse(context, apiResp); return; } #endregion #region 判断手机是否已被使用,且是否是当前账号 if (check_user == "1") { UserInfo model = bllUser.GetUserInfoByPhone(phone); if (limit_user == "1" && model == null) { apiResp.code = (int)APIErrCode.IsNotFound; apiResp.msg = "该手机号没有账号"; bllSms.ContextResponse(context, apiResp); return; } if (limit_user == "2" && model != null) { apiResp.code = (int)APIErrCode.IsNotFound; apiResp.msg = "该手机号已有账号"; bllSms.ContextResponse(context, apiResp); return; } if (model != null) { UserInfo CurrentUserInfo = bllUser.GetCurrentUserInfo(); if (CurrentUserInfo != null && model.UserID != CurrentUserInfo.UserID) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机号码已被其他账号使用,请联系管理员"; bllSms.ContextResponse(context, apiResp); return; } //if (model.IsPhoneVerify == 1) //{ // apiResp.code = (int)APIErrCode.OperateFail; // apiResp.msg = "手机号码已验证"; // bllSms.ContextResponse(context, apiResp); // return; //} } } #endregion var lastSmsVerificationCode = bllSms.GetLastSmsVerificationCode(phone); if (lastSmsVerificationCode != null) { if ((DateTime.Now - lastSmsVerificationCode.InsertDate).TotalSeconds < 60) { apiResp.code = (int)APIErrCode.IsRepeat; apiResp.msg = "验证码限制每60秒发送一次"; bllSms.ContextResponse(context, apiResp); return; } } string verCode = new Random().Next(111111, 999999).ToString(); string smsSignature = string.Format("{0}", bllSms.GetWebsiteInfoModelFromDataBase().SmsSignature);//短信签名 if (string.IsNullOrWhiteSpace(smsContent) || !smsContent.Contains("{{SMSVERCODE}}")) { smsContent = "手机验证码:{{SMSVERCODE}}"; } smsContent = smsContent.Replace("{{SMSVERCODE}}", verCode);//替换验证码标签 string msg = ""; bool isSuccess = false; bllSms.SendSmsVerificationCode(phone, smsContent, smsSignature, verCode, out isSuccess, out msg); if (!isSuccess) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机验证码发送失败"; bllSms.ContextResponse(context, apiResp); return; } apiResp.status = isSuccess; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "手机验证码已发送"; bllSms.ContextResponse(context, apiResp); }
public void ValidasiAngka(object sender, TextCompositionEventArgs e) { MyRegex regex = new MyRegex("[^0-9]+"); e.Handled = regex.IsMatch(e.Text); }
public void ValidasiHuruf(object sender, TextCompositionEventArgs e) { MyRegex regex = new MyRegex("[^a-zA-Z]"); e.Handled = regex.IsMatch(e.Text); }
public void ProcessRequest(HttpContext context) { string code = context.Request["code"]; string Phone = context.Request["Phone"]; string wxOpenId; UserInfo CurrentUserInfo = bllUser.GetCurrentUserInfo(); #region 判断手机格式 if (!MyRegex.PhoneNumLogicJudge(Phone)) { apiResp.code = (int)APIErrCode.PhoneFormatError; apiResp.msg = "手机格式错误"; bllTableFieldMap.ContextResponse(context, apiResp); return; } #endregion #region 判断验证码是否正确 SmsVerificationCode sms = bllSms.GetLastSmsVerificationCode(Phone); if (sms == null || sms.VerificationCode != code) { apiResp.code = (int)APIErrCode.CheckCodeErr; apiResp.msg = "验证码错误"; bllSms.ContextResponse(context, apiResp); return; } #endregion #region 账号检查 未登录时检查已有账号 if (CurrentUserInfo == null) { if (context.Session["currWXOpenId"] == null) { apiResp.code = (int)APIErrCode.UserIsNotLogin; apiResp.msg = "请先登录"; bllSms.ContextResponse(context, apiResp); return; } wxOpenId = context.Session["currWXOpenId"].ToString(); UserInfo curUser = bllUser.GetUserInfoByOpenId(wxOpenId); if (curUser != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "微信已绑定有账号"; bllSms.ContextResponse(context, apiResp); return; } curUser = bllUser.GetUserInfoByAllPhone(Phone); if (curUser != null) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "微信已绑定有账号"; bllSms.ContextResponse(context, apiResp); return; } } #endregion #region 判断手机是否已被使用 UserInfo model = bllUser.GetUserInfoByPhone(Phone); if (model != null) { if (model.UserID != CurrentUserInfo.UserID) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "手机号码已被其他账号使用,请联系管理员"; bllSms.ContextResponse(context, apiResp); return; } } #endregion //string oldPhone = CurrentUserInfo.Phone; CurrentUserInfo = bllTableFieldMap.ConvertRequestToModel <UserInfo>(CurrentUserInfo); //if(CurrentUserInfo.IsPhoneVerify == 1) CurrentUserInfo.Phone = oldPhone; List <TableFieldMapping> listFieldList = bllTableFieldMap.GetTableFieldMapByTableName(bllTableFieldMap.WebsiteOwner, "ZCJ_UserInfo"); List <string> DefFields = new List <string>() { "AutoID", "UserID", "Password", "UserType", "TrueName", "Phone" }; #region 默认信息检查 姓名 TableFieldMapping TrueNameField = listFieldList.FirstOrDefault(p => p.Field.Equals("TrueName")); if ((TrueNameField == null || TrueNameField.FieldIsNull == 1) && string.IsNullOrWhiteSpace(CurrentUserInfo.TrueName)) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善姓名"; bllTableFieldMap.ContextResponse(context, apiResp); return; } #endregion JObject jtCurUser = JObject.FromObject(CurrentUserInfo); List <JProperty> listPropertys = jtCurUser.Properties().ToList(); foreach (var item in listFieldList.Where(p => p.FieldIsNull == 1 && !DefFields.Contains(p.Field)).OrderBy(p => p.Sort)) { if (!listPropertys.Exists(p => p.Name.Equals(item.Field))) { continue; } if (string.IsNullOrWhiteSpace(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "请完善" + item.MappingName; bllTableFieldMap.ContextResponse(context, apiResp); return; } if (!string.IsNullOrWhiteSpace(item.FormatValiFunc)) { #region 检查数据格式 //检查数据格式 if (item.FormatValiFunc == "number") { if (!MyRegex.IsNumber(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "phone")//email检查 { if (!MyRegex.PhoneNumLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "email")//email检查 { if (!MyRegex.EmailLogicJudge(jtCurUser[item.Field].ToString())) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } if (item.FormatValiFunc == "url") //url检查 { System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址 System.Text.RegularExpressions.Match match = regUrl.Match(jtCurUser[item.Field].ToString()); if (!match.Success) { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = string.Format("{0}格式不正确", item.MappingName); bllTableFieldMap.ContextResponse(context, apiResp); return; } } #endregion } } CurrentUserInfo.IsPhoneVerify = 1; CompanyWebsite_Config nWebsiteConfig = bllWebSite.GetCompanyWebsiteConfig(); if (nWebsiteConfig.MemberStandard == 2) { if (CurrentUserInfo.AccessLevel < 1) { CurrentUserInfo.AccessLevel = 1; CurrentUserInfo.MemberStartTime = DateTime.Now; } //CurrentUserInfo.MemberApplyStatus = 9; } else if (nWebsiteConfig.MemberStandard == 3) { CurrentUserInfo.MemberApplyStatus = 1; CurrentUserInfo.MemberApplyTime = DateTime.Now; } if (bllUser.Update(CurrentUserInfo)) { apiResp.status = true; apiResp.code = (int)APIErrCode.IsSuccess; apiResp.msg = "提交完成"; } else { apiResp.code = (int)APIErrCode.OperateFail; apiResp.msg = "提交失败"; } bllUser.ContextResponse(context, apiResp); }