Example #1
0
        /// <summary>
        /// 判断参数Admin是否符合数据库规范,创建用户时的数据合法性检验
        /// </summary>
        /// <param name="admin">要检查的Admin对象</param>
        /// <returns>合法返回true,否则返回false</returns>
        public static Boolean isLegalNewAdmin(Admin admin)
        {
            Boolean result = true;
            //账号合法性检验
            if (admin.User_account.Length > 64 //长于64不行
                || admin.User_account.Length < 5 //比5短也不行
                || admin.User_account == null //null不行
                || admin.User_account.Equals("") //isNotOrEmpty
                )
                result = false;

            //密码合法性检验
            if (admin.User_password.Length != 32 //长度不是32不行
                || admin.User_password.Equals("") //为空不行
                || admin.User_password == null) //是null也不行
                result = false;

            //登录日期检验
            if (admin.User_last_login_date == null) //为空不行
                result = false;
            //最后登录ip检验
            if (admin.User_last_login_ip == null //为空不行
                || admin.User_last_login_ip.Length < 8 //不能比8位短
                || admin.User_last_login_ip.Length > 64 //不能比64位长
                || admin.User_last_login_ip.Equals("") //为空不行
                )
                result = false;
            //时间戳不做校验
            return result;
        }
Example #2
0
 /// <summary>
 /// 管理员登录用函数,成功则返回对应的Admin对象,否则返回null
 /// </summary>
 /// <param name="admin">要验证的Admin对象</param>
 /// <returns>成功返回Admin的详细信息,否则返回null</returns>
 public static Admin isLegalLogin(Admin admin)
 {
     Admin result = null;
     if (isLegalLoginInfo(admin))
     {
         AdminData adminData = AdminData.GetNewInstance();
         result = adminData.GetAdminByAccountAndPassword(admin);
     }
     return result;
 }
Example #3
0
 /// <summary>
 /// 将ADMIN类转换为Admin类,a_id在这里没管,因为无意义。
 /// </summary>
 /// <param name="admin">要转换的ADMIN类对象</param>
 /// <returns>等价的Admin对象</returns>
 public Admin ConvertADMINToAdmin(ADMIN admin)
 {
     Admin result = new Admin();
     result.User_id = admin.admin_id;
     result.User_account = admin.admin_account;
     result.User_password = admin.admin_password;
     result.User_last_login_date = admin.admin_last_login_time;
     result.User_last_login_ip = admin.admin_last_login_ip;
     result.User_nickname = admin.admin_nickname;
     result.User_timestamp = admin.admin_timestamp;
     return result;
 }
Example #4
0
 /// <summary>
 /// 将ADMIN对象转换为Admin对象,a_id这里没管因为没意义
 /// </summary>
 /// <param name="admin">要转换的Admin对象</param>
 /// <returns>转换后的ADMIN对象</returns>
 public ADMIN ConvertAdminToADMIN(Admin admin)
 {
     /*数据库里就这5个*/
     ADMIN result = new ADMIN();
     result.admin_id = admin.User_id;
     result.admin_account = admin.User_account;
     result.admin_password = admin.User_password;
     result.admin_last_login_time = admin.User_last_login_date;
     result.admin_last_login_ip = admin.User_last_login_ip;
     result.admin_nickname = admin.User_nickname;
     result.admin_timestamp = admin.User_timestamp;
     return result;
 }
Example #5
0
 /// <summary>
 /// 发布新闻
 /// </summary>
 /// <param name="news">要发布的新闻类</param>
 /// <param name="author">作者</param>
 /// <returns>成功返回true,失败返回false</returns>
 public static Boolean CreateNews(News news, Admin author)
 {
     Boolean result = true;
     if ( !isLegalNews(news) || !AdminOpr.isLegalNewAdmin(author) )
     {
         //数据合法性检查未通过
         result = false;
     }
     else
     {
         news.Article_author = author.User_id;
         NewsData newsData  = NewsData.GetInstance();
         result = newsData.CreateNews(news);
     }
     return result;
 }
Example #6
0
 public Admin(Admin admin)
 {
     //因为隐式调用的时候,调用的永远都是父类的【无参】构造函数,所以可以这么玩儿。
     this.u_id = admin.U_id;
     this.user_id = admin.User_id;
     this.user_account = admin.User_account;
     this.user_password = admin.User_password;
     this.user_nickname = admin.User_nickname;
     this.user_sex = admin.User_sex;
     this.user_head = admin.User_head;
     this.user_isDeleted = admin.User_isDeleted;
     this.user_isChecked = admin.User_isChecked;
     this.user_last_login_date = admin.User_last_login_date;
     this.user_last_login_ip = admin.User_last_login_ip;
     this.user_timestamp = admin.User_timestamp;
 }
Example #7
0
 /// <summary>
 /// 根据账号密码获得数据库中的admin实例
 /// </summary>
 /// <param name="admin">要查找的Admin对象</param>
 /// <returns>成功返回Admin对象,未找到或失败返回null</returns>
 public Admin GetAdminByAccountAndPassword(Admin admin)
 {
     Admin result = null;
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     try
     {
     ADMIN result_admin = (from usr in DataEntity.ADMIN
                          where usr.admin_account == admin.User_account
                          && usr.admin_password == admin.User_password
                               select usr).Single();
         result = ConvertADMINToAdmin(result_admin);
     }
     catch
     {
         result = null;
     }
     return result;
 }
Example #8
0
        /// <summary>
        /// 判断参数admin是否符合登录的数据要求,数据验证用数据合法性检验函数
        /// </summary>
        /// <param name="admin">待验证Admin对象</param>
        /// <returns>符合要求返回true,否则返回false</returns>
        public static Boolean isLegalLoginInfo(Admin admin)
        {
            Boolean result = true;
            //账号合法性检验
            if (admin.User_account.Length > 64 //长于64不行
                || admin.User_account.Length < 5 //比5短也不行
                || admin.User_account == null //null不行
                || admin.User_account.Equals("") //isNotOrEmpty
                )
                result = false;

            //密码合法性检验
            if (admin.User_password.Length != 32 //长度不是32不行
                || admin.User_password.Equals("") //为空不行
                || admin.User_password == null) //是null也不行
                result = false;
            return result;
        }
Example #9
0
        /// <summary>
        /// 更新管理员信息,由BLL层调用,成功返回true,失败返回fales;
        /// </summary>
        /// <param name="admin">要更新的管理员Admin实例</param>
        /// <returns>成功返回true,失败返回false</returns>
        public Boolean UpdateAdminInfo(Admin admin)
        {
            Boolean result = false;
            avfunEntities DataEntity = DataEntityManager.GetDataEntity();
            try
            {
                ADMIN destAdmin = ( from usr in DataEntity.ADMIN
                                    where usr.admin_id == admin.User_id
                                    && usr.admin_timestamp == admin.User_timestamp
                                    select usr).Single();
                //全套更新
                destAdmin.admin_id = admin.User_id;
                destAdmin.admin_account = admin.User_account;
                destAdmin.admin_password = admin.User_password;
                destAdmin.admin_last_login_time = admin.User_last_login_date;
                destAdmin.admin_last_login_ip = admin.User_last_login_ip;
                destAdmin.admin_nickname = admin.User_nickname;

                DataEntity.SaveChanges();
                result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }
Example #10
0
 /// <summary>
 /// 根据参数中的user_id返回给定Admin的信息
 /// </summary>
 /// <param name="admin">要查找的Admin实例,user_id必填</param>
 /// <returns>成功返回Admin类,失败返回null</returns>
 public static Admin GetAdminByID(Admin admin)
 {
     Admin result = null;
     return result;
 }
Example #11
0
 /// <summary>
 /// 更新管理员信息,成功返回true失败返回false
 /// </summary>
 /// <param name="admin">要更新的管理员</param>
 /// <returns>成功true失败false</returns>
 public static Boolean UpdateAdminInfo(Admin admin)
 {
     Boolean result = false;
     if (isLegalNewAdmin(admin))
     {
         //数据完整性检查通过
         AdminData adminData = AdminData.GetNewInstance();
         result = adminData.UpdateAdminInfo(admin);
     }
     return result;
 }
Example #12
0
        /// <summary>
        /// 根据Request判断管理员是否登录,主要看Cookie,若登录了返回完整Admin对象
        /// </summary>
        /// <param name="httpRequest">需要判断的httpRequest</param>
        /// <returns>若已登录返回完整Admin对象,否则返回null</returns>
        public static Admin isLogged(HttpRequest httpRequest)
        {
            //构造登录用类
            Admin loginAdmin = new Admin();
            Admin result = null;
            if (httpRequest.Cookies["adminAccount"] == null
                || httpRequest.Cookies["adminPassword"] == null
                || httpRequest.Cookies["adminAccount"].Value.Length > 64
                || httpRequest.Cookies["adminPassword"].Value.Length != 32
                )
                return null;
            else
            {
                loginAdmin.User_account = httpRequest.Cookies["adminAccount"].Value;
                loginAdmin.User_password = httpRequest.Cookies["adminPassword"].Value;

                //登录,返回结果
                if (isLegalLoginInfo(loginAdmin))
                {
                    result = isLegalLogin(loginAdmin);
                }
            }
            return result;
        }
Example #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin loggedAdmin = AdminOpr.isLogged(Request); //获取信息

            if (!Page.IsPostBack)
            {
                //第一次显示
                if (loggedAdmin != null) //已经登录
                {
                    //如果已经登录
                    AdminLoginForm.Visible = false; //不显示登录页面
                    AdminLoginStatus.Text = "欢迎回来!尊敬的管理员" + loggedAdmin.User_nickname + ",3秒后自动为您转入管理员首页";
                    AdminLoginStatus.Visible = true;
                    //重定向
                    HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
                    RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
                    RedirectMeta.Content = "3;url=admin_index.aspx"; //时间为三秒,跳转到首页
                    this.Page.Header.Controls.Add(RedirectMeta);
                }
                else //没登录
                {
                    AdminLoginForm.Visible = true;
                    AdminLoginStatus.Visible = false; //隐藏指示信息
                }
            }
            else
            {
                //提交回来了登录信息
                String AdminLoginVerifyCode = Request.Form["txtAdminVerifyCode"];
                String adminAccount = Request.Form["txtAdminAccount"];
                String adminPassword = Request.Form["txtAdminPassword"];
                if (Session[AdminLoginVerifyCodeGenerator.strIdentify] != null &&
                     !Session[AdminLoginVerifyCodeGenerator.strIdentify].ToString().Equals("") && //notNullAndEmpty
                     AdminLoginVerifyCode != null &&
                    !AdminLoginVerifyCode.Equals(""))
                {
                    //清空Session防止后退提交
                    Session.Remove(AdminLoginVerifyCodeGenerator.strIdentify);

                    //验证码校验通过
                    Admin loginAdmin = new Admin();
                    loginAdmin.User_account = adminAccount;
                    loginAdmin.User_password = UserOpr.MD5(adminPassword);
                    Admin entireAdmin = AdminOpr.isLegalLogin(loginAdmin);
                    if (entireAdmin != null )
                    {
                        //合法登录请求
                        entireAdmin.User_last_login_date = DateTime.Now; //登录时间
                        entireAdmin.User_last_login_ip = HttpContext.Current.Request.UserHostAddress; //登录ip
                        AdminOpr.UpdateAdminInfo(entireAdmin); //更新登录ip和时间
                        //分配cookies
                        HttpCookie adminAccountCookie = new HttpCookie("adminAccount");
                        HttpCookie adminPasswordCookie = new HttpCookie("adminPassword");
                        adminAccountCookie.Value = entireAdmin.User_account;
                        adminPasswordCookie.Value = entireAdmin.User_password;
                        adminAccountCookie.Expires = DateTime.Now.AddDays(1D); // 1天过期
                        adminPasswordCookie.Expires = DateTime.Now.AddDays(1D); //1天过期
                        //添加Cookie,相当于授权
                        Response.Cookies.Add(adminAccountCookie);
                        Response.Cookies.Add(adminPasswordCookie);

                        //UI操作
                        AdminLoginForm.Visible = false; //不显示登录页面
                        AdminLoginStatus.Text = "欢迎回来!尊敬的管理员" + entireAdmin.User_nickname + ",3秒后自动为您转入管理员首页";
                        AdminLoginStatus.Visible = true;
                        //重定向
                        HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
                        RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
                        RedirectMeta.Content = "3;url=admin_index.aspx"; //时间为三秒,跳转到首页
                        this.Page.Header.Controls.Add(RedirectMeta);

                    }
                    else
                    {
                        //登录请求非法
                        AdminLoginStatus.Text = "用户名或密码错误,请重试";
                        AdminLoginStatus.Visible = true;
                        AdminLoginForm.Visible = true;
                    }
                }
                else
                {
                    //验证码校验失败,给出提示信息
                    AdminLoginStatus.Text = "验证码校验失败,请刷新验证码后重试";
                    AdminLoginStatus.Visible = true;
                    AdminLoginForm.Visible = true;
                }
            }
        }