Пример #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (Tweeter == null)
            {
                HttpCookie loginCookie = Request.Cookies["Login_Cookie"];
                if (loginCookie != null)
                {
                    loginCookie.Expires = DateTime.UtcNow.AddYears(-9);

                    int id = Int32.TryParse(loginCookie.Values["ID"], out id) ? id : -1;
                    string code = (loginCookie.Values["Code"] ?? "").Trim();

                    if (code.Length > 0)
                    {
                        Tweeter foundTweeter = TweeterRepository.FromTwitterId(id);

                        if (foundTweeter != null)
                        {
                            // Expire old logins
                            IList<PersistentLogin> loginsToRemove = foundTweeter.PersistentLogins
                                .Where(pl => pl.LastLoginDate < DateTime.UtcNow.AddDays(-30.0)).ToList();
                            foundTweeter.PersistentLogins.RemoveAll(loginsToRemove);

                            // Find a login that matches the key
                            PersistentLogin foundLogin = foundTweeter.PersistentLogins
                                .FirstOrDefault(pl => pl.SecureKey == code);

                            if (foundLogin != null)
                            {
                                // Generate new code
                                string newCode = SecurityUtils.GenerateSecureKey(KeyStrength._512bit);

                                // Set cookie
                                loginCookie.Values["Code"] = newCode;
                                loginCookie.Expires = DateTime.UtcNow.AddDays(30.0);
                                loginCookie.HttpOnly = true;

                                // Update login entity
                                foundLogin.SecureKey = newCode;
                                foundLogin.LastLoginDate = DateTime.UtcNow;

                                // Assign Tweeter as logged in user
                                Tweeter = foundTweeter;
                            }

                            // Update user in database
                            TweeterRepository.Save(foundTweeter);
                        }
                    }

                    Response.Cookies.Add(loginCookie);
                }
            }

            LanguageSelectForm languageForm = new LanguageSelectForm();
            languageForm.Languages = LanguageRepository.ListLanguages(false);
            languageForm.SelectedLanguage = DefaultLanguage != null ? (int?)DefaultLanguage.Id : null;

            IList<TagReport> tags = TweetRepository.MostPopularTags(App, DefaultLanguage, 30).OrderBy(t => t.Tag).ToList();

            long lowestUsageCount = tags.Count > 0 ? tags.Min(t => t.UsageCount) : 0;
            long highestUsageCount = tags.Count > 0 ? tags.Max(t => t.UsageCount) : 0;

            TagCloudView tagCloud = new TagCloudView();

            foreach (TagReport tag in tags)
            {
                double weight = Math.Log((double)tag.UsageCount) / Math.Log((double)highestUsageCount) * 100.0;

                TagCloudView.TagStrenth strength;

                if (weight >= 99)
                {
                    strength = TagCloudView.TagStrenth.VeryLarge;
                }
                else if (weight >= 75)
                {
                    strength = TagCloudView.TagStrenth.Large;
                }
                else if (weight >= 50)
                {
                    strength = TagCloudView.TagStrenth.Medium;
                }
                else if (weight >= 25)
                {
                    strength = TagCloudView.TagStrenth.Small;
                }
                else
                {
                    strength = TagCloudView.TagStrenth.VerySmall;
                }

                tagCloud.Tags.Add(new TagCloudView.Tag()
                {
                    Name = tag.Tag,
                    Strenth = strength
                });
            }

            MasterFrontEndView masterView = new MasterFrontEndView(App, languageForm, tagCloud);

            if (Tweeter != null)
            {
                masterView.TweeterPanel = new TweeterPanelView()
                {
                    Username = Tweeter.Username,
                    ImageUrl = Tweeter.ImageUrl,
                    TotalVotes = TweeterRepository.TotalVotesByTweeter(Tweeter, App),
                    ApplicationName = App.Title
                };
            }

            if (DefaultLanguage != null)
            {
                masterView.DefaultLanguage = DefaultLanguage;
            }

            ViewData["MasterView"] = masterView;

            base.OnActionExecuting(filterContext);
        }
Пример #2
0
        public ActionResult SetLanguage(LanguageSelectForm languageForm)
        {
            DefaultLanguage = LanguageRepository.FromId(languageForm.SelectedLanguage.GetValueOrDefault(-1));

            return Redirect(ReturnUrl);
        }
Пример #3
0
 public MasterFrontEndView(Application app, LanguageSelectForm languages, TagCloudView tagCloud)
 {
     this.App = app;
     this.Languages = languages;
     this.TagCloud = tagCloud;
 }