Example #1
0
        public ActionResult DoLogin()
        {
            if (string.IsNullOrEmpty(Request["UserName"]))
            {
                return Json(new { Result = false, Msg = "用户名不能为空!" }, JsonRequestBehavior.AllowGet);
            }

            if (string.IsNullOrEmpty(Request["Password"]))
            {
                return Json(new { Result = false, Msg = "密码不能为空!" }, JsonRequestBehavior.AllowGet);
            }

            if (string.IsNullOrEmpty(Request["UserName"]))
            {
                return Json(new { Result = false, Msg = "用户名不能为空!" }, JsonRequestBehavior.AllowGet);
            }

            if (string.IsNullOrEmpty(Request["Password"]))
            {
                return Json(new { Result = false, Msg = "密码不能为空!" }, JsonRequestBehavior.AllowGet);
            }

            if (true)
            {
                if (string.IsNullOrEmpty(Request["ValidCode"]))
                {
                    return Json(new { Result = false, Msg = "验证码不能为空!" }, JsonRequestBehavior.AllowGet);
                }

                if (string.IsNullOrEmpty(SessionHelper.Instance.ValidateCode))
                {
                    return Json(new { Result = false, Msg = "验证码错误!" }, JsonRequestBehavior.AllowGet);
                }

                if (!Request["ValidCode"].Equals(SessionHelper.Instance.ValidateCode, StringComparison.CurrentCultureIgnoreCase))
                {
                    return Json(new { Result = false, Msg = "验证码错误!" }, JsonRequestBehavior.AllowGet);
                }

                //清空验证码
                SessionHelper.Instance.ValidateCode = "";
            }

            string userName = Request["UserName"];
            string password = Request["Password"];
            string encryptPassword = MD5Lib.Encrypt(password);
            if (encryptPassword.Length > 11)
                encryptPassword = encryptPassword.Substring(0, 11);

            int userId;
            if (bll.Login(userName, encryptPassword + "%", out userId))
            {
                EntranceHomeBLL ehBLL = new EntranceHomeBLL();
                Member_Account member = ehBLL.GetMember_AccountModel(userId, "Delflag=0 and Status=2");

                SiteCache cache = SiteCache.Instance;
                LoginInfo loginInfo = new LoginInfo();
                loginInfo.PartitionId = 1;
                loginInfo.UserId = userId;

                cache.LoginInfo = loginInfo;
                cache.UserName = member.UserName;
                cache.NickName = member.Nickname;
                cache.OrganId = Convert.ToInt32(member.OrganId);
                List<PlatformGroups> list = ehBLL.GetPlatformGroupsList(1, userId);
                PlatformGroups model = new PlatformGroups()
                {
                    Id = (int)PlatformGroupEnum.TeacherGeneral,
                    Title = "普通教师",
                    ManageOrganId = Convert.ToInt32(member.OrganId),
                    ManagerId = member.Id
                };
                list.Add(model);
                cache.PlatformGroups = list;

                return Json(new { Result = true, Msg = "登录成功!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = false, Msg = "用户名或密码不正确!" }, JsonRequestBehavior.AllowGet);
            }
        }
Example #2
0
        public ActionResult Enter(int uid, string code)
        {
            string validCode = MD5Lib.Encrypt(uid.ToString() + "teacher.shlll.net" + DateTime.Now.ToString("yyyyMMddHH"));
            if (validCode.Equals(code, StringComparison.CurrentCultureIgnoreCase))
            {
                EntranceHomeBLL ehBLL = new EntranceHomeBLL();
                Member_Account member = ehBLL.GetMember_AccountModel("Delflag=0 and Status=2 and OutSourceId=" + uid);
                if (member == null)
                {
                    return Content("用户信息不存在。");
                }
                else
                {
                    SiteCache cache = SiteCache.Instance;

                    //保存缓存信息
                    LoginInfo loginInfo = new LoginInfo();
                    loginInfo.PartitionId = 1;
                    loginInfo.UserId = member.Id;
                    cache.LoginInfo = loginInfo;
                    cache.UserName = member.UserName;
                    cache.NickName = member.Nickname;
                    cache.OrganId = Convert.ToInt32(member.OrganId);
                    List<PlatformGroups> list = ehBLL.GetPlatformGroupsList(1, member.Id);
                    PlatformGroups model = new PlatformGroups()
                    {
                        Id = (int)PlatformGroupEnum.TeacherGeneral,
                        Title = "普通教师",
                        ManageOrganId = Convert.ToInt32(member.OrganId),
                        ManagerId = member.Id
                    };
                    list.Add(model);
                    cache.PlatformGroups = list;

                    //默认设置为普通教师权限
                    cache.GroupId = (int)PlatformGroupEnum.TeacherGeneral;
                    cache.ManagerId = member.Id;
                    cache.ManageOrganId = Convert.ToInt32(member.OrganId);

                    return Redirect("/Learn/MyTest/Index");
                }
            }
            else
            {
                return Content("验证信息不正确。");
            }
        }