Пример #1
0
        public static AddSuserResult AddSuser(string suser, string pwd)
        {
            Suser suserObject;
            bool  registered;

            string pwdHash = Suser.SecurePassword(pwd);

            if (!Suser.IsSuserNameAllowed(suser))
            {
                return(AddSuserResult.HasNotAllowedChar);
            }

            if (suser.Length < 3 || suser.Length > 32)
            {
                return(AddSuserResult.TooLongOrShort);
            }

            suserObject = new Suser(0, suser, pwdHash);

            if (SozlukDataStore.AddSuser(suserObject, out registered))
            {
                if (!registered)
                {
                    return(AddSuserResult.TakenBefore);
                }
            }
            else
            {
                return(AddSuserResult.BadLuck);
            }


            return(AddSuserResult.Joined);
        }
Пример #2
0
        public override bool Process()
        {
            Suser suserObj = null;

            string suser, pwd;

            suser = GetValue <string>("Suser");


            pwd = GetValue <string>("Pass", false);


            if (!Suser.IsSuserNameAllowed(suser))
            {
                PushResponseItem("AuthStatus", "AuthFailed");
                return(true);
            }

            if (suser != null && pwd != null)
            {
                suserObj = SozlukDataStore.GetSuser(suser);
            }

            if (suserObj != null && suserObj.ValidatePassword(pwd))
            {
                PushResponseItem("AuthStatus", "AuthSuccess");
            }
            else
            {
                PushResponseItem("AuthStatus", "AuthFailed");
            }

            return(true);
        }
Пример #3
0
        private void HandleIndexing()
        {
            int    pageNum;
            string pagerHash;
            string indexVal;

            SearchAndIndexQueryResult result;

            pageNum   = GetValue <int>("pagenum");
            pagerHash = GetValue <string>("ph");
            indexVal  = GetValue <string> ("index");

            if (!string.IsNullOrEmpty(pagerHash) && IsValidPagerHash(pagerHash))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (pageNum > 0)
            {
                pageNum--;
            }
            else
            {
                pageNum = 0;
            }

            result = SozlukDataStore.FetchBasliks(indexVal, pageNum, pagerHash);

            if (result.HasEntry)
            {
                PushResponseItem("TotalRecordCount", result.TotalRecordCount);
                PushResponseItem("LogicalEntryCount", result.LogicalRecordCount);
                PushResponseItem("PhysicalEntryCount", result.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(result.TotalRecordCount, RecordPerPageType.Basliks));
                PushResponseItem("CurrentPageNum", pageNum + 1);

                if (!string.IsNullOrEmpty(result.PagerHash))
                {
                    PushResponseItem("PagerHash", result.PagerHash);
                }

                foreach (var entry in result.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }


                result.Entries.Clear();
                result.Entries = null;
            }
            else
            {
                PushResponseItem("LogicalEntryCount", 0);
            }
        }
Пример #4
0
        public override bool Process()
        {
            bool status = SozlukDataStore.AddEntry(entry);

            if (!status)
            {
                Log.Warning("Entry addition failed ({0})", entry.ToString());
            }

            base.PushResponseItem("Status", Helper.GetStatusString(status, "Ok", "Fail"));

            if (status)
            {
                PushResponseItem("BaslikId", entry.BaslikID);
            }

            return(true);
        }
Пример #5
0
        private void HandleSearch()
        {
            bool     noDate;
            int      pageNum   = GetValue <int>("pagenum");
            string   pagerHash = GetValue <string>("ph");
            string   term      = GetValue <string>("term");
            string   suser     = GetValue <string>("suser");
            DateTime beginDate = GetValue <DateTime>("date");
            DateTime endDate   = GetValue <DateTime>("todate");

            noDate = beginDate == DateTime.MinValue;

            if (noDate)
            {
                endDate = DateTime.MinValue; //no date
            }
            else if (endDate == DateTime.MinValue)
            {
                //begin set but end not. so assume the end to the today like sozluk-cgi does
                endDate = DateTime.Now;

                if (beginDate > endDate)
                {
                    //We are damn sure that there will be no record :P
                    PushResponseItem("LogicalEntryCount", 0);
                    return;
                }
            }

            if (!string.IsNullOrEmpty(suser) && !Suser.IsSuserNameAllowed(suser))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (!string.IsNullOrEmpty(pagerHash) && IsValidPagerHash(pagerHash))
            {
                PushResponseItem("LogicalEntryCount", 0);
                return;
            }

            if (!string.IsNullOrEmpty(term))
            {
                term = NormalizeTerm(term);
            }

            if (pageNum > 0)
            {
                pageNum--;
            }

            SearchAndIndexQueryResult result;

            result = SozlukDataStore.FetchBasliksUsingSearch(
                false, term, suser, beginDate, endDate,
                pageNum, pagerHash, noDate);

            if (result.HasEntry)
            {
                PushResponseItem("TotalRecordCount", result.TotalRecordCount);
                PushResponseItem("LogicalEntryCount", result.LogicalRecordCount);
                PushResponseItem("PhysicalEntryCount", result.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(result.TotalRecordCount, RecordPerPageType.Basliks));
                PushResponseItem("CurrentPageNum", pageNum + 1);


                if (!string.IsNullOrEmpty(result.PagerHash))
                {
                    PushResponseItem("PagerHash", result.PagerHash);
                }


                foreach (var entry in result.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }

                result.Entries.Clear();
                result.Entries = null;
            }
            else
            {
                PushResponseItem("LogicalEntryCount", 0);
            }
        }
Пример #6
0
        public override bool Process()
        {
            ViewQueryResult queryResult;
            int             pageNumber, baslikId;
            bool            latest = false;

            pageNumber = GetValue <int>("pagenum");
            baslikId   = GetValue <int>("bid");

            if (HasKey("latest"))
            {
                latest = true;
            }

            if (baslikId < 0)
            {
                baslikId = 0;
            }

            if (pageNumber > 0)
            {
                pageNumber--;
            }
            else
            {
                pageNumber = 0;
            }

            if (latest && baslikId > 0)
            {
                BaslikBasicInfo bbi;

                if (CacheManager.TryGetCachedResult <BaslikBasicInfo>("BBI_" + baslikId.ToString(), out bbi))
                {
                    pageNumber = SozlukDataStore.CalcPageCount(bbi.TotalEntries, RecordPerPageType.Entries) - 1;
                }
            }

            queryResult = SozlukDataStore.FetchEntriesOfBaslik(
                GetValue <string>("baslik"),
                baslikId,
                pageNumber);

            if (queryResult.HasEntry)
            {
                PushResponseItem("RecordCount", queryResult.PhysicalRecordCount);
                PushResponseItem("TotalPageCount", SozlukDataStore.CalcPageCount(queryResult.TotalRecordCount, RecordPerPageType.Entries));
                PushResponseItem("RecordsPerPage", SozlukDataStore.RecordsPerPage);
                PushResponseItem("CurrentPageNum", pageNumber + 1);
                PushResponseItem("BaslikId", queryResult.BaslikId);
                PushResponseItem("Baslik", queryResult.Entries[0].Baslik);


                foreach (var entry in queryResult.Entries)
                {
                    PushResponseContent(entry.GetTransportString());
                }
            }
            else
            {
                PushResponseItem("RecordCount", 0);
            }

            return(true);
        }