Пример #1
0
        public TwitterService Create(User user)
        {
            var isAuthenticated = user != null && !string.IsNullOrEmpty(user.AuthData.Secret)
                && !string.IsNullOrEmpty(user.AuthData.Token);

            if (!isAuthenticated)
                return new TwitterService(Config.Twitter.ConsumerKey, Config.Twitter.ConsumerSecret);

            return new TwitterService(Config.Twitter.ConsumerKey, Config.Twitter.ConsumerSecret,
                                      user.AuthData.Token, user.AuthData.Secret);
        }
Пример #2
0
 public AuthenticatedHomePageViewModel(User user, ITwitterFactory twitter)
 {
     Email = user.Email;
     var twitterUser = twitter.CurrentUser;
     if (twitterUser == null) throw new InvalidOperationException("twitterUser was not found or was just null");
     ProfilePicUrl = twitterUser.ProfileImageUrl;
     TwitterHandle = twitterUser.ScreenName;
     var service = twitter.Create();
     if (twitterUser == null) throw new InvalidOperationException("Twitter service was null or just couldn't be constructed");
     Favorites = service.ListFavoriteTweets(2, 5);
 }
Пример #3
0
        public EmailResult LoginEmail(User model)
        {
            model.LoginKey = Guid.NewGuid();
            userRepository.Save(model);

            Subject = "Welcome to TweetDigest";
            From = "*****@*****.**";
            To.Add(model.Email);
            return Email("LoginEmail", new LoginEmailViewModel
                {
                    TwitterHandle = model.TwitterHandles.FirstOrDefault() ?? model.Email,
                    ReturnKey = model.LoginKey.Value
                });
        }
Пример #4
0
            public void It_sends_login_email_when_twitter_creds_are_already_stored()
            {
                var user = new User
                    {
                        AuthData = new TwitterAuthData {Secret = "foo", Token = "bar"}
                    };
                mocker.Use<IUserRepository>(x => x.GetByEmail("*****@*****.**") == user);
                mocker.Use<IMailController>(x => x.LoginEmail(user) == new EmailResult(Mock.Of<IMailInterceptor>(), Mock.Of<IMailSender>(), new MailMessage(), string.Empty, string.Empty, Encoding.Default, false));

                Sut.Index(new SetEmailViewModel {UserEmail = "*****@*****.**"});
                mocker.Verify<IMailController>(x => x.LoginEmail(user));
            }
Пример #5
0
 public IEnumerable<TwitterStatus> GetFavoritesForUser(User user)
 {
     var twitterService = twitterFactory.Create(user);
     return twitterService.ListFavoriteTweets();
 }
Пример #6
0
 public void Save(User user)
 {
     users.Save(user);
 }
Пример #7
0
 private AuthenticatedHomePageViewModel GetAuthenticatedHomePageViewModel(User user)
 {
     return new AuthenticatedHomePageViewModel(user, twitterFactory);
 }