コード例 #1
0
        public ActionResult Login(FormCollection form)
        {
            string name   = form["name"];
            string pwd    = form["pwd"];
            var    member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.UserName == name ||
                                                                                               m.Tel == name || m.Mail == name).FirstOrDefault();

            if (member == null)
            {
                //从考试订房中获取考生资料
                var users = EnterRepository.GetRepositoryEnter().UsersRepository.LoadEntities(m => m.Tel == name).FirstOrDefault();
                if (users == null)
                {
                    return(Content("用户不存在"));
                }
                else
                {
                    //自动创建会员
                    member            = new Member();
                    member.CreateTime = DateTime.Now;
                    member.Tel        = users.Tel;
                    member.Picture    = SystemContext.Instance.GetDefaultImg();
                    member.Password   = string.IsNullOrEmpty(users.Pwd)? Utility.MD5Helper.MD5(SystemContext.Instance.DefaultPwd): Utility.MD5Helper.MD5(member.Password);
                    member.UserName   = users.Name + "_" + users.Sequences.ToString();
                    EnterRepository.GetRepositoryEnter().MemberRepository.AddEntity(member);
                    if (EnterRepository.GetRepositoryEnter().SaveChange() <= 0)
                    {
                        return(Content("用户不存在"));
                    }
                }
            }
            else if (Utility.MD5Helper.MD5(pwd) != member.Password)
            {
                return(Content("密码错误"));
            }
            WebCookieHelper.SetUserCookie(member.ID, member.UserName, member.Tel, "", member.Picture, 15);
            string tel      = WebCookieHelper.GetUserInfo(2);
            var    employee = EnterRepository.GetRepositoryEnter().EmployeeRepository.LoadEntities(m => m.Tel == tel).FirstOrDefault();

            if (employee != null)
            {
                WebCookieHelper.SetEmployeeCookie(employee.ID, employee.Name, employee.EmpNo, employee.Tel, 15);
            }
            return(Content(string.Empty));
        }
コード例 #2
0
        public ActionResult PersonalInfo()
        {
            int id     = WebCookieHelper.GetUserId(0);
            var member = EnterRepository.GetRepositoryEnter().MemberRepository.LoadEntities(m => m.ID == id).FirstOrDefault();

            if (member == null)
            {
                string userAgent = Request.UserAgent;
                if (userAgent.ToLower().Contains("micromessenger"))
                {
                    Utility.CookieHelper.SetCookie("returnurl", Request.Url.ToString(), "", 1);
                    return(Redirect("/weixin/account"));
                }
                else
                {
                    return(Redirect("/member/login?returnurl=" + Request.Url));
                }
            }
            var oAuthUser      = EnterRepository.GetRepositoryEnter().OAuthUserRepository.LoadEntities(m => m.MemberID == id).FirstOrDefault();
            int blogsum        = EnterRepository.GetRepositoryEnter().BlogRepository.LoadEntities(m => m.MemberID == id).Count();
            int blogvideosum   = 0;
            int blogpicturesum = 0;

            EnterRepository.GetRepositoryEnter().BlogRepository.GetBlogs(null, id, SystemConst.CategoryCode.BlogVideo, null, 0, 0, out blogvideosum);
            EnterRepository.GetRepositoryEnter().BlogRepository.GetBlogs(null, id, SystemConst.CategoryCode.BlogPicture, null, 0, 0, out blogvideosum);

            if (oAuthUser != null)
            {
                ViewBag.FigureUrl = oAuthUser.Headimgurl;
            }
            string tel      = WebCookieHelper.GetUserInfo(2);
            var    employee = EnterRepository.GetRepositoryEnter().EmployeeRepository.LoadEntities(m => m.Tel == tel).FirstOrDefault();

            if (employee != null)
            {
                WebCookieHelper.SetEmployeeCookie(employee.ID, employee.Name, employee.EmpNo, employee.Tel, 15);
            }
            ViewBag.employee       = employee;
            ViewBag.blogsum        = blogsum;
            ViewBag.blogvideosum   = blogvideosum;
            ViewBag.blogpicturesum = blogpicturesum;
            GlobalMethod.log.Info(string.Format("{0}进入个人主页", member.UserName));
            return(View(member));
        }
コード例 #3
0
        public JsonResult Login(Models.LoginModel model)
        {
            if (ModelState.IsValid)
            {
                string validateImgCode = CookieHelper.GetCookie("ValidateImgCode");
                //首先判断下验证码是否正确
                if (!string.IsNullOrEmpty(validateImgCode) && string.Equals(validateImgCode,
                                                                            model.ValidateCode, StringComparison.OrdinalIgnoreCase))
                {
                    Employee adminModel = new Employee();
                    if (new Regex("1[3|5|7|8|][0-9]{9}").IsMatch(model.UserName))
                    {//匹配手机号码
                        adminModel = EnterRepository.GetRepositoryEnter().EmployeeRepository.LoadEntities(m => m.Tel == model.UserName).FirstOrDefault();
                    }
                    else  //匹配用户名
                    {
                        adminModel = EnterRepository.GetRepositoryEnter().EmployeeRepository.LoadEntities(m => m.EmpNo == model.UserName).FirstOrDefault();
                    }
                    if (adminModel == null)
                    {
                        return(Json(new
                        {
                            state = "error",
                            message = "用户名不存在"
                        }));
                    }
                    else
                    {
                        //判断密码是否正确
                        if (adminModel.Pwd == model.Password)
                        {
                            string ip            = IpHelper.GetRealIP();
                            string address       = IpHelper.GetAdrByIp(ip);
                            string brower        = IpHelper.GetBrowerVersion();
                            string adminloginlog = string.Join("|", new string[] { DateTime.Now.ToString(), adminModel.Name, ip, address, brower });
                            log.Info("用户登录后台管理:" + adminloginlog);
                            //添加登录日志并修改上次登录信息

                            //先清除原来的cookie
                            WebCookieHelper.EmployeeLoginOut();
                            //登录成功,保存cookie
                            WebCookieHelper.SetEmployeeCookie(adminModel.ID, adminModel.Name, adminModel.EmpNo, adminModel.Tel, (model.IsRemind != null && model.IsRemind) ? 15 : 0);
                            return(Json(new
                            {
                                state = "success",
                                message = "登录成功"
                            }));
                        }
                        else
                        {
                            return(Json(new
                            {
                                state = "error",
                                message = "密码错误"
                            }));
                        }
                    }
                }
                else
                {
                    return(Json(new
                    {
                        state = "error",
                        message = "验证码错误"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    state = "error",
                    message = "输入信息不完整"
                }));
            }
        }