Example #1
0
        /// <summary>
        /// 通过当前登录用户的token 获取用户信息,并缓存
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public Entities.SysUser getLogged(string token)
        {
            Entities.SysUser sysUser = null;

            _memoryCache.TryGetValue <Entities.SysUserToken>(token, out var userToken);
            if (userToken != null)
            {
                _memoryCache.TryGetValue(string.Format(MODEL_KEY, userToken.SysUserId), out sysUser);
            }
            if (sysUser != null)
            {
                return(sysUser);
            }

            if (Guid.TryParse(token, out var tokenId))
            {
                var tokenItem = _sysUserTokenRepository.Table.Include(x => x.SysUser)
                                .FirstOrDefault(o => o.Id == tokenId);
                if (tokenItem != null)
                {
                    _memoryCache.Set(token, tokenItem, DateTimeOffset.Now.AddHours(4));
                    //缓存
                    _memoryCache.Set(string.Format(MODEL_KEY, tokenItem.SysUserId), tokenItem.SysUser, DateTimeOffset.Now.AddHours(4));
                    return(tokenItem.SysUser);
                }
            }
            return(null);
        }
Example #2
0
        public ActionResult EditUser(Entities.SysUser model, string returnUrl = null)
        {
            ModelState.Remove("Id");
            ViewBag.ReturnUrl = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("userIndex");
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (!String.IsNullOrEmpty(model.MobilePhone))
            {
                model.MobilePhone = StringUitls.toDBC(model.MobilePhone);
            }
            model.Name = model.Name.Trim();

            if (model.Id == Guid.Empty)
            {
                model.Id           = Guid.NewGuid();
                model.CreationTime = DateTime.Now;
                model.Salt         = EncryptorHelper.CreateSaltKey();
                model.Account      = StringUitls.toDBC(model.Account.Trim());
                model.Enabled      = true;
                model.IsAdmin      = false;
                model.Password     = EncryptorHelper.GetMD5(model.Account + model.Salt);
                model.Creator      = WorkContext.CurrentUser.Id;
                _sysUserService.insertSysUser(model);
            }
            else
            {
                model.ModifiedTime = DateTime.Now;
                model.Modifier     = WorkContext.CurrentUser.Id;
                _sysUserService.updateSysUser(model);
            }
            return(Redirect(ViewBag.ReturnUrl));
        }
Example #3
0
 /// <summary>
 /// 新增,插入
 /// </summary>
 /// <param name="model"></param>
 public void insertSysUser(Entities.SysUser model)
 {
     if (existAccount(model.Account))
     {
         return;
     }
     _sysUserRepository.insert(model);
 }
Example #4
0
        /// <summary>
        /// 重置密码。默认重置成账号一样
        /// </summary>
        /// <param name="id"></param>
        /// <param name="modifer"></param>
        public void resetPassword(Entities.SysUser modelpass)
        {
            // _sysUserRepository.DbContext.Entry(modelpass).State = EntityState.Unchanged;
            _sysUserRepository.DbContext.Entry(modelpass).Property("Password").IsModified = true;
            _sysUserRepository.DbContext.Entry(modelpass).Property("Modifier").IsModified = true;

            _sysUserRepository.DbContext.SaveChanges();
        }
Example #5
0
 /// <summary>
 /// 更新修改
 /// </summary>
 /// <param name="model"></param>
 public void updateSysUser(Entities.SysUser model)
 {
     _sysUserRepository.DbContext.Entry(model).State = EntityState.Unchanged;
     _sysUserRepository.DbContext.Entry(model).Property("Name").IsModified        = true;
     _sysUserRepository.DbContext.Entry(model).Property("Email").IsModified       = true;
     _sysUserRepository.DbContext.Entry(model).Property("MobilePhone").IsModified = true;
     _sysUserRepository.DbContext.Entry(model).Property("Sex").IsModified         = true;
     _sysUserRepository.DbContext.SaveChanges();
 }
Example #6
0
        public void updateUsermessage(Entities.SysUser model)
        {
            // _sysUserRepository.DbContext.Entry(model).State = EntityState.Unchanged;
            _sysUserRepository.DbContext.Entry(model).Property("MobilePhone").IsModified = true;
            _sysUserRepository.DbContext.Entry(model).Property("Email").IsModified       = true;
            _sysUserRepository.DbContext.Entry(model).Property("Avatar2").IsModified     = true;
            _sysUserRepository.DbContext.SaveChanges();

            removeCacheUser(model.Id);   //没作用呢?
        }
Example #7
0
        public IPagedList <OrderDetail> searchOrder(OrderDetailSearchArgs args, int page, int size)
        {
            var query = _orderdetailRepository.Table;

            if (args != null)
            {
                if (!String.IsNullOrEmpty(args.q))
                {
                    var userList          = _sysUserRepository.Entities.Where(o => o.Account == (args.q));
                    Entities.SysUser user = null;
                    if (userList.Count() > 0)
                    {
                        user = userList.First();
                    }
                    int seatNumber;
                    Entities.LibrarySeat seat = null;
                    bool isInt = int.TryParse(args.q, out seatNumber);
                    if (isInt)
                    {
                        var seatList = _librarySeatRepository.Entities.Where(o => o.SeatNumber == seatNumber);
                        if (seatList.Count() > 0)
                        {
                            seat = seatList.First();
                        }
                    }
                    ;
                    if (user != null && seat != null)
                    {
                        query = query.Where(o => o.SysUserId == user.Id || o.LibrarySeatId == seat.Id);
                    }
                    else if (user != null)
                    {
                        query = query.Where(o => o.SysUserId == user.Id);
                    }
                    else if (seat != null)
                    {
                        query = query.Where(o => o.LibrarySeatId == seat.Id);
                    }
                }
                if (args.hascheckin.HasValue)
                {
                    query = query.Where(o => o.HasCheckIn == args.hascheckin);
                }
                if (args.hasend.HasValue)
                {
                    query = query.Where(o => o.HasEnd == args.hasend);
                }
            }
            query = from e in query orderby e.CreateTime descending select e;
            return(new PagedList <Entities.OrderDetail>(query, page, size));
        }
Example #8
0
        public IActionResult register(Entities.RegisterModel model)
        {
            if (_sysUserService.existAccount(model.Account))
            {
                AjaxData.Status  = false;
                AjaxData.Message = "该账号已存在";
                return(Json(AjaxData));
            }

            if (_sysUserService.existEmail(model.Email))
            {
                AjaxData.Status  = false;
                AjaxData.Message = "该邮箱已被注册";
                return(Json(AjaxData));
            }

            if (_sysUserService.existMobilePhone(model.MobilePhone))
            {
                AjaxData.Status  = false;
                AjaxData.Message = "该手机号码已被注册";
                return(Json(AjaxData));
            }


            Entities.SysUser user = new Entities.SysUser();
            user.Account     = model.Account;
            user.Name        = model.Name;
            user.Email       = model.Email;
            user.MobilePhone = model.MobilePhone;

            user.Id           = Guid.NewGuid();
            user.CreationTime = DateTime.Now;
            user.Salt         = EncryptorHelper.CreateSaltKey();
            user.Account      = user.Account.Trim();
            user.Enabled      = true;
            user.IsAdmin      = false;
            user.Password     = EncryptorHelper.GetMD5(model.Password + user.Salt);
            user.Creator      = user.Id;
            _sysUserService.insertSysUser(user);

            AjaxData.Status  = true;
            AjaxData.Message = "注册成功";

            return(Json(AjaxData));
        }
Example #9
0
 public ActionResult EditAccount(Entities.SysUser model, string returnUrl = null)
 {
     ViewBag.ReturnUrl = Url.IsLocalUrl(returnUrl) ? returnUrl : Url.RouteUrl("mainIndex");
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (!string.IsNullOrEmpty(model.MobilePhone))
     {
         model.MobilePhone = StringUitls.toDBC(model.MobilePhone);
     }
     model.Name         = model.Name.Trim();
     model.ModifiedTime = DateTime.Now;
     model.Modifier     = WorkContext.CurrentUser.Id;
     _sysUserService.updateSysUser(model);
     if (!string.IsNullOrEmpty(model.Password))
     {
         _sysUserService.changePassword(model.Id, model.Password);
     }
     return(Redirect(ViewBag.ReturnUrl));
 }
Example #10
0
        /// <summary>
        /// 私有方法,获取当前用户的方法数据
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private List <Entities.SysCategory> GetMyCategories(Entities.SysUser user)
        {
            var list = _sysCategoryService.getAll();

            if (user == null)
            {
                return(null);
            }
            if (user.IsAdmin)
            {
                return(list);
            }

            //获取权限数据
            var userRoles = _sysUserRoleService.getAll();

            if (userRoles == null || !userRoles.Any())
            {
                return(null);
            }
            var roleIds        = userRoles.Where(o => o.UserId == user.Id).Select(x => x.RoleId).Distinct().ToList();
            var permissionList = _sysPermissionServices.getAll();

            if (permissionList == null || !permissionList.Any())
            {
                return(null);
            }

            var categoryIds = permissionList.Where(o => roleIds.Contains(o.RoleId)).Select(x => x.CategoryId).Distinct().ToList();

            if (!categoryIds.Any())
            {
                return(null);
            }
            list = list.Where(o => categoryIds.Contains(o.Id)).ToList();
            return(list);
        }
Example #11
0
 public void DeleteAccount(Entities.SysUser account)
 {
     service.Remove(account);
 }
Example #12
0
 public void UpdateAccount(Entities.SysUser account)
 {
     service.Update(account);
 }
Example #13
0
 public void InsertAccount(Entities.SysUser account)
 {
     service.Add(account);
 }
Example #14
0
 public void updatePassword(Entities.SysUser model)
 {
     // _sysUserRepository.DbContext.Entry(model).State = EntityState.Unchanged;updateUsermessage
     _sysUserRepository.DbContext.Entry(model).Property("Password").IsModified = true;
     _sysUserRepository.DbContext.SaveChanges();
 }
Example #15
0
 void ISysUserService.updateSysUser(Entities.SysUser model)
 {
     _repository.Update(model);
 }
Example #16
0
 void ISysUserService.updateSysUser(Entities.SysUser model)
 {
     throw new NotImplementedException();
 }