Beispiel #1
0
        public static void CreateUser(string username, string email, bool receiveEmailNewsletter, Host host, string ipAddress)
        {
            username = username.Trim();
            email = email.Trim();

            string password = PasswordGenerator.Generate(8);
            string passwordSalt = Cipher.GenerateSalt();
            string passwordHash = Cipher.Hash(password, passwordSalt);

            User user = new User();
            user.Username = username;
            user.Email = email;
            user.Password = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.IsGeneratedPassword = true;
            user.IsValidated = false;
            user.IsBanned = false;
            user.ReceiveEmailNewsletter = receiveEmailNewsletter;
            user.HostID = host.HostID;
            user.IPAddress = ipAddress;
            user.LastActiveOn = DateTime.Now;
            user.IsVetted = host.AutoVetUsers;

            using (TransactionScope scope = new TransactionScope()) {
                user.Save();

                EmailHelper.SendNewUserEmail(email, username, password, host);
                UserAction.RecordUserRegistration(user.HostID, user);

                scope.Complete();
            }
        }
 public static void Send(MailMessage message, Host host)
 {
     SmtpClient smtpClient = new SmtpClient(host.SmtpHost, host.SmtpPort);
     smtpClient.Credentials = new NetworkCredential(host.SmtpUsername, host.SmtpPassword);
     smtpClient.EnableSsl = host.SmtpEnableSsl;
     smtpClient.Send(message);
 }
Beispiel #3
0
        public string GravatarUrl(Host host)
        {
            string root = "";
            if (host != null)
                root = host.RootUrl;

            if (this.User.UseGravatar) {
                string gravatarHash = FormsAuthentication.HashPasswordForStoringInConfigFile(this._user.GravatarEmail, "MD5").ToLower();
                return String.Format("{0}/gravatar/{1}/{2}", root, gravatarHash, this._size);
            } else {
                return String.Format("{0}/static/images/cache/defaultgravatars/gravatar_{1}.jpg", root, this._size);
            }
        }
        public static void SendChangedEmailEmail(string toEmail, string username, string currentEmail, Host host)
        {
            // Send a verify email address.  Add a 64bit encryption "hash" to verify when they click it.
            Send(host.Email, toEmail, host.SiteTitle + " has requested you to verify your email",
                String.Format(@"
                This is to verify that the email address you have selected is valid.

                Please click on the link below to verify this email address:

                {0}

                If you did not request to change your email address, pleas disreguard this message.

                Thanks,
                {1}", host.RootUrl + "/verifyemail/" + Security.Cipher.EncryptToBase64(username + "#" + currentEmail + "#" + toEmail), host.SiteTitle), host);
        }
        public static void SendPasswordEmail(string toEmail, string username, string password, Host host)
        {
            Send(host.Email, toEmail, "Your new " + host.SiteTitle + " password",
                String.Format(@"

                Please keep this email for your records. Your account information is as follows:

                ---------------
                Username: {0}
                Password: {1}
                ---------------

                You can log in to kick at the following location : {2}

                {3}", username, password, host.RootUrl + "/login", host.SiteTitle), host);
        }
        public static void SendNewUserEmail(string toEmail, string username, string password, Host host)
        {
            Send(host.Email, toEmail, "Welcome to " + host.SiteTitle + " " + username,
                String.Format(@"
                Welcome to {3}.

                Your account information is as follows:

                ---------------
                Username: {0}
                Password: {1}
                ---------------

                You can log in to kick at the following location : {2}

                Thanks for joining our site,
                {3}", username, password, host.RootUrl + "/login", host.SiteTitle), host);
        }
        public static RssChannel ConvertToRssChannel(StoryCollection stories, string title, string description, string link, Host host)
        {
            RssChannel channel = new RssChannel();
            channel.Title = title;
            channel.Description = description;
            channel.Link = new System.Uri(link);
            channel.Language = "en-us";
            channel.Generator = host.SiteTitle + " - " + host.TagLine;
            channel.Docs = "";
            channel.TimeToLive = 30;
            channel.Copyright = "Atweb Publishing Ltd.";

            if (stories.Count == 0) {
                RssItem item = new RssItem();
                item.Title = " ";
                item.Description = " ";
                item.PubDate = DateTime.Now.ToUniversalTime();

                channel.Items.Add(item);
            } else {

                foreach (Story story in stories) {
                    string storyUrl = host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, host.HostID).CategoryIdentifier);

                    //TODO: GJ: add category info

                    RssItem item = new RssItem();
                    item.Title = story.Title;
                    item.Description = story.Description + " <br /><br /><br />" + Incremental.Common.Web.Helpers.ControlHelper.RenderControl(new Incremental.Kick.Web.Controls.StoryDynamicImage(story.Url, host));
                    item.PubDate = story.PublishedOn.ToUniversalTime();
                    RssGuid guid = new RssGuid();
                    guid.Name = storyUrl;
                    guid.PermaLink = true;
                    item.Guid = guid;
                    item.Link = new Uri(storyUrl);

                    channel.Items.Add(item);
                }
            }

            return channel;
        }
        public virtual void ProcessRequest(HttpContext context)
        {
            this._hostProfile = HostCache.GetHost(HostHelper.GetHostAndPort(context.Request.Url));
            this.GetStoryData(context);

            int storyCount =
                Math.Min(
                    !string.IsNullOrEmpty(context.Request["count"]) ? Convert.ToUInt16(context.Request["count"]) : _stories.Count,
                    _stories.Count);

            context.Response.ContentType = "text/javascript";

            this.WriteJavaScriptLine(@"<div class=""KickStoryList"">", context);
            foreach (Story story in this._stories.GetRange(0, storyCount)) {
                this.WriteJavaScriptLine(@"<div class=""KickStory"">", context);
                this.WriteJavaScriptLine(String.Format(@"<a href=""{0}"">{1}</a>",
                    UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, this._hostProfile.HostID).CategoryIdentifier, this._hostProfile),
                    story.Title), context);
                this.WriteJavaScriptLine(@"</div>", context);
            }

            this.WriteJavaScriptLine(@"</div>", context);
        }
Beispiel #9
0
 public ApiShout ToApi(Host host)
 {
     //NOTE: GJ: PERFORMANCE: should we be hitting the cache here, we could defer until later and just add the id here
     return new ApiShout(this.ShoutID, UserCache.GetUser(this.FromUserID).ToApi(host), this.Message, this.CreatedOn);
 }
Beispiel #10
0
        public static void SendUserBanEmail(User user, Host host)
        {
            Send_Begin(host.Email, user.Email, "[" + host.SiteTitle + "]",
                String.Format(@"
                A moderator has banned you from {0}.

                Please let us know if you think this was in error.", host.SiteTitle), host);
        }
Beispiel #11
0
        public static void SendStoryDeletedEmail(Story story, Host host)
        {
            Send_Begin(host.Email, story.User.Email, "[" + host.SiteTitle + "]",
                String.Format(@"
                Your post

                '{0}'
                '{1}'

                was deleted by a moderator.

                Please let us know if you think this was in error.", story.Title, story.Description), host);
        }
Beispiel #12
0
        public static void UserPassedTest(User user, Host host)
        {
            user.IsVetted = true;
            user.Save();

            UserAction.RecordUserPassedTest(host.HostID, user);
        }
Beispiel #13
0
 public static void BanUser(int userID, User moderator, Host host)
 {
     User user = User.FetchByID(userID);
     user.Ban(moderator, host);
 }
Beispiel #14
0
        public static void SendPasswordResetEmail(int userID, Host host)
        {
            User user = User.FetchByID(userID);

            EmailHelper.SendPasswordResetEmail(user.Email, user.Username, user.LastActiveOn, host);
        }
Beispiel #15
0
        public static void UpdatePassword(int userID, string newPassword, Host host)
        {
            newPassword = newPassword.Trim();
            string passwordSalt = Cipher.GenerateSalt();
            string passwordHash = Cipher.Hash(newPassword, passwordSalt);

            User user = User.FetchByID(userID);
            user.Password = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.IsGeneratedPassword = false;
            user.Save();

            System.Diagnostics.Trace.WriteLine("UpdatePassword: " + userID);

            EmailHelper.SendChangedPasswordEmail(user.Email, user.Username, newPassword, host);
        }
Beispiel #16
0
 public static void SendUserUnBanEmail(User user, Host host)
 {
     Send_Begin(host.Email, user.Email, "[" + host.SiteTitle + "]",
         String.Format(@"
         A moderator has un-banned you from {0}. Welcome back!!", host.SiteTitle), host);
 }
Beispiel #17
0
 public static int GetUpcomingStoryCount(Host host)
 {
     return GetStoryCount(host.HostID, false, DateTime.Now.AddHours(-host.Publish_MaximumStoryAgeInHours), DateTime.Now);
 }
Beispiel #18
0
 private static int GetStoryScore(Story story, Host host)
 {
     int score = 0;
     score += story.KickCount * host.Publish_KickScore;
     score += story.CommentCount * host.Publish_CommentScore;
     System.Diagnostics.Trace.WriteLine("Pub: Score of [" + score + "] for storyID " + story.StoryID);
     return score;
 }
Beispiel #19
0
 public ApiUser ToApi(Host host)
 {
     return new ApiUser(this.Username, host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.UserProfile, this.Username), new Gravatar(this, 50).GravatarUrl(host));
 }
Beispiel #20
0
 public static void Send_Begin(string from, string to, string subject, string body, Host host)
 {
     AsyncHelper.FireAndForget(delegate { Send(from, to, subject, body, host); });
 }
Beispiel #21
0
        internal static void SendPasswordResetEmail(string toEmail, string username, DateTime createdDateTime, Host host)
        {
            Send(host.Email, toEmail, "Reset you " + host.SiteTitle + " password",
                String.Format(@"
                Please follow the link below to reset your password:

                {0}

                Thanks,
                {1}", host.RootUrl + "/resetpassword/" + username + "/" + createdDateTime.Ticks.GetHashCode().ToString(), host.SiteTitle), host);
        }
Beispiel #22
0
 public static void Send(string from, string to, string subject, string body, Host host)
 {
     Send(new MailMessage(from, to, subject, body), host);
 }
Beispiel #23
0
        public void UnBan(User moderator, Host host)
        {
            this.IsBanned = false;
            this.Save();
            this.UpdateStoryCommentShoutSpamStatus(false);

            EmailHelper.SendUserUnBanEmail(this, host);
            UserAction.RecordUserUnBan(this.HostID, this, moderator);
            UserCache.RemoveUser(this.UserID);
        }
 public StoryDynamicImage(string url, Host hostProfile)
 {
     _url = HttpUtility.UrlEncode(url);
     _hostProfile = hostProfile;
 }
Beispiel #25
0
        private static bool IsWeakStory(Story story, Host host)
        {
            if ((story.KickCount < host.Publish_MinimumStoryKickCount) || (story.CommentCount < host.Publish_MinimumStoryCommentCount))
                return true;

            //TODO: check the average kicks and comments per hour
            //TODO: check the view count

            return false;
        }
Beispiel #26
0
        public static void ResetPassword(int userID, Host host)
        {
            //generate a password
            User user = User.FetchByID(userID);
            string password = PasswordGenerator.Generate(8);
            string passwordSalt = Cipher.GenerateSalt();
            string passwordHash = Cipher.Hash(password, passwordSalt);

            user.PasswordSalt = passwordSalt;
            user.Password = passwordHash;
            user.LastActiveOn = DateTime.Now;
            user.IsGeneratedPassword = true;
            user.Save();

            EmailHelper.SendPasswordEmail(user.Email, user.Username, password, host);
        }
        public void Insert(string HostName,string RootUrl,string SiteTitle,string SiteDescription,string TagLine,string LogoPath,DateTime CreatedOn,string BlogUrl,string Email,string Template,bool ShowAds,string Culture,string UICulture,short Publish_MinimumStoryAgeInHours,short Publish_MaximumStoryAgeInHours,short Publish_MaximumSimultaneousStoryPublishCount,short Publish_MinimumStoryScore,short Publish_MinimumStoryKickCount,short Publish_MinimumStoryCommentCount,short Publish_MinimumAverageStoryKicksPerHour,short Publish_MinimunAverageCommentsPerHour,short Publish_MinimumViewCount,short Publish_KickScore,short Publish_CommentScore,string AdsenseID,string TrackingHtml,string AnnouncementHtml,string FeedBurnerMainRssFeedUrl,string FeedBurnerMainRssFeedCountHtml,bool UseStaticRoot,string SmtpHost,int SmtpPort,string SmtpUsername,string SmtpPassword,bool SmtpEnableSsl,string SubmitAStoryMessage,string JoinTheCommunityMessage,string ReCaptchaPublicKey,string ReCaptchaPrivateKey,bool AutoVetUsers)
        {
            Host item = new Host();

            item.HostName = HostName;

            item.RootUrl = RootUrl;

            item.SiteTitle = SiteTitle;

            item.SiteDescription = SiteDescription;

            item.TagLine = TagLine;

            item.LogoPath = LogoPath;

            item.CreatedOn = CreatedOn;

            item.BlogUrl = BlogUrl;

            item.Email = Email;

            item.Template = Template;

            item.ShowAds = ShowAds;

            item.Culture = Culture;

            item.UICulture = UICulture;

            item.Publish_MinimumStoryAgeInHours = Publish_MinimumStoryAgeInHours;

            item.Publish_MaximumStoryAgeInHours = Publish_MaximumStoryAgeInHours;

            item.Publish_MaximumSimultaneousStoryPublishCount = Publish_MaximumSimultaneousStoryPublishCount;

            item.Publish_MinimumStoryScore = Publish_MinimumStoryScore;

            item.Publish_MinimumStoryKickCount = Publish_MinimumStoryKickCount;

            item.Publish_MinimumStoryCommentCount = Publish_MinimumStoryCommentCount;

            item.Publish_MinimumAverageStoryKicksPerHour = Publish_MinimumAverageStoryKicksPerHour;

            item.Publish_MinimunAverageCommentsPerHour = Publish_MinimunAverageCommentsPerHour;

            item.Publish_MinimumViewCount = Publish_MinimumViewCount;

            item.Publish_KickScore = Publish_KickScore;

            item.Publish_CommentScore = Publish_CommentScore;

            item.AdsenseID = AdsenseID;

            item.TrackingHtml = TrackingHtml;

            item.AnnouncementHtml = AnnouncementHtml;

            item.FeedBurnerMainRssFeedUrl = FeedBurnerMainRssFeedUrl;

            item.FeedBurnerMainRssFeedCountHtml = FeedBurnerMainRssFeedCountHtml;

            item.UseStaticRoot = UseStaticRoot;

            item.SmtpHost = SmtpHost;

            item.SmtpPort = SmtpPort;

            item.SmtpUsername = SmtpUsername;

            item.SmtpPassword = SmtpPassword;

            item.SmtpEnableSsl = SmtpEnableSsl;

            item.SubmitAStoryMessage = SubmitAStoryMessage;

            item.JoinTheCommunityMessage = JoinTheCommunityMessage;

            item.ReCaptchaPublicKey = ReCaptchaPublicKey;

            item.ReCaptchaPrivateKey = ReCaptchaPrivateKey;

            item.AutoVetUsers = AutoVetUsers;

            item.Save(UserName);
        }
Beispiel #28
0
 public static string CreateUrl(PageName pageName, string storyIdentifier, string categoryIdentifier, Host hostProfile)
 {
     switch (pageName) {
         case PageName.ViewStory:
             return hostProfile.RootUrl + String.Format("/{0}/{1}", categoryIdentifier, storyIdentifier);
         default:
             throw new Exception("not enough params to create url");
     }
 }