Example #1
0
        /// <summary>
        /// 加载信息
        /// </summary>
        protected void LoadInfo()
        {
            ddl_Class.DataSource     = NewsAction.NewsClass.Where(p => p.IsLeafClass && p.ModelID == 3);
            ddl_Class.DataTextField  = "ClassName";
            ddl_Class.DataValueField = "ID";
            ddl_Class.DataBind();

            ddl_Class.SelectedValue = cls.ToS();

            ddl_Author.DataSource     = UserView.GetModelList();
            ddl_Author.DataTextField  = "UserName";
            ddl_Author.DataValueField = "ID";
            ddl_Author.DataBind();

            Question qu = QuestionView.GetModelByID(id.ToS());


            if (id > 0)
            {
                ddl_Class.SelectedValue = qu.ClassID.ToS();
                txt_Title.Text          = qu.Title;
                //ddl_Author.Text = qu.UserID.ToS();
                ddl_Author.SelectedValue = qu.UserID.ToS();
                txt_ClickCount.Text      = qu.ClickCount.ToS();
                txt_Content.Text         = qu.Content;

                rp_list.DataSource = AnswerView.GetModelList(string.Format("QuestionID={0} order by id", qu.ID));
                rp_list.DataBind();
            }
        }
Example #2
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Result UserRegister(User user)
        {
            SysSetting setting = BasePage.SystemSetting;

            Result r = new Result();

            if (!setting.EnableReg)//不允许注册
            {
                r.Success = false;
                r.Text    = "系统关闭了用户注册功能!";
                return(r);
            }

            if (UserView.Exist(string.Format("UserName='******'", user.UserName)))
            {
                r.Success = false;
                r.Text    = "这个账号已经存在,请重新选择!";
                return(r);
            }

            if (user.UserName.Length > setting.MaxUserName || user.UserName.Length < setting.MinUserName)
            {
                r.Success = false;
                r.Text    = string.Format("账号长度请设置在{0}和{1}之间", setting.MinUserName, setting.MaxUserName);
                return(r);
            }

            //密码经过MD5加密后无法验证长度

            //系统保留词
            string[] userNameFilter = setting.UserNameFilter.Trim().Split(',');
            foreach (string k in userNameFilter)
            {
                if (user.UserName.Contains(k))
                {
                    r.Success = false;
                    r.Text    = "账号中存在系统保留词,请重新设置";
                    return(r);
                }
            }

            if (setting.EmailCheck)
            {
                if (UserView.Exist(string.Format("Email='{0}'", user.Email)))
                {
                    r.Success = false;
                    r.Text    = "您设置的邮箱账号已经在系统中注册,系统不允许重复注册";
                    return(r);
                }
            }

            //用户默认分组
            if (user.Group <= 0)
            {
                user.Group = setting.RegisterDefaultGroup;
            }

            UserGroup g = UserGroupView.GetModelByID(user.Group.ToS());

            user.Enable = g.RegAutoAudit;

            //注册时间间隔
            user.RegIP = WS.GetIP();
            var ipusers = UserView.GetModelList(string.Format("RegIP='{0}'", user.RegIP)).OrderByDescending(p => p.RegTime);

            if (ipusers.Count() > 0)
            {
                User _lastUser = ipusers.First();

                if (_lastUser != null && (DateTime.Now - _lastUser.RegTime).TotalMinutes < Convert.ToDouble(setting.RegTimeSpan.ToDecimal()))
                {
                    r.Success = false;
                    r.Text    = "您的注册动作过于频繁,请稍后重试!";
                    return(r);
                }
            }
            user.RegTime       = DateTime.Now;
            user.Cent          = setting.RegCent;
            user.LastLoginIP   = WS.GetIP();
            user.LastLoginTime = DateTime.Now;

            UserView.Insert(user);
            r.Success = true;
            r.Text    = "注册成功!";
            return(r);
        }