Ejemplo n.º 1
0
        /// <summary>
      /// 验证教师用户的合法性
      /// </summary>
      /// <param name="uname"></param>
      /// <param name="pwd"></param>
      /// <returns></returns>
        public bool ValidateUser(string uname, string pwd)
        {
            string pwdEncode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
           
             ExamDbDataContext dc = DataAccess.CreateDBContext(); 
            var teachers = from t in dc.TeacherInfo
                           where t.LoginName == uname && t.Password == pwdEncode
                           select t;
            if (teachers.Count<TeacherInfo>() > 0)
            {
                TeacherInfo t=teachers.FirstOrDefault<TeacherInfo>();
                HttpContext.Current.Session["DepartmentID"] = t.DepartmentID;
                HttpContext.Current.Session["UserRealName"] = t.TeacherName;
                HttpContext.Current.Session["UserID"] = t.TeacherID;

                if(t.MajorID==null)
                    HttpContext.Current.Session["MajorID"] = 0;
                else
                    HttpContext.Current.Session["MajorID"] = t.MajorID;
          
                HttpContext.Current.Session["IsStudent"] = false;
                if (t.IsMajorManager == true)
                {
                    HttpContext.Current.Session["Role"] = "majorManager";
                    HttpContext.Current.Session["IsMajorManager"] = true;
                }
                else HttpContext.Current.Session["Role"] = "teacher";

                string basePath = Utility.GetConfigValue(t.DepartmentID, "UploadedFilePath");             
               

                HttpContext.Current.Session["PersonalDirectory"] = basePath+ "/PersonalFiles/Teacher/"+t.TeacherName +"_"+ (t.TeacherNum==null?"N":t.TeacherNum);

                t.LoginCount = t.LoginCount + 1;

                LogInfo l = new LogInfo();
                l.LogTitle = "登录";
                l.LogContent = t.TeacherName + "老师登录成功!";
                l.LogType = "登录";
                l.AddedTime = DateTime.Now;
                dc.LogInfo.InsertOnSubmit(l);
                dc.SubmitChanges();
                return true;
            }
            else return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 验证管理员的合法性
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool ValidateUser(string uname, string pwd)
        {
           string pwdEncode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
            
             ExamDbDataContext dc = DataAccess.CreateDBContext();
            var admins = from a in dc.AdminUserInfo
                         where a.LoginName == uname && a.Password == pwdEncode
                         select a;
            if (admins.Count<AdminUserInfo>() > 0)
            {
                AdminUserInfo ad=ToSingle<AdminUserInfo>(admins);//.First<AdminUserInfo>();
                if (ad == null) return false;
                HttpContext.Current.Session["DepartmentID"] =ad.DepartmentID;
                HttpContext.Current.Session["UserRealName"] = ad.LoginName;
                HttpContext.Current.Session["IsAdmin"] = true;
                HttpContext.Current.Session["UserID"] = 0;
                   HttpContext.Current.Session["AdminUserID"]= ad.AdminUserID;
                HttpContext.Current.Session["IsStudent"] = false;
                if (ad.IsSuperAdmin == true)
                {
                    HttpContext.Current.Session["IsSuperAdmin"] = true;
                    HttpContext.Current.Session["Role"] = "superadmin";
                }
                else
                {
                    HttpContext.Current.Session["IsSuperAdmin"] = null;

                    if (ad.IsFromAdministration == true)
                        HttpContext.Current.Session["Role"] = "schooladmin";
                    else HttpContext.Current.Session["Role"] = "admin";
                }

                ad.LoginCount = ad.LoginCount + 1;

                LogInfo l = new LogInfo();
                l.LogTitle = "登录";
                l.LogContent = ad.LoginName + "管理员登录成功!";
                l.LogType = "登录";
                l.AddedTime = DateTime.Now;
                dc.LogInfo.InsertOnSubmit(l);
                dc.SubmitChanges();
                return true;
            }
            else return false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 验证学生用户的合法性
        /// </summary>
        /// <param name="uname"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool ValidateUser(string uname, string pwd)
        {

            string pwdEncode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "SHA1");
            ExamDbDataContext dc = DataAccess.CreateDBContext();
            var students = from s in dc.StudentInfo
                           where s.LoginName == uname && s.Password == pwdEncode
                           select s;
            if (students.Count<StudentInfo>() > 0)
            {
                StudentInfo s = students.FirstOrDefault<StudentInfo>();
                if (s == null) return false;
                HttpContext.Current.Session["DepartmentID"] = s.DepartmentID;
                HttpContext.Current.Session["UserRealName"] = s.StuName;
                HttpContext.Current.Session["UserID"] = s.StudentID;
                HttpContext.Current.Session["MajorID"] = s.MajorID;
                HttpContext.Current.Session["FullProfile"] = s.IsFullProfile;

                HttpContext.Current.Session["StuNum"] = s.StuNum;
                HttpContext.Current.Session["ClassName"] = s.Class;

                HttpContext.Current.Session["IsStudent"] = true;
                HttpContext.Current.Session["Role"] = "student";
                //HttpContext.Current.Session["PersonalDirectory"] = "~/Files/PersonalFiles/Student/"+s.DepartmentID+"/" + s.StuName + s.StudentID;
                string basePath = Utility.GetConfigValue(s.DepartmentID, "UploadedFilePath");
                HttpContext.Current.Session["PersonalDirectory"] = basePath + "/PersonalFiles/Student/" + s.StuNum + "_" + s.StuName;

                s.LoginCount = s.LoginCount + 1;

                LogInfo l = new LogInfo();
                l.LogTitle = "登录";
                l.LogContent ="学号为"+s.StuNum+ s.StuName + "同学登录成功!";
                l.LogType = "登录";
                l.AddedTime = DateTime.Now;
                dc.LogInfo.InsertOnSubmit(l);
                dc.SubmitChanges();
                return true;
            }
            else return false;
        }