Exemple #1
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);
        }
        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);
        }
Exemple #3
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);
            }
        }