Exemplo n.º 1
0
        protected void GetAuthToken(OfficerToken token, string key, string newKey, string ip)
        {
            AuthenticateTokenMapDao _authenMap = new AuthenticateTokenMapDao();
            AuthenticateToken       Obj        = new AuthenticateToken();


            //_authenMap.AddOrUpdate(Obj);

            var objToken = _authenMap.FindActiveByAPIKey(key).ToList();

            foreach (var Items in objToken)
            {
                Items.Active = false;
                _authenMap.AddOrUpdate(Items);
                _authenMap.CommitChange();
            }
            //if (objToken.Count() > 0)
            //{
            //    //disable token
            //    foreach (var item in objToken)
            //    {
            //        if (item.Owner_ip == ip && Convert.ToDateTime(item.Process_date).AddMinutes(item.Process_time) > DateTime.Now)
            //        {
            //            token.Token_id = Encryption.Encrypt(item.Keygen);
            //        }
            //        else
            //        {
            //            item.Active = false;
            //            _authenMap.AddOrUpdate(item);
            //            _authenMap.CommitChange();
            //        }
            //    }
            //}

            //if (string.IsNullOrEmpty(token.Token_id))
            //{



            var authen = new AuthenticateToken(key, newKey, ip);

            _authenMap.AddOrUpdate(authen);
            _authenMap.CommitChange();
            token.Token_id = MyExtensions.ParamEncode(new { authen.ApiKey, Process_date = authen.Process_date.ToThaiFormateAndtime(), authen.Process_time, authen.Keygen });
            //token   =
            //}

            //_authenMap = null;
        }
Exemplo n.º 2
0
        private void _ReleaseToken(string tokenId)
        {
            if (string.IsNullOrEmpty(tokenId))
            {
                result = falseresult("UnAuthorized...");
            }

            // string key = Encryption.Decrypt(tokenId); //new key
            AuthenticateTokenMapDao _authenMap = new AuthenticateTokenMapDao();

            if (!IsValidateToken(tokenId))
            {
                result = falseresult("UnAuthorized.");
            }

            try
            {
                var objToken = _authenMap.FindByKeygen(TokenValid.Keygen).ToList();
                if (objToken.Count() > 0)
                {
                    //disable token
                    foreach (var item in objToken)
                    {
                        item.Active = false;
                        _authenMap.AddOrUpdate(item);
                        _authenMap.CommitChange();

                        SaveUtility.SaveTransactionLog(item.Keygen, "Release Token", SaveUtility.TransStatus.Create, tokenId, item.Owner_ip, "s");
                    }
                }
            }
            catch (Exception ex)
            {
                SaveUtility.logError(ex);
                result = falseresult(ex.Message);
            }
            finally
            {
                _authenMap = null;
            }

            result = Trueresult("OK");
            HttpContext.Current.Response.ContentType = "application/json";
            HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
            HttpContext.Current.Response.End();
        }