示例#1
0
        public ActionResult FindPassword(string token, string password1, string password2)
        {
            var flag = true;

            if (string.IsNullOrEmpty(password1))
            {
                ViewBag.password1Wrong = "请输入新密码";
                flag = false;
            }
            if (string.IsNullOrEmpty(password2))
            {
                ViewBag.password2Wrong = "请再次输入新密码";
                flag = false;
            }
            if (!string.IsNullOrEmpty(password1) && !string.IsNullOrEmpty(password2) && password1 != password2)
            {
                ViewBag.password2Wrong = "密码不一致,请重新输入";
                flag = false;
            }
            if (!flag)
            {
                return(View());
            }
            flag = SupplierUserBll.UpdatePassWordByToken(token, password1);
            if (flag)
            {
                return(View("FindPasswordSuccess"));
            }
            else
            {
                return(new TransferResult("/Error/TokenExpired"));
            }
        }
示例#2
0
        public ActionResult EditUser(int id = 0)
        {
            var supplierID = CurrentUser.SupplierID;

            try
            {
                SupplierUserInfo userInfo;
                if (id > 0)
                {
                    userInfo = SupplierUserBll.GetSupplierUserBySupplierIDAndUserID(supplierID, id);
                }
                else
                {
                    userInfo = new SupplierUserInfo();
                }
                var page = new PageDTO()
                {
                    PageIndex = 1, PageSize = int.MaxValue
                };
                var RoleList = SupplierUserBll.GetSupplierRoleBySupplierID(supplierID, page);
                ViewBag.RoleList = RoleList.Items;
                return(View(userInfo));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(Content(""));
        }
示例#3
0
        public ActionResult SaveGroup(SupplierRoleInfo roleinfo)
        {
            var supplierID = CurrentUser.SupplierID;

            try
            {
                if (SupplierUserBll.ExistsSupplierRoleName(supplierID, roleinfo.RoleID, roleinfo.RoleName))
                {
                    return(Json(new { Error = 1, Message = "此分組名已存在" }));
                }
                var falg = SupplierUserBll.SaveSupplierRoleInfo(supplierID, roleinfo);
                if (falg)
                {
                    return(Json(new { Error = 0 }));
                }
                else
                {
                    return(Json(new { Error = 1 }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(Json(new { Error = 1, Message = ex.Message }));
            }
        }
示例#4
0
        public ActionResult ChangeUserStatus(int userID, int status)
        {
            var supplierID = CurrentUser.SupplierID;

            try
            {
                var falg = SupplierUserBll.ChangeSupplierUserStatus(supplierID, userID, status);
                if (falg)
                {
                    if (status == 2)
                    {
                        //账号被禁用的时候使用户的会话失效
                        LoginHelper.RemoveLoginInfo(userID);
                    }
                    return(Json(new { Error = 0 }));
                }
                else
                {
                    return(Json(new { Error = 1 }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(Json(new { Error = 1, Message = ex.Message }));
            }
        }
示例#5
0
 public JsonResult ChangePassword(string oldPassword, string newPassword)
 {
     if (string.IsNullOrEmpty(oldPassword))
     {
         return(Json(new { Error = 1, OldPassword = "******" }));
     }
     if (string.IsNullOrEmpty(newPassword))
     {
         return(Json(new { Error = 1, NewPassword = "******" }));
     }
     try
     {
         var oldPass = MD5Hash.GetMd5String(oldPassword);
         var oriPass = SupplierUserBll.GetPassHashByUserID(CurrentUser.ID);
         if (!string.Equals(oriPass, oldPass, StringComparison.OrdinalIgnoreCase))
         {
             return(Json(new { Error = 1, OldPassword = "******" }));
         }
         var flag = SupplierUserBll.UpdatePassWordByUserID(CurrentUser.ID, newPassword) > 0;
         if (flag)
         {
             return(Json(new { Error = 0 }));
         }
         else
         {
             return(Json(new { Error = 1, Message = "密码修改失败" }));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         return(Json(new { Error = 1, Message = ex.Message }));
     }
 }
示例#6
0
        public JsonResult ForgetPassword(string supplierName, string userName)
        {
            supplierName = supplierName.SafeTrim();
            userName     = userName.SafeTrim();
            var flag   = true;
            var errors = new System.Collections.Hashtable();

            errors.Add("Error", "1");
            if (string.IsNullOrEmpty(supplierName))
            {
                errors.Add("SupplierNameWrong", "请输入公司名称");
                flag = false;
            }
            if (string.IsNullOrEmpty(userName))
            {
                errors.Add("UserNameWrong", "请输入账号");
                flag = false;
            }
            if (!flag)
            {
                return(Json(errors));
            }
            else
            {
                var date       = DateTime.Now.Date;
                var supplierID = SupplierUserBll.GetSupplierID(supplierName, userName);
                if (supplierID <= 0)
                {
                    errors.Add("ClearInput", "1");
                    errors.Add("UserNameWrong", "公司名称&登录账号错误或不匹配,请核实后重新输入");
                    return(Json(errors));
                }
                var counter = SupplierUserBll.GetSupplierCounter(supplierID, EnumCountType.ForgetPassword, date);
                if (counter != null)
                {
                    if (DateTime.Now < counter.UpdateTime.AddMinutes(10))
                    {
                        return(Json(new { Error = 1, Message = "密码重置邮件已经发送,如果您未收到重置邮件,请在10分钟后重新验证索取" }));
                    }
                    if (counter.Value >= 5)
                    {
                        return(Json(new { Error = 1, Message = "该账号今天已超过验证次数限制,请明天再试" }));
                    }
                }
                var token = SupplierUserBll.GetFindPasswordToken(supplierName, userName);
                if (token == null)
                {
                    errors.Add("ClearInput", "1");
                    errors.Add("UserNameWrong", "公司名称&登录账号错误或不匹配,请核实后重新输入");
                    return(Json(errors));
                }
                else
                {
                    return(Json(new { Error = 0 }));
                }
            }
        }
示例#7
0
        public ActionResult EditGroup(int id = 0)
        {
            SupplierRolePermissionModel model = new SupplierRolePermissionModel();
            var supplierID = CurrentUser.SupplierID;

            try
            {
                if (id == 0)
                {
                    model.Role = new SupplierRoleInfo();
                }
                else
                {
                    model.Role = SupplierUserBll.GetSupplierRoleInfo(supplierID, id);
                    if (model.Role == null)
                    {
                        throw new Exception("未找到用戶分組(id:" + id.ToString() + ")");
                    }
                }
                var menuIds = model.Role.MenuIdList ?? new List <int>();
                var lstMenu = new SupplierUserMenuBLL().GetAllMenuPermission();
                var dic     = lstMenu.ToDictionary(p => p.Permission,
                                                   p => new Tree <SupplierMenuInfo>()
                {
                    Node        = p,
                    IsActive    = menuIds.Contains(p.MenuId) ? (bool?)true : null,
                    SubNodeList = new List <Tree <SupplierMenuInfo> >()
                });
                foreach (var menu in lstMenu.Where(p => p.ParentPermission != EnumPermission.None))
                {
                    Tree <SupplierMenuInfo> node;
                    if (dic.TryGetValue(menu.ParentPermission, out node))
                    {
                        node.SubNodeList.Add(dic[menu.Permission]);
                    }
                }
                var PermissionTree = new List <Tree <SupplierMenuInfo> >();
                PermissionTree.AddRange(lstMenu.Where(p => p.ParentPermission == EnumPermission.None).Select(p => dic[p.Permission]));
                foreach (var node in PermissionTree.Where(p => p.IsActive == true))
                {
                    if (node.Exists(p => !p.IsActive.HasValue))
                    {
                        node.IsActive = false;
                    }
                }
                model.PermissionTree = PermissionTree;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(new TransferResult("/Error/PageNotFound"));
            }
            return(View(model));
        }
示例#8
0
        public ActionResult FindPassword(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(new TransferResult("/Error/TokenExpired"));
            }
            var fpToken = SupplierUserBll.VerifyFindPasswordToken(token);

            if (fpToken == null)
            {
                return(new TransferResult("/Error/TokenExpired"));
            }
            return(View());
        }
示例#9
0
        public JsonResult SaveUser(SupplierUserInfo userinfo)
        {
            if (userinfo.ID == 0)
            {
                userinfo.UserName = userinfo.UserName.SafeTrim();
                if (string.IsNullOrEmpty(userinfo.UserName))
                {
                    return(Json(new { Error = 1, Message = "請輸入賬號" }));
                }
                if (userinfo.UserName.Length > 50)
                {
                    return(Json(new { Error = 1, Message = "賬號長度不能超過50個字符" }));
                }
                if (string.IsNullOrEmpty(userinfo.Password))
                {
                    return(Json(new { Error = 1, Message = "請輸入密碼" }));
                }
                if (userinfo.Password.Length < 6 || userinfo.Password.Length > 32)
                {
                    return(Json(new { Error = 1, Message = "密碼長度只允許為6到32个字符" }));
                }
                if (!string.IsNullOrEmpty(userinfo.NickName) && (userinfo.NickName.Length < 4 || userinfo.NickName.Length > 20))
                {
                    return(Json(new { Error = 1, Message = "使用者姓名長度只允許為6到32个字符" }));
                }
            }
            var supplierID = CurrentUser.SupplierID;

            try
            {
                if (userinfo.ID == 0 && SupplierUserBll.ExistsSupplierUserName(userinfo.UserName))
                {
                    return(Json(new { Error = 1, Message = "此賬號已被佔用" }));
                }
                var falg = SupplierUserBll.SaveSupplierUserInfo(supplierID, userinfo);
                if (falg)
                {
                    return(Json(new { Error = 0 }));
                }
                else
                {
                    return(Json(new { Error = 1 }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(Json(new { Error = 1, Message = ex.Message }));
            }
        }
示例#10
0
        public ActionResult ViewGroupUsers(int id = 0)
        {
            var supplierID = CurrentUser.SupplierID;

            try
            {
                var dataList = SupplierUserBll.GetSupplierUserBySupplierIDAndRoleID(supplierID, id);
                return(View(dataList));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(View(new List <SupplierUserInfo>()));
        }
示例#11
0
        /// <summary>
        /// 获取当前登录用户的LoginUserModel
        /// </summary>
        /// <param name="Session"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static LoginUserModel GetUserInfo(HttpSessionStateBase Session, int userid)
        {
            var model = CacheHelper.AutoCache <LoginUserModel>(
                GetCacheKey(userid.ToString()), "", () =>
            {
                return(SupplierUserBll.GetLoginUserModelByUserID(userid));
            });

            if (model != null && (model.SupplierUserInfo.Status != 1 || model.SupplierUserInfo.SupplierStatus != 1))
            {
                //用户状态无效,使用户的会话失效
                model = null;
                RemoveCurrentLoginInfo();
            }
            return(model);
        }
示例#12
0
        public ActionResult UserList(int PageIndex = 1)
        {
            var supplierID = CurrentUser.SupplierID;
            var page       = new PageDTO()
            {
                PageIndex = PageIndex, PageSize = 50
            };

            try
            {
                var dataList = SupplierUserBll.GetSupplierUserBySupplierID(supplierID, page);
                return(View(dataList));
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(View(new PageOf <SupplierUserInfo>()));
        }
示例#13
0
        public ActionResult DeleteGroup(int id)
        {
            var supplierID = CurrentUser.SupplierID;

            try
            {
                var falg = SupplierUserBll.DeleteSupplierRoleInfo(supplierID, id);
                if (falg)
                {
                    return(Json(new { Error = 0 }));
                }
                else
                {
                    return(Json(new { Error = 1 }));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(Json(new { Error = 1, Message = ex.Message }));
            }
        }
示例#14
0
 public ActionResult Login(LoginModel model)
 {
     if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password))
     {
         do
         {
             var date   = DateTime.Now.Date;
             var userID = SupplierUserBll.GetSupplierUserID(model.UserName.SafeTrim());
             if (userID <= 0)
             {
                 model.ErrorInfoForUserName = "******";
                 break;
             }
             var counter = SupplierUserBll.GetSupplierCounter(userID, EnumCountType.LoginFail, date);
             if (counter != null && counter.Value >= 10)
             {
                 model.ErrorInfoForUserName = "******";
                 break;
             }
             var userInfo = SupplierUserBll.GetUserInfoByLogin(model.UserName.SafeTrim(), model.Password);
             if (userInfo != null)
             {
                 if (userInfo.Status != 1)
                 {
                     model.ErrorInfoForUserName = "******";
                 }
                 else if (userInfo.SupplierStatus != 1)
                 {
                     model.ErrorInfoForUserName = "******";
                 }
                 else
                 {
                     var userMenuBll = new SupplierUserMenuBLL();
                     SupplierPermissionModel userPermission;
                     if (userInfo.IsAdmin == 1)
                     {
                         userPermission = userMenuBll.GetAllPermissionInfo();
                     }
                     else
                     {
                         userPermission = userMenuBll.GetMenuBySupplierUserId(userInfo.ID);
                     }
                     if (userPermission != null && userPermission.MenuList != null && userPermission.MenuList.Count > 0)
                     {
                         var loginUserModel = new LoginUserModel()
                         {
                             SupplierUserInfo = userInfo,
                             MenuList         = userPermission.MenuList,
                             PermissionSet    = userPermission.PermissionSet
                         };
                         LoginHelper.Cache(Session, loginUserModel);
                         if (string.IsNullOrEmpty(model.ReturnUrl) || string.Equals(model.ReturnUrl, "/") || model.ReturnUrl.StartsWith("/?"))
                         {
                             return(RedirectToAction("Index", "Home"));
                         }
                         else
                         {
                             return(Redirect(model.ReturnUrl));
                         }
                     }
                     else
                     {
                         model.ErrorInfoForUserName = "******";
                     }
                 }
             }
             else
             {
                 model.ErrorInfoForUserName = "******";
             }
         }while (false);
     }
     else
     {
         model.ErrorInfoForUserName = "******";
         model.ErrorInfoForPassword = "******";
     }
     return(View(model));
 }