Beispiel #1
0
        public VM.Common.UserItem ValidUser(VM.LoginModel loginUser)
        {
            var userpwd = DESEncrypt.Encrypt(loginUser.Password); //PRD
            //var userpwd = loginUser.Password; //Test
            var user = ctx.Common_Authen_User.FirstOrDefault(m => m.LogonName == loginUser.LoginName && m.Password == userpwd && m.Status == 1);

            if (user != null)
            {
                var userId = user.UserID;
                var model  = GetUser(user.UserID);

                //if (this.ctx.Common_Authen_RoleUser.Any(i => i.RoleID == RoleID.Student && i.UserID == userId))
                //{
                //    model.IsSutdent = true;
                //}
                //if (this.ctx.Common_Authen_RoleUser.Any(i => i.RoleID == RoleID.Lecturer && i.UserID == userId))
                //{
                //    model.IsLecture = true;
                //}

                return(model);
            }
            else
            {
                return(null);
            }
        }
        public ActionResult Login(VM.LoginModel model, string returnUrl)
        {
            var request = Request;

            if (ModelState.IsValid)
            {
                //using (Permission permissionBL = new Permission())
                //{
                //    UserItem userItem = permissionBL.ValidUser(model);
                //    if (userItem == null)
                //    {
                //        ModelState.AddModelError("", "用户名或密码不存在.");
                //        return View(model);
                //    }
                //    else
                //    {
                //        UserHelper.WriteLoginCookie(userItem);
                //        returnUrl = string.IsNullOrEmpty(returnUrl) ? "/" : returnUrl;
                //        return Redirect(returnUrl);
                //    }
                //}

                using (Permission permissionBL = new Permission())
                {
                    UserItem userItem = permissionBL.ValidUser(model);
                    if (userItem == null)
                    {
                        ModelState.AddModelError("", "用户名或密码不存在.");
                        return(View(model));
                    }
                    else
                    {
                        UserHelper.WriteLoginCookie(userItem);
                        returnUrl = string.IsNullOrEmpty(returnUrl) ? request.ApplicationPath : returnUrl;
                        return(Redirect(returnUrl));
                    }
                }
            }
            else
            {
                return(View(model));
            }
        }