/// <summary>
        /// ctor the Mighty
        /// </summary>
        public BrewSessionCommentEmailMessage(IWebSettings webSettings, BrewSession brewSession, string commenterUsername,
            UserSummary userToNotify, BrewSessionComment brewSessionComment, BrewgrUrlBuilder brewgrUrlBuilder)
            : base(webSettings)
        {
            this.WebSettings = webSettings;
            this.BrewSession = brewSession;
            this.CommenterUsername = commenterUsername;
            this.UserToNotify = userToNotify;
            this.BrewSessionComment = brewSessionComment;
            this.BrewgrUrlBuilder = brewgrUrlBuilder;

            // Set Sender
            this.SenderAddress = webSettings.SenderAddress;
            this.SenderDisplayName = webSettings.SenderDisplayName;

            // Set Recipient
            this.ToRecipients.Add(userToNotify.EmailAddress);

            // Build Subject
            if (brewSession.UserId == userToNotify.UserId)
            {
                this.Subject = string.Format("{0} commented on your brew session for {1}", commenterUsername, brewSession.RecipeSummary.RecipeName);
            }
            else
            {
                this.Subject = string.Format("{0} also left a comment on the brew session for {1}", commenterUsername, brewSession.RecipeSummary.RecipeName);
            }
        }
		/// <summary>
		/// ctor the Mighty
		/// </summary>
		public RecipeCommentEmailMessage(IWebSettings webSettings, RecipeSummary recipeSummary, string commenterUsername, 
			UserSummary userToNotify, RecipeComment recipeComment, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
		{
			this.WebSettings = webSettings;
			this.RecipeSummary = recipeSummary;
			this.CommenterUsername = commenterUsername;
			this.UserToNotify = userToNotify;
			this.RecipeComment = recipeComment;
			this.BrewgrUrlBuilder = brewgrUrlBuilder;

			// Set Sender
			this.SenderAddress = webSettings.SenderAddress;
			this.SenderDisplayName = webSettings.SenderDisplayName;

			// Set Recipient
			this.ToRecipients.Add(userToNotify.EmailAddress);

			// Build Subject
			if (recipeSummary.CreatedBy == userToNotify.UserId)
			{
				this.Subject = string.Format("{0} commented on your recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
			else
			{
				this.Subject = string.Format("{0} also left a comment on the recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
		}
        /// <summary>
        /// ctor the Mighty
        /// </summary>
        public BrewSessionCommentEmailMessage(IWebSettings webSettings, BrewSession brewSession, string commenterUsername,
                                              UserSummary userToNotify, BrewSessionComment brewSessionComment, BrewgrUrlBuilder brewgrUrlBuilder)
            : base(webSettings)
        {
            this.WebSettings        = webSettings;
            this.BrewSession        = brewSession;
            this.CommenterUsername  = commenterUsername;
            this.UserToNotify       = userToNotify;
            this.BrewSessionComment = brewSessionComment;
            this.BrewgrUrlBuilder   = brewgrUrlBuilder;

            // Set Sender
            this.SenderAddress     = webSettings.SenderAddress;
            this.SenderDisplayName = webSettings.SenderDisplayName;

            // Set Recipient
            this.ToRecipients.Add(userToNotify.EmailAddress);

            // Build Subject
            if (brewSession.UserId == userToNotify.UserId)
            {
                this.Subject = string.Format("{0} commented on your brew session for {1}", commenterUsername, brewSession.RecipeSummary.RecipeName);
            }
            else
            {
                this.Subject = string.Format("{0} also left a comment on the brew session for {1}", commenterUsername, brewSession.RecipeSummary.RecipeName);
            }
        }
        /// <summary>
        /// ctor the Mighty
        /// </summary>
        public RecipeCommentEmailMessage(IWebSettings webSettings, RecipeSummary recipeSummary, string commenterUsername,
                                         UserSummary userToNotify, RecipeComment recipeComment, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
        {
            this.WebSettings       = webSettings;
            this.RecipeSummary     = recipeSummary;
            this.CommenterUsername = commenterUsername;
            this.UserToNotify      = userToNotify;
            this.RecipeComment     = recipeComment;
            this.BrewgrUrlBuilder  = brewgrUrlBuilder;

            // Set Sender
            this.SenderAddress     = webSettings.SenderAddress;
            this.SenderDisplayName = webSettings.SenderDisplayName;

            // Set Recipient
            this.ToRecipients.Add(userToNotify.EmailAddress);

            // Build Subject
            if (recipeSummary.CreatedBy == userToNotify.UserId)
            {
                this.Subject = string.Format("{0} commented on your recipe, {1}", commenterUsername, recipeSummary.RecipeName);
            }
            else
            {
                this.Subject = string.Format("{0} also left a comment on the recipe, {1}", commenterUsername, recipeSummary.RecipeName);
            }
        }
		/// <summary>
		/// Updates the persisted user
		/// </summary>
		public void Update(UserSummary userSummary)
		{
			var httpContext = HttpContext.Current;
			httpContext.Session.Remove(UserSessionKey);

			this.Persist(userSummary);
		}
		/// <summary>
		/// Attempts to login a returning user 
		/// </summary>
		public bool ReturnLogin(int userId, out UserSummary userSummary)
		{
			if(userId <= 0)
			{
				throw new ArgumentOutOfRangeException("userId");
			}

			userSummary = null;

			var matchingUser = this.Repository.GetSet<User>()
				.Include(x => x.UserAdmin)
				.Include(x => x.UserPartnerAdmins)
				.FirstOrDefault(x => x.UserId == userId);

			if (matchingUser == null)
			{
				return false;
			}

			// Log Login and get Summary
			this.TrackLogin(matchingUser.UserId);
			userSummary = Mapper.Map(matchingUser, new UserSummary());

			return true;			
		}
Пример #7
0
        /// <summary>
        /// Resolves the current User
        /// </summary>
        public UserSummary Resolve()
        {
            var httpContext = HttpContext.Current;

            if (httpContext.Session[UserSessionKey] != null)
            {
                return(httpContext.Session[UserSessionKey] as UserSummary);
            }

            // Get User Id
            var identity = HttpContext.Current.User.Identity;

            if (string.IsNullOrWhiteSpace(identity.Name))
            {
                return(null);
            }

            var userId = Int32.Parse(identity.Name);

            UserSummary userSummary = null;

            using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
            {
                if (!this.UserLoginService.ReturnLogin(userId, out userSummary))
                {
                    throw new SecurityException("Could not resolve the user");
                }

                unitOfWork.Commit();
            }

            this.Persist(userSummary);

            return(userSummary);
        }
Пример #8
0
        /// <summary>
        /// Updates the persisted user
        /// </summary>
        public void Update(UserSummary userSummary)
        {
            var httpContext = HttpContext.Current;

            httpContext.Session.Remove(UserSessionKey);

            this.Persist(userSummary);
        }
		/// <summary>
		/// Persists the user for resolution
		/// </summary>
		public void Persist(UserSummary userSummary)
		{
			if(userSummary == null)
			{
				throw new ArgumentNullException("userSummary");
			}

			var httpContext = HttpContext.Current;
			httpContext.Session.Add(UserSessionKey, userSummary);
		}
Пример #10
0
        /// <summary>
        /// Persists the user for resolution
        /// </summary>
        public void Persist(UserSummary userSummary)
        {
            if (userSummary == null)
            {
                throw new ArgumentNullException("userSummary");
            }

            var httpContext = HttpContext.Current;

            httpContext.Session.Add(UserSessionKey, userSummary);
        }
		/// <summary>
		/// ctor the Mighty
		/// </summary>
		public BrewerFollowEmailMessage(IWebSettings webSettings, string followingUsername, UserSummary userToNotify, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
		{
			this.WebSettings = webSettings;
			this.FollowingUsername = followingUsername;
			this.UserToNotify = userToNotify;
			this.BrewgrUrlBuilder = brewgrUrlBuilder;

			// Set Sender
			this.SenderAddress = webSettings.SenderAddress;
			this.SenderDisplayName = webSettings.SenderDisplayName;

			// Set Recipient
			this.ToRecipients.Add(userToNotify.EmailAddress);

			// Build Subject
			this.Subject = followingUsername + " is now following you!";
		}
Пример #12
0
        /// <summary>
        /// ctor the Mighty
        /// </summary>
        public BrewerFollowEmailMessage(IWebSettings webSettings, string followingUsername, UserSummary userToNotify, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
        {
            this.WebSettings       = webSettings;
            this.FollowingUsername = followingUsername;
            this.UserToNotify      = userToNotify;
            this.BrewgrUrlBuilder  = brewgrUrlBuilder;

            // Set Sender
            this.SenderAddress     = webSettings.SenderAddress;
            this.SenderDisplayName = webSettings.SenderDisplayName;

            // Set Recipient
            this.ToRecipients.Add(userToNotify.EmailAddress);

            // Build Subject
            this.Subject = followingUsername + " is now following you!";
        }
		/// <summary>
		/// ctor the Mighty
		/// </summary>
		public RecipeCommentEmailMessage(IWebSettings webSettings, RecipeSummary recipeSummary, string commenterUsername, UserSummary userToNotify)
		{
			RecipeSummary = recipeSummary;
			CommenterUsername = commenterUsername;
			UserToNotify = userToNotify;

			this.SenderAddress = webSettings.SenderAddress;
			this.SenderDisplayName = webSettings.SenderDisplayName;

			this.ToRecipients.Add(userToNotify.EmailAddress);

			// Build Subject
			if (recipeSummary.CreatedBy == userToNotify.UserId)
			{
				this.Subject = string.Format("{0} commented on your recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
			else
			{
				this.Subject = string.Format("{0} also left a comment on the recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
		}
		/// <summary>
		/// Attempts to log the user in
		/// </summary>
		public bool Login(string emailOrUsername, string password, out UserSummary userSummary)
		{
			if (string.IsNullOrWhiteSpace(emailOrUsername))
			{
				throw new ArgumentNullException("emailOrUsername");
			}

			if (string.IsNullOrWhiteSpace(password))
			{
				throw new ArgumentNullException("password");
			}

			userSummary = null;

			var matchingUser = this.Repository.GetSet<User>()
				.Include(x => x.UserAdmin)
				.Include(x => x.UserPartnerAdmins)
				.Where(x => x.IsActive)
				.FirstOrDefault(x => x.Username == emailOrUsername || x.EmailAddress == emailOrUsername);

			if (matchingUser == null)
			{
				return false;
			}

			if (!this.Hasher.Compare(password, matchingUser.Password))
			{
				return false;
			}

			userSummary = Mapper.Map(matchingUser, userSummary);

			// Log Login and get Summary
			this.TrackLogin(matchingUser.UserId);

			return true;
		}
Пример #15
0
		/// <summary>
		/// Signs the user in and performs redirection
		/// </summary>
		ActionResult SignInAndRedirect(UserSummary userSummary, bool persistLogin = false)
		{
			// Sign User In
			this.SignIn(userSummary, persistLogin);

			// Redirect
			var redirectUrl = (Session["OAuthReturnUrl"] ?? Request["ReturnUrl"]) != null ? string.Format("{0}{1}", this.WebSettings.RootPath, Session["OAuthReturnUrl"].ToString()) 
				: this.WebSettings.RootPath; 

			Session.Remove("OAuthReturnUrl");

			return RedirectPermanent(redirectUrl);
		}
Пример #16
0
		/// <summary>
		/// Signs the User In
		/// </summary>
		void SignIn(UserSummary userSummary, bool persistLogin)
		{
			// Sign User In
			this.AuthenticationService.SignIn(userSummary.UserId.ToString(), persistLogin);
			this.UserResolver.Persist(userSummary);
		}
Пример #17
0
		/// <summary>
		/// Appends a success message for LoginViaDialog
		/// </summary>
		void AppendLoginViaDialogSuccessMessage(UserSummary userSummary, bool editMode = false)
		{
			this.AppendMessage(new SuccessMessage { Text = "Thank you " + userSummary.FirstName + ", " + (editMode ? "You have been logged in" : "Your recipe is being saved") });
		}