public LoginQueryResponse LoginQuery(LoginQueryRequest request)
        {
            var response = new LoginQueryResponse();

            try
            {
                if (request == null || request.LoginName.IsNullOrEmpty() || request.Password.IsNullOrEmpty())
                {
                    response.IsSuccess   = false;
                    response.MessageCode = "1";
                    response.MessageText = "参数不能为空";
                    return(response);
                }

                request.Password = request.Password.GetMd5();


                response = _userinfoService.LoginQuery(request);
            }
            catch (System.Exception ex)
            {
                response.IsSuccess   = false;
                response.MessageCode = "-1";
                response.MessageText = "系统出错";
                LogManager.DefaultLogger.ErrorFormat("登录用户名出错:{0}", new { request, err = ex.ToString() }.ToJson());
            }

            return(response);
        }
예제 #2
0
        public ActionResult Login(LoginUserInfoModel model)
        {
            try
            {
                #region 验证验证码
                var vcode = SessionHelper.Get <string>("vcode");
                if (vcode.IsNullOrEmpty() || vcode != model.Code)
                {
                    return(Json(new { status = 1, msg = "验证码错误" }));
                }
                SessionHelper.RemoveSession("vcode");
                #endregion

                var request = new LoginQueryRequest
                {
                    LoginName = model.UserName,
                    Password  = model.PassWord.GetMd5()
                };

                var loginqueryresponse = _iuserinfoservice.LoginQuery(request);

                if (loginqueryresponse.UserInfoEntity == null)
                {
                    return(Json(new { status = 2, msg = "密码错误" }, JsonRequestBehavior.AllowGet));
                }

                #region 保存用户登录状态
                string identityValue = Guid.NewGuid().ToString("N");

                CookieHelper.Set(PublicConst.IdentityCookieKey, identityValue, true);

                var entity = loginqueryresponse.UserInfoEntity.As <AccountModel>();

                entity.Fingerprint = RequestHelper.Fingerprint;

                var key = identityValue.AddCachePrefix(PublicConst.IdentityCookieKey);

                CacheManager.RedisDefault.Set(key, entity, PublicConst.Time.Hour1);

                #region 记录用户操作日志
                _systemOperationLogService.AddOperationLog(new AddOperationLogRequest
                {
                    Content = string.Format("[LoginName:{0}]-[Name:{1}]-[Content:{2}]", entity.LoginName, entity.Name, "用户登录")
                });
                #endregion

                #endregion

                return(Json(new { status = 0 }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogManager.DefaultLogger.ErrorFormat("登录出错:{0}", new { model, err = ex.ToString() }.ToJson());
                return(Json(new { status = -1, msg = "系统出错!" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
        /// <summary>
        /// 登录查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public LoginQueryResponse LoginQuery(LoginQueryRequest request)
        {
            var response = new LoginQueryResponse();

            try
            {
                var entity = _userInfoRepository.Find <UserInfoPo>(
                    e => e.IsValid == 1 &&
                    (e.LoginName == request.LoginName || e.Email == request.LoginName) &&
                    e.Password == request.Password);

                response.UserInfoEntity = entity.As <UserInfoDto>();
            }
            catch (Exception ex)
            {
                response.IsSuccess   = false;
                response.MessageCode = "-1";
                response.MessageText = ex.Message;
                LogManager.LogicLogger.ErrorFormat("登录查询出错:{0}", new { request, err = ex.ToString() }.ToJson());
            }
            return(response);
        }
예제 #4
0
        public ActionResult Login(LoginUserInfoModel model)
        {
            try
            {
                #region 验证验证码登陆错误次数
                var loginkey = model.UserName + RequestHelper.Ip;
                var loginnum = int.Parse(CacheManager.RunTimeCache.Get(loginkey) ?? "0");

                if (loginnum >= ConfigHelper.GetConfigInt("MaxNumberErrorLogin"))
                {
                    return(Json(new { status = 5, msg = "错误登陆次数超过上限" }, JsonRequestBehavior.AllowGet));
                }
                #endregion

                #region 验证验证码
                var vcode = SessionHelper.Get("vcode").IsNullToString();
                if (vcode.IsNullOrEmpty() || vcode != model.Code)
                {
                    return(Json(new { status = 1, msg = "验证码错误" }));
                }
                SessionHelper.Remove("vcode");
                #endregion

                #region 验证用户名密码
                var request = new LoginQueryRequest
                {
                    LoginName = model.UserName,
                    Password  = model.PassWord.GetMd5()
                };

                var response = _iuserinfoservice.LoginQuery(request);

                if (!response.IsSuccess)
                {
                    return(Json(new { status = 4, msg = "登录出错!" }, JsonRequestBehavior.AllowGet));
                }

                if (response.UserInfoEntity == null)
                {
                    //记录ip地址、用户名登陆次数
                    CacheManager.RunTimeCache.Set(loginkey, (loginnum + 1).ToString(), PublicConst.Time.Day1);
                    return(Json(new { status = 2, msg = "密码错误" }, JsonRequestBehavior.AllowGet));
                }
                CacheManager.RunTimeCache.Remove(loginkey);
                #endregion

                #region 保存用户登录状态
                string identityValue = Guid.NewGuid().ToString("N");

                CookieHelper.Set(PublicConst.IdentityCookieKey, identityValue, true);

                var entity = response.UserInfoEntity.As <AccountModel>();

                entity.Fingerprint = RequestHelper.Fingerprint;

                var key = identityValue.AddCachePrefix(PublicConst.IdentityCookieKey);

                CacheManager.RedisDefault.Set(key, entity, PublicConst.Time.Hour1);

                #region 只允许一个客户端登录
                //var k = entity.Id.ToString().AddCachePrefix("LoginBind");

                //var v = CacheManager.RedisDefault.Get(k);

                //if (!string.IsNullOrEmpty(v))
                //{
                //	CacheManager.RedisDefault.Remove(v.AddCachePrefix(PublicConst.IdentityCookieKey));
                //}

                //CacheManager.RedisDefault.Set(k, identityValue, PublicConst.Time.Hour1);
                #endregion

                #region 记录用户操作日志
                _systemOperationLogService.AddOperationLog(new AddOperationLogRequest
                {
                    Content = string.Format("[LoginName:{0}]-[Name:{1}]-[Content:{2}]", entity.LoginName, entity.Name, "用户登录")
                });
                #endregion

                #endregion

                return(Json(new { status = 0 }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogManager.DefaultLogger.ErrorFormat("登录出错:{0}", new { model, err = ex.ToString() }.ToJson());
                return(Json(new { status = -1, msg = "系统出错!" }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #5
0
 public LoginQueryResponse LoginQuery(LoginQueryRequest request)
 {
     return(_userinfoService.LoginQuery(request));
 }