Example #1
0
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        //Shared.Clear();

        MainUrl = System.Configuration.ConfigurationManager.AppSettings["MAIN_URL"];
        var str = System.Configuration.ConfigurationManager.AppSettings["PageItemLimit"];

        if (!string.IsNullOrEmpty(str))
        {
            this.PageItemLimit = int.Parse(str);
        }

        //string controller = System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
        string action = System.Web.HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString().ToLower();

        if (action != "logout" && action != "login")
        {
            var entity = Shared.GetUserLogon();
            if (entity != null)
            {
                this.UserLogon      = entity;
                this.UserPermission = new Authen().GetPermission(entity.UserCode);
            }
        }


        base.Initialize(requestContext);
    }
        public override Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context)
        => Task.Run(() =>
        {
            //potential bug: capturing this datacontext is dangerous because if the cache gets invalidated and this logon is requested,
            //the datacontext will MOST LIKELY be disposed when it is queried for the logon.
            //The solution is to find a way to get at the current owin context, to get a fresh db context from there.
            var _dataContext = context.OwinContext.GetPerRequestValue <IDataContext>(nameof(IDataContext));

            //cache the logon associated to the given token
            _cache.GetOrAdd(context.AccessToken, _token =>
            {
                var agent = Parser.Parse(context.Request.Headers.Get("User-Agent"));

                var _l = _dataContext.Store <UserLogon>()
                         .QueryWith(_ul => _ul.User)
                         .Where(_ul => _ul.User.EntityId == context.Identity.Name)
                         .Where(_ul => _ul.OwinToken == _token) //get the bearer token from the header
                         .FirstOrDefault();

                if (_l != null)
                {
                    return(_l);
                }
                else
                {
                    _l = new UserLogon
                    {
                        UserId = context.Identity.Name,
                        Client = new Core.Models.UserAgent
                        {
                            OS        = agent.OS.Family,
                            OSVersion = $"{agent.OS.Major}.{agent.OS.Minor}",

                            Browser        = agent.UserAgent.Family,
                            BrowserVersion = $"{agent.UserAgent.Major}.{agent.UserAgent.Minor}",

                            Device = $"{agent.Device.Family}"
                        },
                        OwinToken = _token,
                        Location  = null,

                        ModifiedOn = DateTime.Now
                    };

                    _dataContext.Store <UserLogon>().Add(_l).Context.CommitChanges();

                    return(_l);
                }
            });
        });
Example #3
0
    public static void OnPacket(object pack)
    {
        Debug.Log("OnPacket_UserLogon");
        UserLogon userLogon = pack as UserLogon;

        if (userLogon.ErrorCode == 0)
        {
            Debug.Log("Logon Succeed");
            Gamedata.me.userinfo = userLogon.UserInfo;
            PanelManager.me.Get((int)PanelId.PanelLogon).Hide();
            PanelManager.me.Get((int)PanelId.PanelMain).Show();
            Debug.Log(userLogon.UserInfo.HeroList.Count);
            Debug.Log(userLogon.UserInfo.HeroList[0].Id);
            Debug.Log(userLogon.UserInfo.HeroList[1].Id);
        }
        else if (userLogon.ErrorCode == 1)
        {
            Debug.Log("Logon Failed.");
        }
    }
Example #4
0
        public static void OnPacket(Client client, object pack)
        {
            ReqLogon  req       = pack as ReqLogon;
            UserLogon userLogon = new UserLogon();

            userLogon.UserInfo  = UserSystem.me.GetByUsernameAndPassword(req.Username, req.Password);
            userLogon.ErrorCode = userLogon.UserInfo != null ? 0 : 1;
            if (userLogon.ErrorCode == 0)
            {
                userLogon.UserInfo.HeroList = HeroSystem.me.AllHeros(userLogon.UserInfo.Id);
            }
            client.Send(userLogon);
            return;

            //string cmd = String.Format("SELECT * FROM `user` WHERE Username='******'", "test0");
            //MySqlDataReader reader = Database.me.ExecQuery(cmd);
            //if (reader.Read())
            ////if (reader.NextResult())
            //{
            //    client.SetStatus(Client.Status.InHall);
            //    client.userid = ++Client.userIdCounter;
            //    UserLogon userLogon = new UserLogon();
            //    userLogon.UserId = client.userid;
            //    userLogon.UserInfo = new UserInfo();
            //    userLogon.UserInfo.Id = 0;
            //    userLogon.UserInfo.Username = reader.GetString("Username");
            //    userLogon.UserInfo.Coin = 11;
            //    userLogon.UserInfo.Diamond = 12;
            //    userLogon.UserInfo.Vigour = 13;
            //    userLogon.UserInfo.VipLevel = 14;
            //    userLogon.UserInfo.TeamLevel= 15;
            //    userLogon.UserInfo.BattlePower = 16;


            //    userLogon.UserInfo.Coin = 12;

            //    client.Send(userLogon);
            //}
            //reader.Close();
        }
Example #5
0
 public data_mysql(UserLogon logon)
 {
     base._logon = logon;
 }
Example #6
0
 public UserLogonEventArgs(UserLogon ulogon)
 {
     userlogon = ulogon;
 }
Example #7
0
 public LogonDialog(UserLogon defaultLogon) : this()
 {
     ProvideLogon = defaultLogon;
 }