コード例 #1
0
        public ActionResult UserProfile(string userName, UserProfile profile)
        {
            if (profile.UserName != userName)
            {
                return new HttpUnauthorizedResult();
            }

            string message = string.Empty;

            if (!string.IsNullOrWhiteSpace(profile.WebsiteUrl))
            {
                if (!Uri.IsWellFormedUriString(string.Format("http://{0}", profile.WebsiteUrl), UriKind.Absolute))
                {
                    message = "The website url doesn't appear to be a valid URL.";
                    ModelState.AddModelError(key: "WebsiteUrl", errorMessage: message);
                }
            }

            if (ModelState.IsValid)
            {
                userProfileRepository.UpdateUserProfile(profile);
                message = "Your profile has been updated successfully.";
            }

            return RedirectToAction("Edit", new { Message = message });
        }
コード例 #2
0
        public SessionControllerBuilder ForUser(UserProfile newUser)
        {
            user = newUser;
            userProfileRepository.GetUserProfileByUserName(newUser.UserName).Returns(newUser);

            return this;
        }
コード例 #3
0
        public IEnumerable<Session> LoadSessions(UserProfile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            return sessionRepository.GetSessionsSubmittedBy(profile.UserName);
        }
コード例 #4
0
 internal static Site.MailMessage FromTemplate(IMailTemplate mailTemplate, UserProfile userProfile)
 {
     return new TestMailMessage
     {
         To = new MailAddress(userProfile.EmailAddress, userProfile.Name),
         From = new MailAddress("*****@*****.**", "DDD East Anglia"),
         Subject = mailTemplate.RenderSubjectLine(),
         Body = mailTemplate.RenderBody()
     };
 }
コード例 #5
0
        public IEnumerable<Session> LoadSessions(UserProfile profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            var sessions = sessionRepository.GetSessionsSubmittedBy(profile.UserName);
            return sessions.Where(s => SelectedSessions.SessionIds.Contains(s.SessionId));
        }
コード例 #6
0
 private SpeakerProfile createSpeakerProfile(UserProfile userProfile, int numberOfSubmittedSessions)
 {
     return new SpeakerProfile
     {
         UserId = userProfile.UserId,
         UserName = userProfile.UserName,
         Name = userProfile.Name,
         EmailAddress = userProfile.EmailAddress,
         NewSpeaker = userProfile.NewSpeaker,
         NumberOfSubmittedSessions = numberOfSubmittedSessions
     };
 }
        public void FilterOutUsersWhoHaveNotBeenSelected()
        {
            var profileFilter = new SelectedSpeakerProfileFilter();

            var profile1 = new UserProfile {UserId = 123};
            var profile2 = new UserProfile {UserId = 48};
            var profile3 = new UserProfile {UserId = 456};

            var profiles = profileFilter.FilterProfiles(new[] {profile1, profile2, profile3});

            CollectionAssert.AreEquivalent(new[] {profile2}, profiles);
        }
コード例 #8
0
        public void Notify(UserProfile user)
        {
            MailMessage message = new MailMessage
            {
                To = new MailAddress(user.EmailAddress, user.Name),
                From = FromAddress,
                Subject = mailTemplate.RenderSubjectLine(),
                Body = mailTemplate.RenderBody()
            };

            postman.Deliver(message);
        }
        public void FilterOutUsersWhoHaveNotSubmittedSessions()
        {
            var sessionRepository = Substitute.For<ISessionRepository>();
            var profileFilter = new SubmittedSessionProfileFilter(sessionRepository);

            var profile1 = new UserProfile {UserName = "******"};
            var profile2 = new UserProfile {UserName = "******"};
            var profile3 = new UserProfile {UserName = "******"};
            sessionRepository.GetSessionsSubmittedBy("bob").Returns(new[] {new Session {SpeakerUserName = "******"}});

            var profiles = profileFilter.FilterProfiles(new[] {profile1, profile2, profile3});

            CollectionAssert.AreEquivalent(new[] {profile3}, profiles);
        }
コード例 #10
0
        public static void SetupWithAuthenticatedUser(this Controller controller, UserProfile user)
        {
            if (user == null)
            {
                return;
            }

            var userIdentity = Substitute.For<IIdentity>();
            userIdentity.Name.Returns(user.UserName);

            var userPrincipal = Substitute.For<IPrincipal>();
            userPrincipal.Identity.Returns(userIdentity);

            var httpContext = Substitute.For<HttpContextBase>();
            httpContext.User.Returns(userPrincipal);

            controller.ControllerContext = new ControllerContext {  HttpContext = httpContext };
        }
コード例 #11
0
        public void TestThat_ResetPassword_SendsAnEmailToTheUser_WhenAValidUserIsFound_FromAUserName()
        {
            var userProfileRepository = Substitute.For<IUserProfileRepository>();
            var userProfile = new UserProfile { UserName = "******", EmailAddress = "*****@*****.**" };
            userProfileRepository.GetUserProfileByUserName("bob").Returns(userProfile);
            var postman = Substitute.For<IPostman>();
            var controller = new ResetPasswordController(userProfileRepository, Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(postman));
            controller.SetupWithHttpContextAndUrlHelper();

            var model = new ResetPasswordStepOneModel { UserName = "******" };
            controller.ResetPassword(model);

            var expectedMessage = MailMessage.FromTemplate(PasswordResetMailTemplate.Create(string.Empty), userProfile);
            postman.Received().Deliver(expectedMessage);
        }
コード例 #12
0
        private SessionDisplayModel CreateDisplayModel(Session session, UserProfile profile)
        {
            var isUsersSession = Request.IsAuthenticated && session.SpeakerUserName == User.Identity.Name;
            var tweetLink = CreateTweetLink(isUsersSession, session.Title,
                                            Url.Action("Details", "Session", new { id = session.SessionId },
                                                       Request.Url.Scheme));

            var displayModel = new SessionDisplayModel
                {
                    SessionId = session.SessionId,
                    SessionTitle = session.Title,
                    SessionAbstract = session.Abstract,
                    SpeakerId = profile.UserId,
                    SpeakerName = profile.Name,
                    SpeakerUserName = session.SpeakerUserName,
                    SpeakerGravatarUrl = profile.GravatarUrl(),
                    TweetLink = tweetLink,
                    IsUsersSession = isUsersSession
                };
            return displayModel;
        }
コード例 #13
0
        public void ShouldEmailTheUserTheirSubmission_WhenCreating()
        {
            var postman = Substitute.For<IPostman>();
            var bob = new UserProfile { Name = "Bob", EmailAddress = "*****@*****.**", UserName = "******" };
            var session = new Session
            {
                Title = "Bob's awesome session",
                Abstract = "This is going to be awesome!"
            };

            var controller = new SessionControllerBuilder()
                .WithPostman(postman)
                .WhenSubmissionsAreOpen()
                .ForUser(bob)
                .Submitting(session)
                .Build();

            controller.Create(session);

            var expectedMailMessage = MailMessage.FromTemplate(SessionCreatedMailTemplate.Create(session), bob);
            postman.Received().Deliver(expectedMailMessage);
        }
コード例 #14
0
        public void ShouldEmailTheUserTheirUpdatedSubmission_WhenEditing()
        {
            var postman = Substitute.For<IPostman>();
            var bob = new UserProfile { Name = "Bob", EmailAddress = "*****@*****.**", UserName = "******" };
            var session = new Session
            {
                Title = "Bob's even more awesome session",
                Abstract = "Just wait until you see it!",
                SpeakerUserName = bob.UserName,
                SessionId = 1
            };

            var controller = new SessionControllerBuilder()
                .WithPostman(postman)
                .ForUser(bob)
                .Updating(session)
                .Build();

            controller.Edit(bob.UserName, session);

            var expectedMailMessage = MailMessage.FromTemplate(SessionUpdatedMailTemplate.Create(session), bob);
            postman.Received().Deliver(expectedMailMessage);
        }
コード例 #15
0
        public ActionResult Edit(UserProfile userProfile)
        {
            if (ModelState.IsValid)
            {
                userProfileRepository.UpdateUserProfile(userProfile);
                return RedirectToAction("Index");
            }

            return View(userProfile);
        }
コード例 #16
0
 private static UserModel CreateUserModel(UserProfile profile)
 {
     return new UserModel
         {
             UserId = profile.UserId,
             UserName = profile.UserName,
             Name = profile.Name,
             EmailAddress = profile.EmailAddress,
             MobilePhone = profile.MobilePhone,
             WebsiteUrl = profile.WebsiteUrl,
             TwitterHandle = profile.TwitterHandle,
             Bio = profile.Bio,
             NewSpeaker = profile.NewSpeaker,
             GravatarUrl = profile.GravatarUrl()
         };
 }
コード例 #17
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider;
            string providerUserId;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("ManageLogins");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                UserProfile user = userProfileRepository.GetUserProfileByUserName(model.UserName);

                // Check if user already exists
                if (user == null)
                {
                    // Insert name into the profile table
                    var userProfile = new UserProfile { UserName = model.UserName, Name = model.Name, EmailAddress = model.EmailAddress };
                    userProfileRepository.AddUserProfile(userProfile);

                    OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                    OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                    return RedirectToLocal(returnUrl);
                }

                ModelState.AddModelError("UserName", ErrorCodeToString(MembershipCreateStatus.DuplicateUserName));
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
コード例 #18
0
        private SpeakerDisplayModel CreateDisplayModel(UserProfile userProfile, IEnumerable<Session> sessions)
        {
            var isCurrentUser = Request.IsAuthenticated && userProfile.UserName == User.Identity.Name;
            var userSessions = sessions.ToDictionary(s => s.SessionId, s => s.Title);

            return new SpeakerDisplayModel
                {
                    IsCurrentUser = isCurrentUser,
                    Name = userProfile.Name,
                    Bio = userProfile.Bio,
                    GravatarUrl = userProfile.GravatarUrl(),
                    TwitterHandle = userProfile.TwitterHandle,
                    WebsiteUrl = userProfile.WebsiteUrl,
                    Sessions = userSessions
                };
        }
コード例 #19
0
        private void SendEmailToUser(UserProfile profile, string passwordResetToken)
        {
            string protocol = Request.Url.Scheme;
            string resetUrl = Url.Action("EmailConfirmation", "ResetPassword", new { token = passwordResetToken }, protocol);

            var mailTemplate = PasswordResetMailTemplate.Create(resetUrl);
            emailMessengerFactory.CreateEmailMessenger(mailTemplate).Notify(profile);
        }
コード例 #20
0
        public void Edit_SavesTheUserProfileCorrectly()
        {
            var controller = CreateController();
            var userProfile = new UserProfile { UserName = "******", Name = "Fred Bloggs", EmailAddress = "*****@*****.**" };

            controller.Edit(userProfile);

            userProfileRepository.Received().UpdateUserProfile(userProfile);
        }
コード例 #21
0
 public UserProfile AddUserProfile(UserProfile userProfile)
 {
     return db.UserProfiles.Insert(userProfile);
 }
コード例 #22
0
 public void UpdateUserProfile(UserProfile profile)
 {
     db.UserProfiles.UpdateByUserId(profile);
 }