Ejemplo n.º 1
0
        /// <summary>
        /// 找到上级任务负责人 如果上级是自己则继续向上找 直到找到非自己为止
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="user"></param>
        /// <returns>返回找到负责人的userId</returns>
        public int getTaskSuperior(int taskId, UserAuthSession user)
        {
            var task = SimpleDb.GetSingle(u => u.Id == taskId);

            if (task.ChargeUserId != user.UserId)
            {
                throw new Exception("您与选中任务无关联,无法提交");
            }

            while (true)
            {
                task = SimpleDb.GetSingle(u => u.Id == task.ParentId);

                if (task == null)
                {
                    break;
                }

                if (task.ChargeUserId != user.UserId)
                {
                    break;
                }
            }

            if (task == null)
            {
                throw new Exception("暂无可用上级,请联系管理员重新分配");
            }

            return(task.ChargeUserId);
        }
Ejemplo n.º 2
0
        public ProjectService(IHttpContextAccessor httpContextAccessor, ICacheContext cacheContext)
        {
            _httpContextAccessor = httpContextAccessor;
            _cacheContext        = cacheContext;

            string token = _httpContextAccessor.HttpContext.Request.Headers[Define.TOKEN_NAME];

            user = _cacheContext.Get <UserAuthSession>(token);
        }
Ejemplo n.º 3
0
        public ActionResult LoginAccess(string username, string password)
        {
            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(username))
            {
                ViewBag.ValidateInfo = "用户名或密码不能为空请重新登录";
                return(View("Login"));//new RedirectResult("/Admin/Account/Login");
            }
            UserBC     bc     = new UserBC();
            var        result = bc.GetUsers(username, password);
            UserEntity entity = new UserEntity();

            if (result != null && result.Count > 0)
            {
                entity = result.FirstOrDefault();
            }
            else
            {
                ViewBag.ValidateInfo = "用户名或密码错误请重新登录";
                ////用户名密码错误请重新登录
            }

            if (entity != null && !string.IsNullOrEmpty(entity.User_Id))
            {
                var currentSession = new UserAuthSession
                {
                    Id         = entity.User_Id,
                    Account    = entity.Login_Name,
                    Name       = entity.User_Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    CreateTime = DateTime.Now,
                    IpAddress  = HttpContext.Request.UserHostAddress,
                };


                CacheManager.Instance.CurrentUser = currentSession;
                //创建Session
                new ObjCacheProvider <UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddHours(1));
                var cookie = new HttpCookie("Token", currentSession.Token)
                {
                    Expires = DateTime.Now.AddHours(1)
                };
                HttpContext.Response.Cookies.Add(cookie);
                return(new RedirectResult("/Admin/Account/Index"));
            }
            else
            {
                ViewBag.ValidateInfo = "用户名或密码错误请重新登录";
                ////用户名密码错误请重新登录
            }

            // return new RedirectResult("/Admin/Account/Login");
            return(View("Login"));
        }
        public void Create(UserAuthSession model)
        {
            //添加Session
            DbContext.UserAuthSession.Add(model);
            DbContext.SaveChanges();

            //设置缓存
            CacheContext.Set(model.SessionKey, new SessionCacheItem
            {
                AppKey      = model.AppKey,
                InvalidTime = model.InvalidTime,
                UserName    = model.UserName
            });
        }
Ejemplo n.º 5
0
        private LoginResult Parse(PassportLoginRequest model)
        {
            //过滤字段无效字符
            model.Trim();

            var result = new LoginResult();

            //获取应用信息
            var appInfo = _appInfoService.Get(model.AppKey);

            if (appInfo == null)
            {
                result.Success  = false;
                result.ErrorMsg = "应用不存在";
            }
            TempData[AppInfo] = appInfo;

            //获取用户信息
            var userInfo = _appUserService.Get(model.UserName);

            if (userInfo == null)
            {
                result.Success  = false;
                result.ErrorMsg = "用户不存在";
            }

            //if (userInfo.UserPwd != model.Password.ToMd5())
            //{
            //    //密码不正确
            //    return View(model);
            //}

            var currentSession = new UserAuthSession
            {
                UserName    = model.UserName,
                Token       = Guid.NewGuid().ToString().ToMd5(),
                InvalidTime = DateTime.Now.AddMinutes(10),
                AppKey      = model.AppKey,
                CreateTime  = DateTime.Now,
                IpAddress   = Request.UserHostAddress
            };

            //创建Session
            new UserAuthSessionService().Create(currentSession);

            result.Success   = true;
            result.ReturnUrl = appInfo.ReturnUrl;
            result.Token     = currentSession.Token;
            return(result);
        }
Ejemplo n.º 6
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var    token  = "";
            string action = httpContext.Request.Url.ToString();

            if (action.ToLower().Contains("/public/"))
            {
                NeedLogin = false;
                return(true);
            }
            //Token by QueryString
            if (httpContext.Request.Cookies[ConstCommon.Token] != null)  //从Cookie读取Token
            {
                token = httpContext.Request.Cookies[ConstCommon.Token].Value;
            }
            bool Pass = false;

            try
            {
                if (string.IsNullOrEmpty(token))
                {
                    httpContext.Response.StatusCode = 401;//无权限状态码
                    Pass    = false;
                    IsLogin = false;
                }
                else
                {
                    //UserAuthSession userSession = objCacheProvider.GetCache(token);
                    this.userSession = objCacheProvider.GetCache(token);
                    if (this.userSession == null || string.IsNullOrEmpty(this.userSession.Token))
                    {
                        httpContext.Response.StatusCode = 401;//无权限状态码
                        Pass    = false;
                        IsLogin = false;
                    }
                    else
                    {
                        Pass    = true;
                        IsLogin = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Pass = false;
            }
            return(Pass);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 用户名密码登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public Response Login(string username, string password)
        {
            var result = new Response <string>();

            try
            {
                // 密码加密
                password = Md5.Encrypt(password);
                // 防sql注入
                username = Md5.avoidSqlInjection(username);

                var userInfo = SimpleDb.GetSingle(u => u.userName.Equals(username));

                if (userInfo == null)
                {
                    throw new Exception("用户不存在");
                }
                if (!Md5.Encrypt(userInfo.passWord).Equals(password))
                {
                    throw new Exception("密码不正确");
                }

                var currentSession = new UserAuthSession
                {
                    UserId       = userInfo.userId,
                    WechatUserId = userInfo.wechatUserId,
                    UserName     = userInfo.userName,
                    Token        = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    CreateTime   = DateTime.Now
                };

                _cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10));
                result.Result = currentSession.Token;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }

            return(result);
        }
Ejemplo n.º 8
0
        public ActionResult LogOff()
        {
            ObjCacheProvider <UserAuthSession> objCacheProvider = new ObjCacheProvider <UserAuthSession>();
            string token = string.Empty;

            //Token by QueryString

            if (HttpContext.Request.Cookies[ConstCommon.Token] != null)  //从Cookie读取Token
            {
                token = HttpContext.Request.Cookies[ConstCommon.Token].Value;
            }

            UserAuthSession userSession = objCacheProvider.GetCache(token);

            if (userSession != null && string.IsNullOrEmpty(userSession.Token))
            {
                objCacheProvider.Remove(userSession.Token);
            }
            return(new RedirectResult("/Admin/Account/Login"));
        }
Ejemplo n.º 9
0
        public ActionResult Index(PassportLoginRequest model)
        {
            //获取应用信息
            var appInfo = _appInfoService.Get(model.AppKey);

            if (appInfo == null)
            {
                //应用不存在
                return(View(model));
            }

            TempData[AppInfo] = appInfo;

            if (ModelState.IsValid == false)
            {
                //实体验证失败
                return(View(model));
            }

            //过滤字段无效字符
            model.Trim();

            //获取用户信息
            var userInfo = _appUserService.Get(model.UserName);

            if (userInfo == null)
            {
                //用户不存在
                return(View(model));
            }

            if (userInfo.UserPwd != model.Password.ToMd5())
            {
                //密码不正确
                return(View(model));
            }

            //获取当前未到期的Session
            var currentSession = _authSessionService.ExistsByValid(appInfo.AppKey, userInfo.UserName);

            if (currentSession == null)
            {
                //构建Session
                currentSession = new UserAuthSession
                {
                    AppKey      = appInfo.AppKey,
                    CreateTime  = DateTime.Now,
                    InvalidTime = DateTime.Now.AddYears(1),
                    IpAddress   = Request.UserHostAddress,
                    SessionKey  = Guid.NewGuid().ToString().ToMd5(),
                    UserName    = userInfo.UserName
                };

                //创建Session
                _authSessionService.Create(currentSession);
            }
            else
            {
                //延长有效期,默认一年
                _authSessionService.ExtendValid(currentSession.SessionKey);
            }

            //记录用户授权日志
            _userAuthOperateService.Create(new UserAuthOperate
            {
                CreateTime = DateTime.Now,
                IpAddress  = Request.UserHostAddress,
                Remark     = string.Format("{0} 登录 {1} 授权成功", currentSession.UserName, appInfo.Title),
                SessionKey = currentSession.SessionKey
            });

            var redirectUrl = string.Format("{0}?SessionKey={1}&SessionUserName={2}",
                                            appInfo.ReturnUrl,
                                            currentSession.SessionKey,
                                            userInfo.UserName);

            //跳转默认回调页面
            return(Redirect(redirectUrl));
        }
Ejemplo n.º 10
0
 public bool Create(UserAuthSession model)
 {
     //设置缓存
     return(CacheContext.Set(model.Token, model));
 }