Пример #1
0
        public async Task <IActionResult> Login(LoginInfoModel loginInfo)
        {
            _logger.LogInformation($"用户登录{JsonConvert.SerializeObject(loginInfo)}");
            ResponseResult responseResult = new ResponseResult(false, "未执行!");

            try
            {
                loginInfo.VerifyCode = new VerifyCodeModel()
                {
                    Id   = string.Empty,
                    Code = string.Empty
                };

                var result = await _authServiceClient.Login(loginInfo);

                if (result.Code.Equals(ResultEnum.SUCCESS))
                {
                    ////登陆
                    CurrentUserManage.Login(result.Result);
                }
                else
                {
                    responseResult.Message = result.Message;
                }

                responseResult.Message = "登陆成功!";
                responseResult.Code    = ResultEnum.SUCCESS;
            }
            catch (Exception ex)
            {
                responseResult.Message = ex.Message;
            }

            return(Json(responseResult));
        }
Пример #2
0
        public ResponseResult Login(LoginInfo loginInfo)
        {
            ResponseResult responseResult = new ResponseResult(false, "未执行!");

            try
            {
                //第一步:处理验证码
                string sessionVerCode = SessionHelper.Session[APPKeys.Vercode].ToString();

                //取完后要删除,不然Session里还有
                SessionHelper.Session[APPKeys.Vercode] = string.Empty;
                if (string.IsNullOrWhiteSpace(sessionVerCode) || !sessionVerCode.Equals(loginInfo.Vercode))
                {
                    throw new Exception("验证码错误!");
                }

                //第二部:处理验证用户名密码

                //lambda表达式不能进行强制类型转换
                int         status = (int)Status.On;
                SysUserInfo user   = _sysUserInfoRepository.GetList(u =>
                                                                    u.ULoginName.Equals(loginInfo.ULoginName) && u.Status == status)
                                     .FirstOrDefault();
                if (user == null)
                {
                    throw new Exception("用户不存在或已被禁用!");
                }

                var aa = loginInfo.ULoginPwd.ToMD5String();
                if (!loginInfo.ULoginPwd.ToMD5String().Equals(user.ULoginPWD))
                {
                    throw new Exception("密码错误!");
                }
                //登陆
                CurrentUserManage.Login(user);
                responseResult.Message = "登陆成功!";
                responseResult.Success = true;
            }
            catch (Exception ex)
            {
                responseResult.Message = ex.Message;
            }

            return(responseResult);
        }
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"发送请求 {request.RequestUri } ");

            //处理请求
            request.Headers.Add("x-guid", Guid.NewGuid().ToString());//可以添加

            if (CurrentUserManage.IsLogin())
            {
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", CurrentUserManage.UserInfo.AccessToken);
            }
            var result = await base.SendAsync(request, cancellationToken); //调用内部handler 不调用的话就不真正发送请求

            _logger.LogInformation(result.ToString());
            //HttpContextCore.Current.Response.Clear();
            //HttpContextCore.Current.Response.WriteAsync("<script language=\"javascript\">self.location='Account/Login';</script>");
            //处理响应
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 统一登陆验证Session【APPKeys.CurrentUser】
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //如果是本地测试模式,不需要校验
            if (GlobalSwitch.RunModel == RunModel.LocalTest)
            {
                return;
            }
            //判断是否需要跳过校验
            bool isSkipCheckLogin = context.ActionDescriptor.EndpointMetadata.Any(a => a.GetType() == typeof(SkipCheckLogin));

            //1.判断 如果没有登陆并且 需要验证登陆的,则跳转到登陆页面
            if (!CurrentUserManage.IsLogin() && !isSkipCheckLogin)
            {
                //2.跳转到登陆页面
                context.Result = new ViewResult()
                {
                    ViewName = "/Views/Shared/Tip.cshtml"
                };
            }
        }
Пример #5
0
        /// <summary>
        /// 统一登陆验证Session【APPKeys.CurrentUser】
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //如果是本地测试模式,不需要校验
            if (GlobalSettings.LyAdminOptions.RunModel == RunModelEnum.LocalTest)
            {
                return;
            }
            //判断是否需要跳过校验
            bool isSkipCheckLogin = context.ActionDescriptor.EndpointMetadata.Any(a => a.GetType() == typeof(SkipCheckLoginAttribute));

            //1.判断 如果没有登陆并且 需要验证登陆
            if (!CurrentUserManage.IsLogin() && !isSkipCheckLogin)
            {
                //2.1 Ajax请求 返回
                if (context.HttpContext.Request.IsAjaxRequest())
                {
                    ResponseResult responseResult = new ResponseResult(false, "抱歉,没有登录或登录已超时!");
                    context.Result = new JsonResult(responseResult);
                    return;
                }
                //2.2  跳转到登陆页面
                context.Result = new RedirectResult("~/Account/Login");
            }
        }
Пример #6
0
        public ResponseResult GetUserInfoByInfo(string loginInfoULoginName, string loginInfoULoginPwd)
        {
            ResponseResult responseResult = new ResponseResult(false, "登录失败!");

            try
            {
                MySqlHelper mySqlHelper = new MySqlHelper();
                string      strSql      = "SELECT * FROM sysuserinfo WHERE ULoginName =@ULoginName AND Status = 0";
                SysUserInfo sysUser     = mySqlHelper.QueryEntity <SysUserInfo>(strSql, CommandType.Text, new MySqlParameter("@ULoginName", MySqlDbType.VarChar, 20)
                {
                    Value = loginInfoULoginName
                });
                if (sysUser != null)
                {
                    if (sysUser.ULoginPWD.Equals(loginInfoULoginPwd.ToMD5String()))
                    {
                        responseResult.Success = true;
                        responseResult.Message = "登录成功!";
                        CurrentUserManage.Login(sysUser);
                    }
                    else
                    {
                        responseResult.Message = "密码错误";
                    }
                }
                else
                {
                    responseResult.Message = "用户名不存在或已禁用!";
                }
            }
            catch (Exception ex)
            {
                responseResult.Message = ex.Message;
            }
            return(responseResult);
        }
Пример #7
0
 public IActionResult Logout()
 {
     CurrentUserManage.Logout();
     return(View("Index"));
 }