public void UpdateUserLoginHistory(string userId, string loginFrom, string loginIp, DateTime loginTime)
        {
            #region "20180331 增加"
            List <UserLoginHistoryInfo> arr = new BlogManager().QueryBlog_UserLoginHistory(userId);//默认取最新的10条出来
            if (arr != null && arr.Count > 0)
            {
                foreach (var item in arr)
                {
                    //登录日志记录太多 每天同一个ip只记录一条即可
                    if (loginTime.ToString("yyyy-MM-dd") == item.LoginTime.ToString("yyyy-MM-dd") && item.LoginIp == loginIp)
                    {
                        //更新最新一次登陆时间
                        new BlogManager().UpdateBlog_UserLoginHistory(new E_Blog_UserLoginHistory {
                            LoginIp = loginIp, LoginTime = loginTime, LoginFrom = loginFrom, IpDisplayName = item.IpDisplayName, UserId = userId, Id = item.Id
                        });
                        return;
                    }
                }
            }
            #endregion
            string IpDisplayName = "未知";
            try
            {
                IpDisplayName = IpManager.GetIpDisplayname_Sina(loginIp).ToString();
            }
            catch
            {
            }
            new BlogManager().AddBlog_UserLoginHistory(new E_Blog_UserLoginHistory {
                LoginIp = loginIp, LoginTime = loginTime, LoginFrom = loginFrom, IpDisplayName = IpDisplayName, UserId = userId
            });

            //List<UserLoginHistoryInfo> arr = new BlogManager().QueryBlog_UserLoginHistory(userId);
        }
Beispiel #2
0
    public void AutoLogin()
    {
        this.m_isAutoLogin = true;
        IpManager.InitServiceConfig(m_ip, 8000);

        ConnectToServer();
    }
Beispiel #3
0
 public void ResetConnect()
 {
     ResponseHandleInvoker.Instance.ClearResponseQueue();
     ResponseHandleInvoker.Instance.IsPaused = false;
     HeartFPSManager.Instance.Clear();
     IpManager.InitServiceConfig();
     ServiceManager.DestorySockets();
     SingletonManager.Instance.Clear();
     NotifyManager.ClearEvents();
     ResetTaskInstance();
     RegisterEventHandler();
     UI.MainUI.EnegryColdWorkData.Instance.ResetEventHadels();
 }
Beispiel #4
0
 private async Task ApplyResponseRequest()
 {
     if (!long.TryParse(DatKey, out var key))
     {
         throw new BBSErrorException(BBSErrorType.BBSInvalidThreadKeyError);
     }
     var clientResponse = new ClientResponse()
     {
         Body = Body, Name = Name, Mail = Mail
     };
     await clientResponse.CreateResponseAsync(BoardKey, key,
                                              IpManager.GetHostName(_connectionInfo, _headers), _context, _dependency, _sessionManager.Session,
                                              true);
 }
Beispiel #5
0
            private async Task ApplyThreadRequest()
            {
                var clientThread = new ClientThread()
                {
                    Title    = Title,
                    Response = new ClientResponse()
                    {
                        Body = Body, Mail = Mail, Name = Name
                    }
                };
                var ip = IpManager.GetHostName(_connectionInfo, _headers);

                await clientThread.CreateThreadAsync(BoardKey, ip, _context, _dependency, _sessionManager.Session);
            }
Beispiel #6
0
    /// <summary>
    /// 发起服务器连接,等待服务器登录随机数返回,在LodginUIPanel里监听S_CEnterCode消息,S_CEnterCodeHandle处理。
    /// </summary>
    /// <returns><c>true</c>, if to server was connected, <c>false</c> otherwise.</returns>
    /// <param name="selectedServer">Selected server.</param>
    public bool ConnectToServer(Server selectedServer)
    {
        bool flag = false;

        IpManager.InitServiceConfig(selectedServer.IP, selectedServer.Port);

        flag = NetServiceManager.Instance.LoginService.ConnectToServer() == SERVICE_CODE.SUCCESS;
        if (flag)
        {
            PlayerPrefs.SetString("ServerIP", selectedServer.IP);
            PlayerPrefs.SetInt("ServerPort", selectedServer.Port);
        }
        return(flag);
    }
Beispiel #7
0
        private void ConnectToServer(string ip)
        {
            IpManager.InitServiceConfig(ip, 8000);

            bool connectStatus = NetServiceManager.Instance.LoginService.ConnectToServer() == SERVICE_CODE.SUCCESS;

            if (connectStatus)
            {
                this.Input_Msg.text = "";
                PlayerPrefs.SetString("ServerIP", ip);
            }
            else
            {
                this.Input_Msg.text = "服务器连接失败";
            }
        }
        public async Task <IActionResult> CreateThread([FromRoute] string boardKey, [FromBody] ClientThread thread)
        {
            try
            {
                var sess = new SessionManager(HttpContext, Context);

                var ip     = IpManager.GetHostName(HttpContext.Connection, HttpContext.Request.Headers);
                var result = await thread.CreateThreadAsync(boardKey, ip, Context, PluginDependency, sess.Session);

                await sess.UpdateSession();

                return(CreatedAtAction(nameof(GetThread), new { id = result.ThreadId }, result));
            }
            catch (BBSErrorException e)
            {
                var error = e.BBSError;
                return(StatusCode(error.ResponseCode, error));
            }
        }
Beispiel #9
0
        public async Task <IActionResult> Index()
        {
            using var sr = new StreamReader(Request.Body);
            BbsCgiRequest req         = null;
            string        hostAddress = IpManager.GetHostName(HttpContext.Connection, HttpContext.Request.Headers);
            var           str         = await sr.ReadToEndAsync();

            try
            {
                var sess = new SessionManager(HttpContext, _context);

                req = new BbsCgiRequest(str, _context, HttpContext.Connection, HttpContext.Request.Headers, _pluginDependency, sess);
                await sess.UpdateSession();

                await req.ApplyRequest();
            }
            catch (BBSErrorException e)
            {
                // OKなの腹立つわ (5chの仕様)
                return(Ok(FormatErrorText(e.BBSError, req?.BoardKey, req?.Name, req?.Mail, req?.Body, hostAddress)));
            }

            return(Ok(OkString));
        }
Beispiel #10
0
        public async Task <JsonResult> LoginFunction(LoginViewModel model, string returnUrl)
        {
            CommonResult r = new CommonResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Values.Select(p => p.Errors);
                    var list   = errors.Select(p =>
                    {
                        return(string.Join(",", p.Select(e => e.ErrorMessage)));
                    });
                    r.code    = (int)ResultCodeEnum.VerifyError;
                    r.message = string.Join(",", list);
                    return(Json(r));
                }

                string value = GetCookieValue("ValidateCodeCount");
                int    i     = string.IsNullOrEmpty(value) ? 0 : Convert.ToInt32(value);
                if (i >= 3)
                {
                    throw new Exception("验证码连续输错3次,请一个小时后在登录!");
                }
                if (Session["ValidateCode"] == null || Session["ValidateCode"].ToString() != model.VerifyCode)
                {
                    ModCookies("ValidateCodeCount", (++i).ToString());
                    throw new Exception("验证码输入错误!");
                }
                else
                {
                    DelCookeis("ValidateCodeCount");
                }

                // 这不会计入到为执行帐户锁定而统计的登录失败次数中
                // 若要在多次输入错误密码的情况下触发帐户锁定,请更改为 shouldLockout: true
                var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

                switch (result)
                {
                case SignInStatus.Success:
                    try
                    {
                        var ipAddr = IpManager.IPAddress;
                        var user   = UserManager.FindByName(model.UserName);
                        Task.Factory.StartNew(() =>
                        {
                            var ip = IpManager.GetIpDisplayname_Amap(ipAddr, null);
                            new AdminLoginHistoryManager().AddLoginHistory(new AdminLoginHistory()
                            {
                                CreationDate = DateTime.Now,
                                Ip           = ipAddr,
                                IpArea       = ip == null ? "Unknown" : ip.ToString(),
                                LoginTime    = DateTime.Now,
                                UserId       = user.Id
                            });
                        });
                    }
                    catch
                    {
                    }
                    return(Json(r));

                case SignInStatus.LockedOut:
                    r.code    = (int)ResultCodeEnum.UserLockout;
                    r.message = "账户被锁";
                    return(Json(r));

                case SignInStatus.RequiresVerification:
                    r.code    = (int)ResultCodeEnum.VerifyError;
                    r.message = "账户要求验证";
                    return(Json(r));

                case SignInStatus.Failure:
                default:
                    r.code    = (int)ResultCodeEnum.SystemError;
                    r.message = "账号或密码不对";
                    return(Json(r));
                }
            }
            catch (Exception ex)
            {
                r.code    = (int)ResultCodeEnum.SystemError;
                r.message = ex.Message;
                return(Json(r));
            }
        }
 static void Main(string[] args)
 {
     IpManager ipManager = new IpManager();
 }
Beispiel #12
0
    public override void SaveResponseHandleToInvoke(byte[] dataBuffer, int socketId, byte cmdtype)
    {
        try
        {
            Package       package;
            MasterMsgType masterMsgType = (MasterMsgType)cmdtype;
            package = PackageHelper.ParseReceiveData(dataBuffer);
            switch (masterMsgType)
            {
            case MasterMsgType.NET_ROOT_LOGIN:
                switch (package.GetSubMsgType())
                {
                //S发送登录随机数到C
                case RootDefineManager.ROOTLOGIN_SC_MAIN_ENTERCODE:
                    AddToInvoker(this.ReceiveEnterCode, dataBuffer, socketId);
                    break;

                //S发送角色信息到C
                case RootDefineManager.ROOTLOGIN_SC_MAIN_LOGINRES:
                    //if (GameManager.Instance.IsLogin91Version)
                {
                    AddToInvoker(this.NewReceiveLoginRes, dataBuffer, socketId);
                }
                    //else
                    //{
                    //    AddToInvoker(this.ReceiveLoginRes, dataBuffer, socketId);
                    //}
                    break;

                default:
                    //TraceUtil.Log("NET_ROOT_LOGIN:"******"NET_ROOT_SELECTACTOR:" + package.GetSubMsgType());
                    break;
                }
                break;

            default:
                //TraceUtil.Log("不能识别的主消息:" + package.GetMasterMsgType());
                break;
            }
        }
        catch (Exception e)
        {
            TraceUtil.Log(SystemModel.Common, TraceLevel.Error, e.ToString());
        }
    }