Пример #1
0
        public ActionResult Index(string userName, string userPwd)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(userPwd))
            {
                ViewBag.Success = false;
                ViewBag.Message = "账号或密码不能为空!";
                return(View());
            }
            userPwd = userPwd.ToSHA1();
            UrUsersBll bll  = new UrUsersBll();
            UR_USERS   user = bll.Query(t => t.USER_LOGIN_NAME == userName && t.USER_LOGIN_PASSWD == userPwd).FirstOrDefault();

            if (user == null)
            {
                ViewBag.Success = false;
                ViewBag.Message = "账号或密码错误!";
                return(View());
            }

            user.USER_LOGIN_DATE = DateTime.Now;
            user.USER_UNUSED1    = Guid.NewGuid().ToString("n");
            bll.Update(user);
            //写入cookie
            HttpCookie cookies = new HttpCookie("UserToken");

            cookies["token"]    = user.USER_UNUSED1;
            cookies["userName"] = HttpUtility.UrlEncode(user.USER_NAME, System.Text.Encoding.UTF8);
            cookies.Expires     = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookies);

            return(Redirect("~/Home/"));
        }
Пример #2
0
        /// <summary>
        /// 验证是否登录
        /// </summary>
        /// <returns></returns>
        public static bool IsLogin()
        {
            try
            {
                UrUsersBll bll     = new UrUsersBll();
                HttpCookie cookies = HttpContext.Current.Request.Cookies["UserToken"];
                if (cookies == null)
                {
                    return(false);
                }

                string   token = cookies["token"];
                UR_USERS user  = bll.Query(t => t.USER_UNUSED1 == token).FirstOrDefault();

                if (user == null)
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
        public ActionResult AdminList()
        {
            string keyword = Request["keyword"];

            ViewBag.Keyword = keyword;
            UrUsersBll      bll     = new UrUsersBll();
            List <UR_USERS> allUser = bll.Query(t => string.IsNullOrEmpty(keyword) ? true : t.USER_NAME.Contains(keyword)).ToList();

            return(View(allUser));
        }
Пример #4
0
        public ActionResult AdminDel(int id)
        {
            UrUsersBll bll   = new UrUsersBll();
            UR_USERS   model = bll.Query(t => t.USER_ID == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Redirect("~/Manage/AdminList"));
        }
Пример #5
0
        /// <summary>
        /// 管理员修改
        /// </summary>
        /// <returns></returns>
        public ActionResult AdminEdit(int?id)
        {
            UR_USERS user = new UR_USERS();

            if (id.ToInt() > 0)
            {
                UrUsersBll bll = new UrUsersBll();
                user = bll.Query(t => t.USER_ID == id).FirstOrDefault();
            }

            ViewBag.Organization = new SysOrganizationBll().Query(t => true).ToDictionary(x => x.ORG_ID, x => x.ORG_NAME);
            ViewBag.Part         = new UrPartBll().Query(t => true).ToDictionary(x => x.PART_ID, x => x.PART_NAME);

            return(View(user));
        }
Пример #6
0
 /// <summary>
 /// 获取当前登录user对象
 /// </summary>
 /// <returns></returns>
 public static UR_USERS CurrentUser()
 {
     try
     {
         UrUsersBll bll     = new UrUsersBll();
         HttpCookie cookies = HttpContext.Current.Request.Cookies["UserToken"];
         if (cookies == null)
         {
             return(null);
         }
         string token = cookies["token"];
         return(bll.Query(t => t.USER_UNUSED1 == token).FirstOrDefault());
     }
     catch
     {
         return(null);
     }
 }
Пример #7
0
        public ActionResult AdminPwd(int userId, string oldPwd, string newPwd)
        {
            UrUsersBll bll  = new UrUsersBll();
            UR_USERS   user = bll.Query(t => t.USER_ID == userId).FirstOrDefault();

            if (user.USER_LOGIN_PASSWD != oldPwd.ToSHA1() && !string.IsNullOrEmpty(user.USER_LOGIN_PASSWD))
            {
                ViewBag.Success = false;
                ViewBag.Message = "当前密码不正确!";
                return(View(user));
            }
            user.USER_LOGIN_PASSWD = newPwd.ToSHA1();

            bll.Update(user);

            ViewBag.Success = true;
            ViewBag.Message = "修改成功!";

            return(View(user));
        }
Пример #8
0
        public ActionResult AdminEdit(UR_USERS model)
        {
            UrUsersBll bll  = new UrUsersBll();
            UR_USERS   user = bll.Query(t => t.USER_ID == model.USER_ID).FirstOrDefault();

            ViewBag.Organization = new SysOrganizationBll().Query(t => true).ToDictionary(x => x.ORG_ID, x => x.ORG_NAME);
            ViewBag.Part         = new UrPartBll().Query(t => true).ToDictionary(x => x.PART_ID, x => x.PART_NAME);

            if (user == null)
            {
                user = model;
                user.USER_CREATE_DATE = DateTime.Now;
                bll.Add(user);
            }
            else
            {
                user.USER_NAME       = model.USER_NAME;
                user.USER_ORG_ID     = model.USER_ORG_ID;
                user.USER_LOGIN_NAME = model.USER_LOGIN_NAME;
                user.USER_PHONE      = model.USER_PHONE;
                user.USER_MOBILE     = model.USER_MOBILE;
                user.USER_EMAIL      = model.USER_EMAIL;
                user.USER_WORK_NO    = model.USER_WORK_NO;
                user.USER_SEX        = model.USER_SEX;
                user.USER_TITLE      = model.USER_TITLE;
                user.USER_ACTIVE     = model.USER_ACTIVE;
                user.USER_ADMIN      = model.USER_ADMIN;

                user.USER_UPDATE_DATE = DateTime.Now;
                bll.Update(user);
            }

            ViewBag.Success = true;
            ViewBag.Message = "修改成功!";

            return(View(user));
        }
Пример #9
0
        //public static T GetRequestPrams(HttpContext context)
        //{
        //    Stream sream = context.Request.InputStream;
        //    StreamReader sr = new StreamReader(sream);
        //    string search = sr.ReadToEnd();
        //    sr.Close();
        //    var jSetting = new JsonSerializerSettings
        //    {
        //        NullValueHandling = NullValueHandling.Ignore
        //    };
        //    return JsonConvert.DeserializeObject<T>(search, jSetting);
        //}



        /// <summary>
        /// 接口验证登录
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public UR_USERS GetUser(string token)
        {
            if (BaseModels.IsLogin())
            {
                //登录状态
                return(BaseModels.CurrentUser());
            }

            if (string.IsNullOrEmpty(token))
            {
                return(null);
            }

            try
            {
                UrUsersBll bll = new UrUsersBll();

                return(bll.Query(t => t.USER_UNUSED1 == token).FirstOrDefault());
            }
            catch
            {
                return(null);
            }
        }