Exemple #1
0
        public void testReplaceHtml()
        {
            String html = @"<p>
  Hello. <font size=""2"">I am size 2</font>
  <font color=""red"">and I am red</font>
</p>";

            String result = @"<p>
  Hello. I am size 2
  and I am red
</p>";

            Assert.AreEqual(result, RegPattern.ReplaceHtml(html, "font", false));

            html   = @"<p><span style=""color:red;"">kkk</span> aaaaaaaa</p>";
            result = @"<p>kkk aaaaaaaa</p>";
            Assert.AreEqual(result, RegPattern.ReplaceHtml(html, "span", false));

            html   = @"<p>zzz <a href=""ccc.html"">aaa name</a> pppp</p>";
            result = @"<p>zzz aaa name pppp</p>";
            Assert.AreEqual(result, RegPattern.ReplaceHtml(html, "a", false));


            //---------------------------------------------------------------------------------------------



            html = @"<p>
<script>         alert('sss');       </script>
<style>
p {color:red;}
</style>
  Hello. <font size=""2"">I am size 2</font>
  <font color=""red"">and I am red</font>
</p>";

            result = @"<p>


  Hello. <font size=""2"">I am size 2</font>
  <font color=""red"">and I am red</font>
</p>";

            String x = RegPattern.ReplaceHtml(html, "script", true);

            x = RegPattern.ReplaceHtml(x, "style", true);

            Assert.AreEqual(result, x);

            html   = @" <p>  pic1 <img src=""eeeeeeee.jpg"" />   </p>  pic2<IMG src=""xxxxxx.gif"" >  ";
            result = @" <p>  pic1    </p>  pic2  ";
            x      = RegPattern.ReplaceHtml(html, "img", true);
            Assert.AreEqual(result, x);


            html   = @" <p>  pic1 <br/>    </p>  pic2<BR> <div><br   /></div> <br /> ";
            result = @" <p>  pic1     </p>  pic2 <div></div>  ";
            x      = RegPattern.ReplaceHtml(html, "br", true);
            Assert.AreEqual(result, x);
        }
        public void CreateEmail()
        {
            User user = ctx.owner.obj as User;

            if (strUtil.HasText(user.Email))
            {
                echoError("已有email,无法创建");
                return;
            }

            String email = strUtil.CutString(ctx.Post("Email"), 30);

            if (strUtil.IsNullOrEmpty(email))
            {
                errors.Add(lang("exEmail"));
            }
            else if (RegPattern.IsMatch(email, RegPattern.Email) == false)
            {
                errors.Add(lang("exUserMail"));
            }
            else if (userService.IsEmailExist(email))
            {
                errors.Add(lang("exEmailFound"));
            }

            if (ctx.HasErrors)
            {
                echoError(); return;
            }

            Result result = userService.CreateEmail(user, email);

            echoResult(result);
        }
Exemple #3
0
        public void testUrl()
        {
            Assert.IsTrue(RegPattern.IsMatch("http://www.163.com", RegPattern.Url));
            Assert.IsTrue(RegPattern.IsMatch("http://163.com", RegPattern.Url));
            Assert.IsTrue(RegPattern.IsMatch("http://www.sohu.com", RegPattern.Url));
            Assert.IsTrue(RegPattern.IsMatch("http://sohu.com", RegPattern.Url));
            Assert.IsTrue(RegPattern.IsMatch("http://www.sina.com.cn", RegPattern.Url));
            Assert.IsTrue(RegPattern.IsMatch("http://sina.com.cn", RegPattern.Url));


            Assert.IsFalse(RegPattern.IsMatch("天气预报", RegPattern.Url));
            Assert.IsFalse(RegPattern.IsMatch("http://天气预报", RegPattern.Url));
            Assert.IsFalse(RegPattern.IsMatch("abc", RegPattern.Url));
            //Assert.IsFalse( RegPattern.IsMatch( "http://abc", RegPattern.Url ) );
        }
Exemple #4
0
        public virtual void UpdateEmail(long id)
        {
            String userEmail = strUtil.SubString(ctx.Post("userEmail"), RegPattern.EmailLength);

            if (strUtil.IsNullOrEmpty(userEmail) || RegPattern.IsMatch(userEmail, RegPattern.Email) == false)
            {
                echoError(lang("exUserMail"));
                return;
            }

            User m = User.findById(id);

            m.Email = userEmail;
            m.update();
            echoToParentPart(lang("opok"));
        }
Exemple #5
0
        private string filterPage(string input, SpiderTemplate spiderTemplate)
        {
            if (strUtil.IsNullOrEmpty(spiderTemplate.DetailClearTag))
            {
                return(input);
            }

            String[] arrTag = spiderTemplate.DetailClearTag.ToLower().Split(',');
            if (arrTag.Length == 0)
            {
                return(input);
            }

            List <String> rTag = new List <String>();

            logger.Info("filterTag, input=" + input);

            // 过滤标签,以及标签内部的内容
            foreach (String tag in arrTag)
            {
                // font/span/a 只过滤tag,不过滤内容;其他都过滤内容
                if (tag == "font" || tag == "span" || tag == "a")
                {
                    rTag.Add(tag);
                    continue;
                }

                logger.Info("tag=" + tag);

                input = RegPattern.ReplaceHtml(input, tag, true);
            }

            logger.Info("filterTag, clear tag1=" + input);


            // 只过滤标签,不过滤标签的内容
            foreach (String tag in rTag)
            {
                logger.Info("tag=" + tag);
                input = RegPattern.ReplaceHtml(input, tag, false);
            }

            logger.Info("filterTag, clear tag2=" + input);


            return(input);
        }
        public void SaveEmail()
        {
            String pwd   = ctx.Post("Pwd");
            String email = strUtil.CutString(ctx.Post("Email"), 30);

            User user = ctx.owner.obj as User;

            if (strUtil.IsNullOrEmpty(pwd))
            {
                errors.Add("请填写密码");
            }
            else if (strUtil.IsNullOrEmpty(email))
            {
                errors.Add(lang("exEmail"));
            }
            else if (RegPattern.IsMatch(email, RegPattern.Email) == false)
            {
                errors.Add(lang("exUserMail"));
            }
            else if (userService.IsPwdCorrect(user, pwd) == false)
            {
                errors.Add(lang("exPwdError"));
            }
            else if (userService.IsEmailExist(email))
            {
                errors.Add(lang("exEmailFound"));
            }

            if (ctx.HasErrors)
            {
                echoError(); return;
            }

            userService.UpdateEmailAndResetConfirmStatus(user, email);

            if (config.Instance.Site.EnableEmail)
            {
                echoToParent(lang("opok"), to(new Common.ActivationController().SendEmailButton));
            }
            else
            {
                echoToParentPart(lang("opok"));
            }
        }
Exemple #7
0
        public void SendMail()
        {
            String EmailList = ctx.Post("EmailList");

            if (strUtil.IsNullOrEmpty(EmailList))
            {
                echoError("请填写email");
                return;
            }

            String[]      arrMail = EmailList.Split(new char[] { ',', ',' });
            List <String> list    = new List <string>();

            foreach (String mailStr in arrMail)
            {
                if (strUtil.IsNullOrEmpty(mailStr))
                {
                    continue;
                }
                String mail = strUtil.SubString(mailStr.Trim(), RegPattern.EmailLength);
                if (RegPattern.IsMatch(mail, RegPattern.Email))
                {
                    list.Add(mail);
                }
            }



            String myWords = strUtil.CutString(ctx.Post("myWords"), 200);

            User   user       = ctx.owner.obj as User;
            String inviteLink = getInviteLink(user);

            ctx.SetItem("inviteLink", inviteLink);
            String mailBody = loadHtml(MailBody);

            mailBody = mailBody.Replace("<div id=\"myWordsPreview\"></div>", "<div id=\"myWordsPreview\">" + myWords + "</div>");

            inviteService.AddMail(user, list, mailBody);

            echoRedirect(lang("opok"), Index);
        }
        public void SaveEmail()
        {
            String pwd   = ctx.Post("Pwd");
            String email = strUtil.CutString(ctx.Post("Email"), 30);

            User user = ctx.owner.obj as User;

            if (strUtil.IsNullOrEmpty(pwd))
            {
                errors.Add("请填写密码");
            }
            else if (strUtil.IsNullOrEmpty(email))
            {
                errors.Add(lang("exEmail"));
            }
            else if (RegPattern.IsMatch(email, RegPattern.Email) == false)
            {
                errors.Add(lang("exUserMail"));
            }
            else if (userService.IsPwdCorrect(user, pwd) == false)
            {
                errors.Add(lang("exPwdError"));
            }
            else if (userService.IsEmailExist(email))
            {
                errors.Add(lang("exEmailFound"));
            }

            if (ctx.HasErrors)
            {
                echoError(); return;
            }

            userService.UpdateEmail(user, email);

            echoToParentPart(lang("opok"));
        }
Exemple #9
0
        public void SaveShare()
        {
            String shareLink        = ctx.Post("shareLink");
            String shareDescription = ctx.Post("shareDescription");

            if (strUtil.IsNullOrEmpty(shareLink))
            {
                errors.Add(lang("exUrl"));
            }
            else if (RegPattern.IsMatch(shareLink, RegPattern.Url) == false)
            {
                errors.Add(lang("exUrlFormat"));
            }

            if (errors.HasErrors)
            {
                echoError();
                return;
            }


            Result result = shareService.CreateUrl((User)ctx.viewer.obj, shareLink, shareDescription);

            if (result.HasErrors)
            {
                echoError(result);
            }
            else
            {
                Share share = result.Info as Share;
                feedService.publishUserAction(share);

                String url = to(Index, ctx.viewer.Id);
                echoRedirect(lang("opok"), url);
            }
        }
        private string CalcAtomStr(string Function, List <string> Prev, List <string> Curr, List <string> Next)
        {
            string ResultStr = Function;

            if (RegPattern.IsMatch(Function))
            {
                MatchCollection mcs = RegPattern.Matches(Function);
                for (int i = 0; i < mcs.Count; i++)
                {
                    Match         m      = mcs[i];
                    string        key    = m.Groups[1].Value.ToLower();
                    string        val    = m.Groups[2].Value.Trim();
                    List <string> CurMap = new List <string>();
                    string        KeyIn  = Curr[0] + "[]";
                    switch (key)
                    {
                    case "currentnote": CurMap = Curr; KeyIn = CurMap.Count == 0 ? "" : Function.ToLower().Replace("currentnote", CurMap[0]); break;

                    case "prevnote": CurMap = Prev; KeyIn = CurMap.Count == 0 ? "" : Function.ToLower().Replace("prevnote", CurMap[0]); break;

                    case "nextnote": CurMap = Next; KeyIn = CurMap.Count == 0 ? "" : Function.ToLower().Replace("nextnote", CurMap[0]); break;

                    default: continue;
                    }
                    string KeyAtom = "";
                    // if (KeyIn == "") return "";
                    if (KeyIn != "")
                    {
                        if (KeyValueCache.ContainsKey(KeyIn))
                        {
                            KeyAtom = KeyValueCache[KeyIn];
                        }
                        else
                        {
                            int idx = 0;
                            if (val != "")
                            {
                                val = val.Replace("n", (CurMap.Count - 1).ToString());
                                try
                                {
                                    idx = (int)Calcer.Compute(val, "");
                                }
                                catch {; }
                            }
                            if (idx < CurMap.Count)
                            {
                                KeyAtom = CurMap[idx];
                                try
                                {
                                    KeyValueCache.Add(KeyIn, KeyAtom);
                                }
                                catch {; }
                            }
                        }
                    }
                    ResultStr = ResultStr.Replace(m.Groups[0].Value, KeyAtom);
                }
                return(ResultStr);
            }
            else
            {
                return("");
            }
        }
Exemple #11
0
        public User validateUser()
        {
            if (config.Instance.Site.RegisterNeedImgValidateion)
            {
                Html.Captcha.CheckError(ctx);
            }

            String name    = ctx.Post("Name");
            String pwd     = ctx.Post("Password1");
            String pageUrl = ctx.Post("FriendUrl");
            String email   = ctx.Post("Email");


            if (strUtil.IsNullOrEmpty(name))
            {
                errors.Add(lang("exUserName"));
            }
            else if (name.Length < config.Instance.Site.UserNameLengthMin)
            {
                errors.Add(string.Format(lang("exUserNameLength"), config.Instance.Site.UserNameLengthMin));
            }
            else
            {
                name = strUtil.SubString(name, config.Instance.Site.UserNameLengthMax);
            }
            if (strUtil.IsAbcNumberAndChineseLetter(name) == false)
            {
                errors.Add(lang("exUserNameError"));
            }


            if (strUtil.IsNullOrEmpty(pwd))
            {
                errors.Add(lang("exPwd"));
            }
            else
            {
                pwd = strUtil.CutString(pwd, 20);
            }


            if (Component.IsEnableUserSpace())
            {
                if (strUtil.IsNullOrEmpty(pageUrl))
                {
                    errors.Add(lang("exUrl"));
                }
                else if (pageUrl.IndexOf("http:") >= 0)
                {
                    errors.Add(lang("exUserUrlHttpError"));
                }
                else
                {
                    pageUrl = strUtil.SubString(pageUrl, config.Instance.Site.UserNameLengthMax);
                    pageUrl = pageUrl.ToLower();
                }

                if (strUtil.IsUrlItem(pageUrl) == false)
                {
                    errors.Add(lang("exUserUrlError"));
                }
            }

            if (strUtil.IsNullOrEmpty(email))
            {
                errors.Add(lang("exEmail"));
            }
            else
            {
                if (RegPattern.IsMatch(email, RegPattern.Email) == false)
                {
                    errors.Add(lang("exUserMail"));
                }
            }

            User user = new User();

            user.Name   = name;
            user.Pwd    = pwd;
            user.Url    = pageUrl;
            user.Email  = email;
            user.Gender = ctx.PostInt("Gender");
            return(user);
        }
        public virtual void SendEmail()
        {
            if (hasActivation())
            {
                echoError("您已经激活");
                return;
            }

            long userId = ctx.viewer.Id;

            if (userId <= 0)
            {
                redirect(SendEmailLogin);
                return;
            }

            User user = userService.GetById(userId);

            if (user == null)
            {
                echoError("用户不存在");
                return;
            }

            // 检查5分钟之内只能重发一次
            // TODO 配置5分钟
            Result result = confirmService.CanSend(user);

            if (result.HasErrors)
            {
                echoError(result);
                return;
            }


            String email = strUtil.SubString(ctx.Post("Email"), RegPattern.EmailLength);

            if (strUtil.IsNullOrEmpty(email))
            {
                echoError("请填写email");
                return;
            }

            if (RegPattern.IsMatch(email, RegPattern.Email) == false)
            {
                echoError("email格式不正确");
                return;
            }

            if (userService.IsEmailExist(userId, email))
            {
                echoError(lang("exEmailFound"));
                return;
            }


            if (email.Equals(user.Email) == false)
            {
                user.Email = email;
                user.update();
            }

            confirmEmail.SendEmail(user, null, null);

            redirectUrl(to(SendEmailDone) + "?email=" + email);
        }
        protected IMenu validateMenu(IMenu menu)
        {
            menu.Name  = ctx.Post("Name");
            menu.Url   = ctx.Post("Url");
            menu.Style = getMenuStyle(ctx);
            String rawUrl = ctx.Post("RawUrl");

            if (strUtil.IsNullOrEmpty(menu.Name))
            {
                errors.Add(lang("exName"));
            }
            if (strUtil.IsNullOrEmpty(rawUrl))
            {
                errors.Add(lang("exUrl"));
            }

            Boolean isUrl = RegPattern.IsMatch(rawUrl, RegPattern.Url);

            if (!isUrl)
            {
                errors.Add(lang("exUrlFormat"));
            }

            if (ctx.HasErrors)
            {
                return(null);
            }


            Boolean isOutUrl = PathHelper.IsOutUrl(rawUrl);

            logger.Info("isOutUrl=" + isOutUrl);

            if (isOutUrl)
            {
                menu.RawUrl = rawUrl;
                menu.Url    = "";
            }
            else
            {
                IMember owner      = ctx.owner.obj;
                String  cleanedUrl = UrlConverter.clearUrl(rawUrl, ctx, owner.GetType().FullName, owner.Url);
                logger.Info("cleanedUrl=" + cleanedUrl);
                menu.RawUrl = cleanedUrl;
            }

            menu.OpenNewWindow = ctx.PostIsCheck("chkBlank");

            if (strUtil.IsNullOrEmpty(menu.Name))
            {
                errors.Add(lang("exName"));
            }
            if (strUtil.IsNullOrEmpty(menu.RawUrl))
            {
                errors.Add(lang("exUrl"));
            }
            if (strUtil.HasText(menu.Url) && strUtil.IsUrlItem(menu.Url) == false)
            {
                errors.Add(lang("exFriendUrlFormat"));
            }

            return(menu);
        }