예제 #1
0
        public IActionResult GetInfo()
        {
            CommonResult        result              = new CommonResult();
            YuebonCacheHelper   yuebonCacheHelper   = new YuebonCacheHelper();
            SysSetting          sysSetting          = yuebonCacheHelper.Get("SysSetting").ToJson().ToObject <SysSetting>();
            SysSettingOutputDto sysSettingOutputDto = new SysSettingOutputDto();

            if (sysSetting == null)
            {
                sysSetting = XmlConverter.Deserialize <SysSetting>("xmlconfig/sys.config");
            }
            sysSetting.Email         = "";
            sysSetting.Emailsmtp     = "";
            sysSetting.Emailpassword = "";
            sysSetting.Smspassword   = "";
            sysSetting.SmsSignName   = "";
            sysSetting.Smsusername   = "";
            sysSettingOutputDto      = sysSetting.MapTo <SysSettingOutputDto>();
            if (sysSettingOutputDto != null)
            {
                sysSettingOutputDto.CopyRight = UIConstants.CopyRight;
                result.ResData = sysSettingOutputDto;
                result.Success = true;
                result.ErrCode = ErrCode.successCode;
            }
            else
            {
                result.ErrMsg  = ErrCode.err60001;
                result.ErrCode = "60001";
            }

            IEnumerable <APP> appList = aPPService.GetAllByIsNotDeleteAndEnabledMark();

            yuebonCacheHelper.Add("AllowAppId", appList);
            return(ToJsonContent(result));
        }
예제 #2
0
        public async Task <IActionResult> GetCheckUser(string username, string password, string vcode, string vkey, string appId, string systemCode)
        {
            CommonResult      result            = new CommonResult();
            RemoteIpParser    remoteIpParser    = new RemoteIpParser();
            string            strIp             = remoteIpParser.GetClientIp(HttpContext).MapToIPv4().ToString();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            var    vCode = yuebonCacheHelper.Get("ValidateCode" + vkey);
            string code  = vCode != null?vCode.ToString() : "11";

            if (vcode.ToUpper() != code)
            {
                result.ErrMsg = "验证码错误";
                return(ToJsonContent(result));
            }
            Log  logEntity = new Log();
            bool blIp      = _filterIPService.ValidateIP(strIp);

            if (blIp)
            {
                result.ErrMsg = strIp + "该IP已被管理员禁止登录!";
            }
            else
            {
                if (string.IsNullOrEmpty(username))
                {
                    result.ErrMsg = "用户名不能为空!";
                }
                else if (string.IsNullOrEmpty(password))
                {
                    result.ErrMsg = "密码不能为空!";
                }
                if (string.IsNullOrEmpty(systemCode))
                {
                    result.ErrMsg = ErrCode.err40006;
                }
                else
                {
                    string strHost = Request.Host.ToString();
                    APP    app     = _appService.GetAPP(appId);
                    if (app == null)
                    {
                        result.ErrCode = "40001";
                        result.ErrMsg  = ErrCode.err40001;
                    }
                    else
                    {
                        if (!app.RequestUrl.Contains(strHost, StringComparison.Ordinal) && !strHost.Contains("localhost", StringComparison.Ordinal))
                        {
                            result.ErrCode = "40002";
                            result.ErrMsg  = ErrCode.err40002 + ",你当前请求主机:" + strHost;
                        }
                        else
                        {
                            SystemType systemType = _systemTypeService.GetByCode(systemCode);
                            if (systemType == null)
                            {
                                result.ErrMsg = ErrCode.err40006;
                            }
                            else
                            {
                                Tuple <User, string> userLogin = await this._userService.Validate(username, password);

                                if (userLogin != null)
                                {
                                    string ipAddressName = IpAddressUtil.GetCityByIp(strIp);
                                    if (userLogin.Item1 != null)
                                    {
                                        result.Success = true;
                                        User              user           = userLogin.Item1;
                                        JwtOption         jwtModel       = App.GetService <JwtOption>();
                                        TokenProvider     tokenProvider  = new TokenProvider(jwtModel);
                                        TokenResult       tokenResult    = tokenProvider.LoginToken(user, appId);
                                        YuebonCurrentUser currentSession = new YuebonCurrentUser
                                        {
                                            UserId         = user.Id,
                                            Name           = user.RealName,
                                            AccessToken    = tokenResult.AccessToken,
                                            AppKey         = appId,
                                            CreateTime     = DateTime.Now,
                                            Role           = _roleService.GetRoleEnCode(user.RoleId),
                                            ActiveSystemId = systemType.Id,
                                            CurrentLoginIP = strIp,
                                            IPAddressName  = ipAddressName
                                        };
                                        TimeSpan expiresSliding = DateTime.Now.AddMinutes(120) - DateTime.Now;
                                        yuebonCacheHelper.Add("login_user_" + user.Id, currentSession, expiresSliding, true);

                                        List <AllowCacheApp> list = yuebonCacheHelper.Get("AllowAppId").ToJson().ToList <AllowCacheApp>();
                                        if (list.Count == 0)
                                        {
                                            IEnumerable <APP> appList = _appService.GetAllByIsNotDeleteAndEnabledMark();
                                            yuebonCacheHelper.Add("AllowAppId", appList);
                                        }
                                        CurrentUser    = currentSession;
                                        result.ResData = currentSession;
                                        result.ErrCode = ErrCode.successCode;
                                        result.Success = true;

                                        logEntity.Account       = user.Account;
                                        logEntity.NickName      = user.NickName;
                                        logEntity.Date          = logEntity.CreatorTime = DateTime.Now;
                                        logEntity.IPAddress     = CurrentUser.CurrentLoginIP;
                                        logEntity.IPAddressName = CurrentUser.IPAddressName;
                                        logEntity.Result        = true;
                                        logEntity.ModuleName    = "登录";
                                        logEntity.Description   = "登录成功";
                                        logEntity.Type          = "Login";
                                        _logService.Insert(logEntity);
                                    }
                                    else
                                    {
                                        result.ErrCode          = ErrCode.failCode;
                                        result.ErrMsg           = userLogin.Item2;
                                        logEntity.Account       = username;
                                        logEntity.Date          = logEntity.CreatorTime = DateTime.Now;
                                        logEntity.IPAddress     = strIp;
                                        logEntity.IPAddressName = ipAddressName;
                                        logEntity.Result        = false;
                                        logEntity.ModuleName    = "登录";
                                        logEntity.Type          = "Login";
                                        logEntity.Description   = "登录失败," + userLogin.Item2;
                                        _logService.Insert(logEntity);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            yuebonCacheHelper.Remove("LoginValidateCode");
            return(ToJsonContent(result, true));
        }