public ActionResult Login(String returnUrl)
 {
     ViewBag.Title = "Login";
     DAL.m_announcement dal_m_announcement = new DAL.m_announcement();
     List<Models.m_announcement> m_announcement_list = dal_m_announcement.GetListModelByPage(true);
     try
     {
         //Remember me login.
         DAL.z_user dal_user = new DAL.z_user();
         if (Request.Cookies["YourAppLogin"] != null)
         {
             string userAccount = Request.Cookies["YourAppLogin"].Values["loginUserAccount"];
             if (userAccount != null)
             {
                 Common.Encrypt Encrypt = new Common.Encrypt();
                 Models.z_user model_z_user = dal_user.GetLoginModel(Encrypt.DecryptString(userAccount.Trim()));
                 if (model_z_user != null)
                 {
                     DAL.z_menu dal_z_menu = new DAL.z_menu();
                     List<Models.z_menu> z_menu_list = dal_z_menu.GetMenuModelListByUserID(model_z_user.ID);
                     Session.Add("loginUserMenuList", z_menu_list);
                     Session.Add("loginUserModel", model_z_user);
                     if (!String.IsNullOrEmpty(returnUrl))
                     {
                         return Redirect(returnUrl);
                     }
                     else
                     {
                         return RedirectToAction("Index", "Home");
                     }
                 }
             }
         }
         ViewBag.errorMessage = "Please Login...";
         return View(m_announcement_list);
     }
     catch
     {
         ViewBag.errorMessage = "Please Login...";
         return View(m_announcement_list);
     }
 }
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     Models.z_user model_z_user = (Models.z_user)filterContext.HttpContext.Session["loginUserModel"];
     List<Models.z_menu> z_menu_list = (List<Models.z_menu>)filterContext.HttpContext.Session["loginUserMenuList"];
     if (model_z_user != null && z_menu_list != null)
     {
         //检查是否有权限
         String controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
         Boolean hasPermission = false;
         foreach (Models.z_menu item in z_menu_list)
         {
             if (item.VALUE.IndexOf("/" + controllerName) >= 0)
             {
                 hasPermission = true;
             }
         }
         if (hasPermission)
         {
             filterContext.Controller.ViewBag.model_z_user = model_z_user;
             filterContext.Controller.ViewBag.z_menu_list = z_menu_list;
         }
         else
         {
             //没有权限
             filterContext.Result = new ViewResult
             {
                 ViewName = "NoPermission",
                 ViewData = filterContext.Controller.ViewData
             };
         }
         //检查是否有权限
     }
     else  //Session lost
     {
         //Remember me login.
         if (filterContext.HttpContext.Request.Cookies["YourAppLogin"] != null)
         {
             DAL.z_user dal_user = new DAL.z_user();
             string userAccount = filterContext.HttpContext.Request.Cookies["YourAppLogin"].Values["loginUserAccount"];
             if (userAccount != null)
             {
                 Common.Encrypt Encrypt = new Common.Encrypt();
                 model_z_user = dal_user.GetLoginModel(Encrypt.DecryptString(userAccount.Trim()));
                 if (model_z_user != null)
                 {
                     DAL.z_menu dal_z_menu = new DAL.z_menu();
                     z_menu_list = dal_z_menu.GetMenuModelListByUserID(model_z_user.ID);
                     filterContext.HttpContext.Session.Remove("loginUserMenuList");
                     filterContext.HttpContext.Session.Remove("loginUserModel");
                     filterContext.HttpContext.Session.Add("loginUserMenuList", z_menu_list);
                     filterContext.HttpContext.Session.Add("loginUserModel", model_z_user);
                     //检查是否有权限
                     String controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                     Boolean hasPermission = false;
                     foreach (Models.z_menu item in z_menu_list)
                     {
                         if (item.VALUE.IndexOf("/" + controllerName) >= 0)
                         {
                             hasPermission = true;
                         }
                     }
                     if (hasPermission)
                     {
                         filterContext.Controller.ViewBag.model_z_user = model_z_user;
                         filterContext.Controller.ViewBag.z_menu_list = z_menu_list;
                     }
                     else
                     {
                         //没有权限
                         filterContext.Result = new ViewResult
                         {
                             ViewName = "NoPermission",
                             ViewData = filterContext.Controller.ViewData
                         };
                     }
                     //检查是否有权限
                 }
             }
         }
         else  //没有session也没有cookies
         {
             filterContext.Result = new ViewResult
             {
                 ViewName = "SessionLost",
                 ViewData = filterContext.Controller.ViewData
             };
         }
     }
     base.OnActionExecuting(filterContext);
 }
 //
 // GET: /Payment/
 public ActionResult Index(string area, string associated_user, string start_time, string end_time)
 {
     area = HttpUtility.UrlDecode(area);
     DAL.m_worker dal_m_worker = new DAL.m_worker();
     Models.z_user session_model_z_user = (Models.z_user)ViewBag.model_z_user;
     //判断是否有管理员和经理权限
     DAL.z_role dal_z_role = new DAL.z_role();
     List<Models.z_role> z_role_list = dal_z_role.GetModelList(session_model_z_user.ID);
     Boolean canAddorImport = false;
     foreach (Models.z_role model_z_role in z_role_list)
     {
         if (model_z_role.NAME == "管理员" || model_z_role.NAME == "经理")
         {
             canAddorImport = true;
         }
     }
     ViewBag.canAddorImport = canAddorImport;
     //判断是否有管理员和经理权限
     if (!canAddorImport)
     {
         associated_user = session_model_z_user.ID.ToString();
     }
     DataSet dsChart = dal_m_worker.GetReportChart(area, associated_user, start_time, end_time);
     ViewBag.ReportChart = dsChart.Tables[0];
     DAL.z_parameter dal_z_parameter = new DAL.z_parameter();
     DAL.z_user dal_z_user = new DAL.z_user();
     ViewBag.area_list = dal_z_parameter.GetModelList("地区");
     ViewBag.associated_user_list = dal_z_user.GetListModel();
     ViewBag.area = area;
     ViewBag.associated_user = associated_user;
     ViewBag.start_time = start_time;
     ViewBag.end_time = end_time;
     return View();
 }
 public ActionResult Login(FormCollection collection)
 {
     DAL.m_announcement dal_m_announcement = new DAL.m_announcement();
     List<Models.m_announcement> m_announcement_list = dal_m_announcement.GetListModelByPage(true);
     try
     {
         var name = collection["name"].Trim();
         var password = collection["password"].Trim();
         var rememberMe = collection["rememberMe"];
         var valicode = collection["valicode"].Trim();
         var returnUrl = collection["returnUrl"];
         //验证验证码
         if (Session["ValidateCode"].ToString() != valicode)
         {
             ViewBag.errorMessage = "Incorrect verification code";
             return View(m_announcement_list);
         }
         //此处验证用户名、密码
         DAL.z_user dal_user = new DAL.z_user();
         Models.z_user model_z_user = dal_user.GetLoginModel(name.Trim(), Common.Common.MD5(password.Trim()));
         if (model_z_user == null)
         {
             ViewBag.errorMessage = "User name or password is incorrect";
             return View(m_announcement_list);
         }
         //验证成功
         if (rememberMe == "on")
         {
             HttpCookie cookie = new HttpCookie("YourAppLogin");
             Common.Encrypt Encrypt = new Common.Encrypt();
             cookie.Values.Add("loginUserAccount", Encrypt.EncryptString(name.Trim()));
             cookie.Expires = DateTime.Now.AddDays(5);
             Response.Cookies.Add(cookie);
         }
         DAL.z_menu dal_z_menu = new DAL.z_menu();
         List<Models.z_menu> z_menu_list = dal_z_menu.GetMenuModelListByUserID(model_z_user.ID);
         Session.Add("loginUserMenuList", z_menu_list);
         Session.Add("loginUserModel", model_z_user);
         if (!String.IsNullOrEmpty(returnUrl))
         {
             return Redirect(returnUrl);
         }
         else
         {
             return RedirectToAction("Index", "Home");
         }
     }
     catch
     {
         ViewBag.errorMessage = "Incorrect verification code";
         return View(m_announcement_list);
     }
 }
Exemplo n.º 5
0
 public ActionResult Delete(FormCollection collection)
 {
     try
     {
         String IDlist = collection["user_id[]"];
         IDlist = IDlist.Replace(",", "','");
         IDlist = "'" + IDlist + "'";
         DAL.z_user dal_z_user = new DAL.z_user();
         dal_z_user.DeleteList(IDlist);
         return RedirectToAction("Index", new { message = HttpUtility.UrlEncode("Delete Succeed") });
     }
     catch
     {
         return RedirectToAction("Index", new { message = HttpUtility.UrlEncode("Delete Failed") });
     }
 }
 public ActionResult MyAccount(FormCollection collection)
 {
     try
     {
         var EMAIL = collection["EMAIL"].Trim();
         var MOBILE_NUM = collection["MOBILE_NUM"].Trim();
         var COMPANY_TEL = collection["COMPANY_TEL"].Trim();
         var PASSWORD = collection["PASSWORD"].Trim();
         var PASSWORD_RE = collection["PASSWORD_RE"].Trim();
         Models.z_user model_z_user = ViewBag.model_z_user;
         if (PASSWORD != null && PASSWORD != "")
         {
             if (PASSWORD == PASSWORD_RE)
             {
                 model_z_user.PASSWORD = Common.Common.MD5(PASSWORD);
             }
             else
             {
                 ViewBag.message = "Modify failed, password does not match";
                 return View();
             }
         }
         model_z_user.EMAIL = EMAIL;
         model_z_user.COMPANY_TEL = COMPANY_TEL;
         model_z_user.MOBILE_NUM = MOBILE_NUM;
         DAL.z_user dal_z_user = new DAL.z_user();
         dal_z_user.Update(model_z_user);
         ViewBag.message = "Modify Successfully";
         return View();
     }
     catch
     {
         ViewBag.message = "Modify failed";
         return View();
     }
 }
Exemplo n.º 7
0
        public ActionResult Create(FormCollection collection)
        {
            DAL.z_user dal_z_user = new DAL.z_user();
            Models.z_user model_z_user = new Models.z_user();
            DAL.z_r_user_role dal_z_r_user_role = new DAL.z_r_user_role();
            try
            {
                DAL.z_parameter dal_z_parameter = new DAL.z_parameter();
                DAL.z_role dal_z_role = new DAL.z_role();
                ViewBag.role_list = dal_z_role.GetModelList();
                // TODO: Add insert logic here
                string USER_CD = collection["USER_CD"].Trim();
                string PASSWORD = collection["PASSWORD"].Trim();
                string PASSWORD_RE = collection["PASSWORD_RE"].Trim();
                string LAST_NAME = collection["LAST_NAME"].Trim();
                string EMAIL = collection["EMAIL"].Trim();
                string MOBILE_NUM = collection["MOBILE_NUM"].Trim();
                string DESCRIPTION = collection["DESCRIPTION"].Trim();
                string ROLE = collection["ROLE"];
                if (USER_CD == "" || PASSWORD == "" || PASSWORD_RE == "" || LAST_NAME == "" || ROLE == null)
                {
                    ViewBag.message = "Create Failed, field with red start can't be blank";
                    return View();
                }
                if (PASSWORD != PASSWORD_RE)
                {
                    ViewBag.message = "Create Failed, password does not match";
                    return View();
                }
                if (dal_z_user.isCdDuplicate(USER_CD))
                {

                    ViewBag.message = "Create Failed, account is already exist";
                    return View();
                }
                model_z_user.ID = Guid.NewGuid();
                model_z_user.USER_CD = USER_CD;
                model_z_user.PASSWORD = Common.Common.MD5(PASSWORD);
                model_z_user.FIRST_NAME = "";
                model_z_user.LAST_NAME = LAST_NAME;
                model_z_user.GENDER = "";
                model_z_user.EMAIL = EMAIL;
                model_z_user.COMPANY_TEL = "";
                model_z_user.COMPANY_ID = Guid.NewGuid();
                model_z_user.MOBILE_NUM = MOBILE_NUM;
                model_z_user.POSITION_ID = Guid.NewGuid();
                model_z_user.DESCRIPTION = DESCRIPTION;
                model_z_user.CREATE_DATETIME = DateTime.Now;
                model_z_user.UPDATE_DATETIME = DateTime.Now;
                model_z_user.DELETE_FLG = "0";
                dal_z_user.Add(model_z_user);
                dal_z_r_user_role.Add(model_z_user.ID.ToString(), ROLE);
                return RedirectToAction("Index", new { message = HttpUtility.UrlEncode("Create Succeed") });
            }
            catch(Exception ex)
            {
                dal_z_user.Delete(model_z_user.ID);
                dal_z_r_user_role.DeleteRoleByUserID(model_z_user.ID.ToString());
                ViewBag.message = "Create Failed";
                return View();
            }
        }
Exemplo n.º 8
0
 //
 // GET: /User/
 public ActionResult Index(String message, String page, String name)
 {
     message = HttpUtility.UrlDecode(message);
     name = HttpUtility.UrlDecode(name);
     int pageNum = Common.Common.getPageNum(page);
     DAL.z_user dal_z_user = new DAL.z_user();
     if (message != null && message != "")
     {
         ViewBag.message = message;
     }
     List<Models.z_user> z_user_list = dal_z_user.GetListModelByPage(name, pageNum * 15 + 1, (pageNum + 1) * 15);
     ViewBag.recordCount = dal_z_user.GetRecordCount(name);
     ViewBag.page = pageNum + 1;
     ViewBag.pageNum = Math.Ceiling((double)ViewBag.recordCount / (double)15);
     ViewBag.name = name;
     return View(z_user_list);
 }
Exemplo n.º 9
0
 public ActionResult Edit(String id, FormCollection collection)
 {
     DAL.z_user dal_z_user = new DAL.z_user();
     Models.z_user model_z_user = dal_z_user.GetModel(new Guid(id));
     DAL.z_r_user_role dal_z_r_user_role = new DAL.z_r_user_role();
     DAL.z_parameter dal_z_parameter = new DAL.z_parameter();
     DAL.z_role dal_z_role = new DAL.z_role();
     ViewBag.role_list = dal_z_role.GetModelList();
     ViewBag.role_list_user = dal_z_role.GetModelList(new Guid(id));
     try
     {
         // TODO: Add insert logic here
         string USER_CD = collection["USER_CD"].Trim();
         string PASSWORD = collection["PASSWORD"].Trim();
         string PASSWORD_RE = collection["PASSWORD_RE"].Trim();
         string LAST_NAME = collection["LAST_NAME"].Trim();
         string EMAIL = collection["EMAIL"].Trim();
         string MOBILE_NUM = collection["MOBILE_NUM"].Trim();
         string DESCRIPTION = collection["DESCRIPTION"].Trim();
         string ROLE = collection["ROLE"];
         if (USER_CD == "" || LAST_NAME == "" || ROLE == null)
         {
             ViewBag.message = "Create Failed, field with red start can't be blank";
             return View(model_z_user);
         }
         if (PASSWORD != "" && PASSWORD != PASSWORD_RE)
         {
             ViewBag.message = "Create Failed, password does not match";
             return View(model_z_user);
         }
         if (dal_z_user.isCdDuplicate(USER_CD, model_z_user.ID.ToString()))
         {
             ViewBag.message = "Create Failed, account is already exist";
             return View(model_z_user);
         }
         model_z_user.USER_CD = USER_CD;
         if (PASSWORD != "")
         {
             model_z_user.PASSWORD = Common.Common.MD5(PASSWORD);
         }
         model_z_user.LAST_NAME = LAST_NAME;
         model_z_user.EMAIL = EMAIL;
         model_z_user.MOBILE_NUM = MOBILE_NUM;
         model_z_user.DESCRIPTION = DESCRIPTION;
         model_z_user.UPDATE_DATETIME = DateTime.Now;
         dal_z_user.Update(model_z_user);
         dal_z_r_user_role.DeleteRoleByUserID(model_z_user.ID.ToString());
         dal_z_r_user_role.Add(model_z_user.ID.ToString(), ROLE);
         return RedirectToAction("Index", new { message = HttpUtility.UrlEncode("Edit Succeed") });
     }
     catch
     {
         ViewBag.message = "Edit Failed";
         return View(model_z_user);
     }
 }
Exemplo n.º 10
0
 //
 // GET: /User/Edit/5
 public ActionResult Edit(String id)
 {
     DAL.z_user dal_z_user = new DAL.z_user();
     Models.z_user model_z_user = dal_z_user.GetModel(new Guid(id));
     DAL.z_parameter dal_z_parameter = new DAL.z_parameter();
     DAL.z_role dal_z_role = new DAL.z_role();
     ViewBag.role_list = dal_z_role.GetModelList();
     ViewBag.role_list_user = dal_z_role.GetModelList(new Guid(id));
     return View(model_z_user);
 }
Exemplo n.º 11
0
 //
 // GET: /User/Details/5
 public ActionResult Details(String id)
 {
     try
     {
         DAL.z_user dal_z_user = new DAL.z_user();
         Models.z_user model_z_user = dal_z_user.GetModel(new Guid(id));
         DAL.z_role dal_z_role = new DAL.z_role();
         List<Models.z_role> z_role_list = dal_z_role.GetModelList(new Guid(id));
         ViewBag.z_role_list = z_role_list;
         return View(model_z_user);
     }
     catch
     {
         ViewBag.message = "Item does not exist";
         return View();
     }
 }