Пример #1
0
        /// <summary>
        /// Validates entries to upload/add/update file
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="userId"></param>
        /// <param name="groupIds"></param>
        /// <returns></returns>
        bool ValidateToUpdateFile(long siteId, long?userId, long[] groupIds)
        {
            //GET/CHECK THE SITE
            awSite site = new SiteLibrary().Get(siteId);

            if (site == null || !site.isEnabled)
            {
                throw new Exception("Site does not exists or disabled.");
            }

            if (userId == null || userId.Value == 0)
            {
                throw new Exception("User does not exists or disabled.");
            }

            //GET/CHECK USER
            AWAPI_Data.CustomEntities.UserExtended user = new UserLibrary().Get(userId.Value);
            if (user == null || !user.isEnabled)
            {
                throw new Exception("User does not exists or disabled.");
            }


            //IF GROUP ID(s) IS SET CHECK IF THE GROUP DOES EXIST ----------------
            if (groupIds != null && groupIds.Length > 0)
            {
                if (GroupIdsExist(siteId, groupIds) == false)
                {
                    throw new Exception("One or more file groups do not exist");
                }
            }

            return(true);
        }
Пример #2
0
        public void ResetPassword(long siteId, string email, string redirectLink)
        {
            awSite site = new SiteLibrary().Get(siteId);

            if (site == null || !site.isEnabled)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.DOES_NOT_EXIST));
            }

            if (site.userResetPasswordEmailTemplateId == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.RESET_PASSWORD_TEMPLATE_DOES_NOT_EXIST));
            }

            //GET THE USER
            awUser user = (from l in _context.awUsers
                           where l.email.Equals(email) && l.isEnabled != false
                           select l).FirstOrDefault();

            if (user == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.DOES_NOT_EXIST));
            }


            //CREATE NEW PASSWORD
            const int PASSWORD_LENGTH = 6;
            string    _allowedChars   = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
            Random    randNum         = new Random();

            char[] chars            = new char[PASSWORD_LENGTH];
            int    allowedCharCount = _allowedChars.Length;

            for (int i = 0; i < PASSWORD_LENGTH; i++)
            {
                chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
            }
            string password = new string(chars);


            //FIRST SEND EMAIL BEFORE RESETING THE PASSWORD
            AWAPI_BusinessLibrary.library.EmailTemplateLib emailLib = new EmailTemplateLib();
            awEmailTemplate template = emailLib.Get(site.userResetPasswordEmailTemplateId.Value);

            if (template == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.RESET_PASSWORD_TEMPLATE_DOES_NOT_EXIST));
            }

            emailLib.Send(site.userResetPasswordEmailTemplateId.Value, email,
                          "firstname|" + user.firstName,
                          "lastname|" + user.lastName,
                          "password|" + password,
                          "link|" + redirectLink,
                          "date|" + DateTime.Now.ToString());

            //UPDATE PASSWORD
            UpdatePassword(user.userId, password);
        }
Пример #3
0
        private long SecureAdd(string accessKey, long siteId, string username, string firstName, string lastName,
                               string email, string password, string description, string link, string imageurl,
                               string gender, DateTime?birthday, string tel, string tel2, string address, string city,
                               string state, string postalCode, string country, string redirectUrlAfterConfirmationTask)
        {
            //CONFIRMATION EMAIL IS REQUIRED -------------------------------------------------------------
            AWAPI_Data.Data.awSite site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(siteId);
            if (site.userConfirmationEmailTemplateId == 0)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.USER_CONFIRMATION_EMAIL_REQURED));
            }

            AWAPI_BusinessLibrary.library.EmailTemplateLib emailTemplateLib = new EmailTemplateLib();
            AWAPI_Data.Data.awEmailTemplate emailTemplate = emailTemplateLib.Get(site.userConfirmationEmailTemplateId);
            if (emailTemplate == null)
            {
                throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.USER_CONFIRMATION_EMAIL_NOT_FOUND));
            }

            //ADD USER ------------------------------------------------------------------------------------
            long userId = _userLib.Add(username, firstName, lastName, email, password, description,
                                       false, false, link, imageurl, gender, birthday, tel, tel2, address,
                                       city, state, postalCode, country);

            if (userId <= 0)
            {
                return(0);
            }

            //ADD USER TO THE SITE ------------------------------------------------------------------------
            _userLib.AddUserToSite(siteId, userId, true);

            //ADD AN AUTOMATED CONFIRMATION TASK ----------------------------------------------------------
            AutomatedTaskLibrary taskLib = new AutomatedTaskLibrary();
            Guid enableUserTaskId        = Guid.NewGuid();

            taskLib.Add(siteId, 0, enableUserTaskId,
                        "Enable User", userId.ToString(),
                        false, "",
                        "AWAPI_BusinessLibrary.library.UserLibrary", "UpdateStatus", String.Format("int64:{0}|bool:{1}", userId, (bool)true),
                        redirectUrlAfterConfirmationTask);

            //SEND CONFIRMATION EMAIL ----------------------------------------------------------------------
            string confirmationLink = ConfigurationLibrary.Config.automatedTaskServiceUrl + "?taskid=" + enableUserTaskId.ToString();

            AWAPI_BusinessLibrary.library.EmailTemplateLib emailLib = new EmailTemplateLib();
            emailLib.Send(emailTemplate.emailTemplateId, email,
                          "firstname|" + firstName,
                          "lastname|" + lastName,
                          "confirmationlink|" + confirmationLink,
                          "date|" + DateTime.Now.ToString());

            return(userId);
        }
Пример #4
0
        public FileAmazonS3(long siteId)
        {
            //if the site has its own bucket name then use it, else get from he main configuration
            SiteLibrary lib = new SiteLibrary();

            AWAPI_Data.Data.awSite site = lib.Get(siteId);

            if (site != null && !String.IsNullOrEmpty(site.fileAmazonS3BucketName))
            {
                BucketName = site.fileAmazonS3BucketName;
            }
            else
            {
                BucketName = ConfigurationLibrary.Config.fileAmazonS3BucketName;
            }
        }
Пример #5
0
        /// <summary>
        /// Returns true if the referrer has right...
        /// </summary>
        /// <param name="siteId"></param>
        /// <returns></returns>
        public static bool IsValidReferrer(long siteId)
        {
            if (siteId <= 0)
            {
                return(false);
            }

            AWAPI_BusinessLibrary.library.SiteLibrary _siteLib = new SiteLibrary();
            AWAPI_Data.Data.awSite site = _siteLib.Get(siteId);

            //check if site doesn't exist or disabled
            if (site == null || !site.isEnabled)
            {
                return(false);
            }

            string domain = System.Web.HttpContext.Current.Request.UrlReferrer.Authority;// = "localhost:56624";

            //check if the domain is granted
            if (!String.IsNullOrEmpty(site.grantedDomains))
            {
                string[] grantedDomains = site.grantedDomains.Split(',');
                foreach (string dmn in grantedDomains)
                {
                    if (dmn.Trim().ToLower().Replace("www.", "").Replace("https://", "").Replace("http://", "") == domain.ToLower())
                    {
                        return(true);
                    }
                }
                return(false);
            }

            //check if the domain is banned
            if (!String.IsNullOrEmpty(site.bannedDomains))
            {
                string[] bannedDomains = site.bannedDomains.Split(',');
                foreach (string dmn in bannedDomains)
                {
                    if (dmn.Trim().ToLower().Replace("www.", "").Replace("https://", "").Replace("http://", "") == domain.ToLower())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #6
0
        public void ProcessRequest(HttpContext context)
        {
            _site = null;
            if (SiteId != 0)
            {
                _site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(SiteId);
            }

            if (_site == null || !_site.isEnabled)
            {
                return;
            }

            _feed = new SyndicationFeed("AWAPI CMS Feed", "", null);
            _feed.Authors.Add(new SyndicationPerson(""));
            _feed.Categories.Add(new SyndicationCategory("contests"));
            _feed.AttributeExtensions.Add(new XmlQualifiedName("site"), _site.title);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), _site.link);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("defaultculture"), _site.cultureCode);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("pagesize"), PageSize.ToString());
            _feed.AttributeExtensions.Add(new XmlQualifiedName("pageindex"), PageIndex.ToString());
            _feed.AttributeExtensions.Add(new XmlQualifiedName("servertime"), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));
            AddParamsToFeed();

            context.Response.ContentType     = "text/xml";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;

            switch (MethodName)
            {
            case "getentrylist":
                GetEntryList(SiteId);
                break;

            case "getentrydailysummary":
                GetEntryDailySummary(SiteId);
                break;

            default:
                break;
            }

            WriteFeed();
        }
Пример #7
0
        public void ProcessRequest(HttpContext context)
        {
            AWAPI_Data.Data.awSite site = null;
            if (SiteId != 0)
            {
                site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(SiteId);
            }

            if (site == null)
            {
                return;
            }


            _feed = new SyndicationFeed("AWAPI CMS Feed", "", null);
            _feed.Authors.Add(new SyndicationPerson(""));
            _feed.Categories.Add(new SyndicationCategory("weatherforecast"));
            _feed.AttributeExtensions.Add(new XmlQualifiedName("site"), site.title);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), site.link);

            if (City != "" && WeatherServiceUrl != "")
            {
                switch (WeatherServiceProvider.ToLower())
                {
                case "google":
                    GetFromGoogle(WeatherServiceUrl + City);
                    break;

                default:
                    break;
                }
            }

            XmlWriter writer = XmlWriter.Create(context.Response.Output);

            context.Response.ContentType = "application/rss+xml";
            Rss20FeedFormatter rss = new Rss20FeedFormatter(_feed);

            rss.WriteTo(writer);
            writer.Close();
        }
Пример #8
0
        /// <summary>
        /// Access Key is required for insert/update methods,
        /// (We cannot get client's IP address from WCF)
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="accessKey"></param>
        /// <returns></returns>
        public static bool IsValidAccessKey(long siteId, string accessKey)
        {
            if (siteId <= 0 || String.IsNullOrEmpty(accessKey))
            {
                return(false);
            }

            AWAPI_BusinessLibrary.library.SiteLibrary _siteLib = new SiteLibrary();
            AWAPI_Data.Data.awSite site = _siteLib.Get(siteId);

            //check if site doesn't exist or disabled
            if (site == null || !site.isEnabled)
            {
                return(false);
            }

            if (site.accessKey.ToLower() == accessKey.ToLower())
            {
                return(true);
            }
            return(false);
        }
Пример #9
0
        public void ProcessRequest(HttpContext context)
        {
            _site = null;
            if (SiteId != 0)
            {
                _site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(SiteId);
            }

            if (_site == null || !_site.isEnabled)
            {
                return;
            }

            string link = String.IsNullOrEmpty(_site.link) ? "http://awapi.com" : _site.link;

            _feed = new SyndicationFeed(_site.title + " - Blog Feed", "", new Uri(link));
            _feed.Authors.Add(new SyndicationPerson("*****@*****.**"));

            _feed.AttributeExtensions.Add(new XmlQualifiedName("site"), _site.title);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), _site.link);
            _feed.AttributeExtensions.Add(new XmlQualifiedName("defaultculture"), _site.cultureCode);

            _feed.AttributeExtensions.Add(new XmlQualifiedName("currentpostid"), CurrentPostId.ToString());
            _feed.AttributeExtensions.Add(new XmlQualifiedName("servertime"), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));

            if (BlogId > 0)
            {
                _feed.AttributeExtensions.Add(new XmlQualifiedName("blogid"), BlogId.ToString());
            }
            if (BlogCategoryId > 0)
            {
                _feed.AttributeExtensions.Add(new XmlQualifiedName("blogcategoryid"), BlogCategoryId.ToString());
            }
            if (PostId > 0)
            {
                _feed.AttributeExtensions.Add(new XmlQualifiedName("postid"), PostId.ToString());
            }

            AddParamsToFeed();

            context.Response.ContentType     = "text/xml";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;

            switch (MethodName)
            {
            case "getblog":
                _feed.Title = new TextSyndicationContent(_site.title + " - Blog");
                _feed.Categories.Add(new SyndicationCategory("blogs"));
                GetBlog(SiteId, BlogId);
                break;

            case "getbloglist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Blog List");
                _feed.Categories.Add(new SyndicationCategory("blogs"));
                GetBlogList(SiteId);
                break;

            case "getcategorylist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Blog Category List");
                _feed.Categories.Add(new SyndicationCategory("blogs"));
                GetCategoryList(BlogId);
                break;

            case "getpost":
                _feed.Title = new TextSyndicationContent(_site.title + " - Blog Post");
                _feed.Categories.Add(new SyndicationCategory("posts"));
                GetBlogPost(SiteId, PostId);
                break;

            case "getpostfilelist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Blog Post File List");
                _feed.Categories.Add(new SyndicationCategory("files"));
                GetBlogPostFileList(SiteId, PostId);
                break;

            case "getpostlist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Post List");
                _feed.Categories.Add(new SyndicationCategory("posts"));
                GetBlogPostList(SiteId, BlogId, BlogCategoryId, TagId, Search, PageIndex, PageSize);
                break;

            case "getarchivedpostlist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Archived Post List");
                _feed.Categories.Add(new SyndicationCategory("posts"));
                GetArchivedBlogPostList(SiteId, BlogId, Archive, PageIndex, PageSize);
                break;

            case "getarchivelist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Post Archive List");
                _feed.Categories.Add(new SyndicationCategory("posts"));
                GetBlogPostArchiveList(BlogId);
                break;

            case "getcommentlist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Comment List");
                _feed.Categories.Add(new SyndicationCategory("comments"));
                GetBlogCommentList(SiteId, BlogId, PostId);
                break;

            case "gettaglist":
                _feed.Title = new TextSyndicationContent(_site.title + " - Tag List");
                _feed.Categories.Add(new SyndicationCategory("tags"));
                GetBlogTagList(BlogId, PostId);
                break;

            default:
                break;
            }

            WriteFeed();
        }
Пример #10
0
        /// <summary>
        /// Returns list of the files...
        /// </summary>
        void GetList()
        {
            long   siteId      = _context.Request["siteId"] == null ? 0 : Convert.ToInt64(_context.Request["siteId"]);
            long   userid      = _context.Request["userid"] == null ? 0 : Convert.ToInt64(_context.Request["userid"]);
            long   fileGroupid = _context.Request["fileGroupid"] == null ? 0 : Convert.ToInt64(_context.Request["fileGroupid"]);
            string contentType = _context.Request["contenttype"] == null ? "" : _context.Request["contenttype"];
            string returnType  = _context.Request["type"] == null ? "rss" : _context.Request["type"];


            //Chheck if the site exists and enabled
            AWAPI_Data.Data.awSite site = new AWAPI_BusinessLibrary.library.SiteLibrary().Get(siteId);
            if (site == null || !site.isEnabled)
            {
                return;
            }

            //SET THE FEED HEADER ----------------------------------
            string          link = String.IsNullOrEmpty(site.link) ? "http://awapi.com" : site.link;
            SyndicationFeed feed = new SyndicationFeed(site.title + " - Blog Feed", "", new Uri(link));

            feed.Authors.Add(new SyndicationPerson("*****@*****.**"));
            feed.AttributeExtensions.Add(new XmlQualifiedName("site"), site.title);
            feed.AttributeExtensions.Add(new XmlQualifiedName("sitelink"), site.link);
            feed.AttributeExtensions.Add(new XmlQualifiedName("servertime"), DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));

            if (userid > 0)
            {
                feed.AttributeExtensions.Add(new XmlQualifiedName("userid"), userid.ToString());
            }
            if (fileGroupid > 0)
            {
                feed.AttributeExtensions.Add(new XmlQualifiedName("filegroupid"), fileGroupid.ToString());
            }
            if (contentType != "")
            {
                feed.AttributeExtensions.Add(new XmlQualifiedName("contenttype"), contentType);
            }

            //GET FILE LIST
            IList <AWAPI_Data.Data.awFile> fileList = _fileLib.GetList(siteId, "");

            if (fileList != null && fileList.Count > 0)
            {
                //get the list if the groupid and userid are set
                var list2 = from l in fileList
                            where l.isEnabled &&
                            (userid == 0 || userid > 0 && l.userId.Equals(userid)) &&
                            (fileGroupid == 0 ||
                             fileGroupid > 0 && l.awFileInGroups.FirstOrDefault(a => a.fileGroupId.Equals(fileGroupid)) != null)
                            select l;

                if (list2 != null && list2.Count() > 0)
                {
                    //fill the syndication feed
                    List <SyndicationItem> items = new List <SyndicationItem>();
                    fileList = list2.ToArray();
                    foreach (AWAPI_Data.Data.awFile file in fileList)
                    {
                        Uri uri = null;

                        SyndicationItem item = new SyndicationItem(
                            file.title,
                            file.description,
                            uri,
                            file.fileId.ToString(),
                            file.createDate);

                        item.ElementExtensions.Add("contenttype", null, file.contentType);
                        if (!String.IsNullOrEmpty(file.thumbnail))
                        {
                            item.ElementExtensions.Add("videopreview", null, file.thumbnail);
                        }

                        item.ElementExtensions.Add("userid", null, file.userId);
                        item.ElementExtensions.Add("username", null, file.awUser_File.username);
                        item.ElementExtensions.Add("userfirstname", null, file.awUser_File.firstName);
                        item.ElementExtensions.Add("userlastname", null, file.awUser_File.lastName);


                        items.Add(item);
                    }
                    feed.Items = items;
                }
            }


            string    output = "";
            XmlWriter writer = XmlWriter.Create(_context.Response.Output);

            if (feed != null)
            {
                switch (returnType)
                {
                case "atom":
                    _context.Response.ContentType = "application/atom+xml";
                    feed.Description = new TextSyndicationContent("AWAPI Content in Atom 1.0 Feed Format");
                    Atom10FeedFormatter atom = new Atom10FeedFormatter(feed);
                    atom.WriteTo(writer);
                    break;

                case "json":
                    _context.Response.ContentType = "application/json";
                    Rss20FeedFormatter rssFeed = new Rss20FeedFormatter(feed);
                    if (rssFeed != null)
                    {
                        output = Newtonsoft.Json.JsonConvert.SerializeObject(rssFeed);
                        //JavaScriptSerializer ser = new JavaScriptSerializer();
                        //output = ser.Serialize(rssFeed);
                    }
                    break;

                default:        //rss
                    feed.Description = new TextSyndicationContent("AWAPI Content in RSS 2.0 Feed Format");
                    _context.Response.ContentType = "application/rss+xml";
                    Rss20FeedFormatter rss = new Rss20FeedFormatter(feed);
                    rss.WriteTo(writer);
                    break;
                }
            }

            if (output != "")
            {
                _context.Response.Write(output);
            }

            writer.Close();
        }