Ejemplo n.º 1
0
        // GET: /member/validate
        public virtual ActionResult ValidateEmail(string key)
        {
            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
            List<string> errorList = new List<string>();
            ProviderIssuedKey nonceKey = new ProviderIssuedKey();
            MessageVM returnMessageVM = new MessageVM
            {
                Image = ImageLibrary.Alert,
                CssClassContainer = "failure",
                Message = "Failed to validate e-mail.  Please <a href=\"" + Url.Action(MVC.Info.ContactUs()) + "\">contact us</a> to resolve the issue.",
                Title = "E-mail Validation Failure",
                LinkText = "Continue",
                LinkHref = Url.Action(MVC.Home.Index()),
                Details = errorList
            };

            if (nonceKey.Load(key))
            {
                ProviderEmail anEmail = new ProviderEmail();
                if (anEmail.Load(nonceKey.Data))
                {
                    anEmail.IsValidated = true;
                    anEmail.EditDate = DateTime.UtcNow;
                    anEmail.Save();

                    if (currentMember.IsLoggedOn && currentMember.IsActive)
                    {
                        returnMessageVM = new MessageVM
                        {
                            Image = ImageLibrary.Success,
                            CssClassContainer = "info",
                            Message = "Your e-mail has been validated",
                            Title = "E-mail validated"
                        };
                    }
                    else if (currentMember.Login(key, null, false, ref errorList) == ProviderCurrentMember.LoginEnum.success)
                    {
                        returnMessageVM = new MessageVM
                        {
                            Image = ImageLibrary.Success,
                            CssClassContainer = "info",
                            Message = "Welcome! Your account has been activated.  Explore our site:",
                            Title = "Account Activated",
                            Details = new List<string>
                            {
                                "<a href='" + Url.Action( MVC.Home.Index(null, null) ) + "' class='button'>Home Page</a> Go back to the main page.",
                                "<a href='" + Url.Action( MVC.Article.ArticleEdit(null, null) ) + "' class='button'>Publish</a> Become an author!  Publish an article.",
                                "<a href='" + Url.Action( MVC.Member.Profile(currentMember.Id.Value, null) ) + "' class='button'>Profile</a> Check out your new member profile " +
                                "where you can review your published articles and add details to show others who you are."
                            }
                        };
                    }
                }
            }

            return View("Message", returnMessageVM);
        }
Ejemplo n.º 2
0
        // GET: /member/ChangePassword
        public virtual ActionResult ChangePassword(string issuedKey)
        {
            ActionResult returnValue = null;

            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
            if (!string.IsNullOrWhiteSpace(issuedKey))
            {
                ProviderIssuedKey aKey = new ProviderIssuedKey();
                if (!aKey.Load(issuedKey))
                {
                    MessageVM returnMessageVM = new MessageVM
                    {
                        Image = ImageLibrary.Alert,
                        CssClassContainer = "failure",
                        Message = "Invalid key provided.  Please <a href=\"" + Url.Action(MVC.Info.ContactUs()) + "\">contact us</a> to resolve the issue.",
                        Title = "Login failure",
                        LinkText = "Continue",
                        LinkHref = Url.Action(MVC.Home.Index())
                    };
                    returnValue = View(MVC.Shared.Views.Message, returnMessageVM);
                }
                else
                {
                    // validate the e-mail if it wasn't already.
                    ProviderEmail anEmail = new ProviderEmail();
                    if (anEmail.Load(aKey.Data) && !anEmail.IsValidated)
                    {
                        anEmail.IsValidated = true;
                        anEmail.EditDate = DateTime.UtcNow;
                        anEmail.Save();
                    }

                    List<string> errorList = new List<string>();
                    if (currentMember.Login(issuedKey, null, false, ref errorList) == ProviderCurrentMember.LoginEnum.success)
                    {
                        MessageVM returnMessageVM = new MessageVM
                        {
                            Image = ImageLibrary.Alert,
                            CssClassContainer = "failure",
                            Message = "Failed to login.  Please <a href=\"" + Url.Action(MVC.Info.ContactUs()) + "\">contact us</a> to resolve the issue.",
                            Title = "Login failure",
                            LinkText = "Continue",
                            LinkHref = Url.Action(MVC.Home.Index()),
                            Details = errorList
                        };
                        returnValue = View(MVC.Shared.Views.Message, returnMessageVM);
                    }
                }
            }

            if(currentMember.IsLoggedOn)
            {
                ChangePasswordVM viewModel = new ChangePasswordVM
                {
                    CurrentMemberId = currentMember.Id.Value
                };
                returnValue = View(viewModel);
            }

            return returnValue;
        }
Ejemplo n.º 3
0
        public static bool UpdateAccount(ProviderCurrentMember currentMember, MemberDataVM data)
        {
            MailAddress validEmail;
            if (!string.IsNullOrWhiteSpace(data.Email) && IWStringUtility.TryParse(data.Email, out validEmail))
            {
                long? memberId = ProviderEmail.FindOwner(validEmail);

                // the e-mail has not been taken so we can take it
                if(!memberId.HasValue)
                {
                    List<ProviderEmail> emailList = currentMember.Emails;
                    if (!emailList.Exists(anEmail => anEmail.Email.Address == validEmail.Address))
                    {
                        // this e-mail doesn't exist so add it
                        ProviderEmail newEmail = new ProviderEmail();
                        newEmail.CreateDate = DateTime.UtcNow;
                        newEmail.EditDate = DateTime.UtcNow;
                        newEmail.Email = validEmail;
                        newEmail.IsValidated = false;
                        newEmail.MemberId = currentMember.Id.Value;
                        newEmail.Save();
                    }
                }
            }

            return true;
        }
Ejemplo n.º 4
0
        public virtual ActionResult RequestValidateEmail(string newEmail, long memberId)
        {
            ActionResult returnValue = null;
            MailAddress mailAddress = null;

            // check if email is unique and try to parse it
            // if unique (not taken) and valid format (and thus not validated) then send activation email
            if (!IWStringUtility.TryParse(newEmail, out mailAddress))
            {
                MessageVM messageModel = new MessageVM
                {
                    Image = ImageLibrary.Alert,
                    CssClassContainer = "failure",
                    Message = "Invalid e-mail",
                    Title = ErrorStrings.TITLE_ERROR,
                    LinkText = "Continue",
                    LinkHref = Url.Action(MVC.Member.Account(memberId, null)),
                };
                returnValue = View("Message", messageModel);
            }
            else if (ProviderEmail.FindOwner(mailAddress, true) != null)
            {
                MessageVM messageModel = new MessageVM
                {
                    Image = ImageLibrary.Alert,
                    CssClassContainer = "failure",
                    Message = "E-mail is already taken.",
                    Title = ErrorStrings.TITLE_ERROR,
                    LinkText = "Continue",
                    LinkHref = Url.Action(MVC.Member.Account(memberId, null)),
                };
                returnValue = View("Message", messageModel);
            }
            else if (!ProviderMember.Exists(memberId))
            {
                MessageVM messageModel = new MessageVM
                {
                    Image = ImageLibrary.Alert,
                    CssClassContainer = "failure",
                    Message = "No member with id "+memberId,
                    Title = ErrorStrings.TITLE_ERROR,
                    LinkText = "Continue",
                    LinkHref = Url.Action(MVC.Member.Account(memberId, null)),
                };
                returnValue = View("Message", messageModel);
            }
            else
            {
                ProviderMember member = new ProviderMember(memberId);
                ProviderEmail anEmail = new ProviderEmail();
                anEmail.MemberId = memberId;
                anEmail.IsValidated = false;
                anEmail.CreateDate = DateTime.UtcNow;
                anEmail.EditDate = DateTime.UtcNow;
                anEmail.Email = mailAddress;
                anEmail.Save();

                EmailManager.Instance.SendActivationEmail(mailAddress, member);

                returnValue = RedirectToAction(MVC.Member.EmailValidationSent());
            }

            return returnValue;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Function to update or create an member account with openId information.
        /// </summary>
        /// <param name="openId">openId of the member account we wish to create or update</param>
        /// <param name="email">e-mail information of the member</param>
        /// <param name="host">the open id provider hostname (www.google.com for instance)</param>
        /// <returns>true if the member was successfully updated/created.</returns>
        public static bool UpdateMemberOpenId(string openId, MailAddress email, string host)
        {
            // check if this member exists already
            ProviderMember aMember;
            ProviderEmail anEmailId = new ProviderEmail();
            ProviderOpenId anOpenId = new ProviderOpenId();

            // Prepare the e-mail
            if (email != null)
            {
                if (!anEmailId.Load(email.Address))
                {
                    anEmailId.CreateDate = DateTime.UtcNow;
                    anEmailId.EditDate = DateTime.UtcNow;
                    anEmailId.Email = email;
                    anEmailId.IsValidated = true;
                }
            }

            // Prepare the openId
            if (!anOpenId.Load(openId))
            {
                anOpenId.CreateDate = DateTime.UtcNow;
                anOpenId.EditDate = DateTime.UtcNow;
                anOpenId.OpenId = openId;
                anOpenId.DisplayName = host;
                anOpenId.IsValidated = true;
            }

            // TODO: my gut tells me these if statements can possibly be reduced to something simpler
            if (anOpenId.IsNew && anEmailId.IsNew)
            {
                // This person doesn't exist yet so create them
                aMember = new ProviderMember();
                aMember.CreateDate = DateTime.UtcNow;
                aMember.EditDate = DateTime.UtcNow;
                aMember.Save();

                // create the e-mail
                if (email != null)
                {
                    anEmailId.MemberId = aMember.Id.Value;
                    anEmailId.Save();
                }

                // create the openId
                anOpenId.MemberId = aMember.Id.Value;
                anOpenId.Save();
            }
            else if (!anOpenId.IsNew && anEmailId.IsNew && email != null)
            {
                // this person has an account already with an open id but no e-mail so just add the e-mail to the account
                aMember = new ProviderMember(anOpenId.MemberId);
                aMember.EditDate = DateTime.UtcNow;
                aMember.Save();

                anEmailId.MemberId = aMember.Id.Value;
                anEmailId.Save();
            }
            else if (anOpenId.IsNew && !anEmailId.IsNew)
            {
                // this person has an account already with an e-mail but no openId so just add the openId to the account
                aMember = new ProviderMember(anEmailId.MemberId);
                aMember.EditDate = DateTime.UtcNow;
                aMember.Save();

                anOpenId.MemberId = aMember.Id.Value;
                anOpenId.Save();
            }
            else if ( !anOpenId.IsNew && !anEmailId.IsNew && anOpenId.MemberId != anEmailId.MemberId)
            {
                // TODO: Crap two different accounts!
                // Do nothing for now but what we really want to do is try and merge the two accounts (with user permission of course).
            }
            else
            {
                // No updates are required
            }

            return true;
        }
Ejemplo n.º 6
0
        public static bool Save(RegisterVM model, ref ProviderMember registerMember)
        {
            registerMember.Password = model.Password;
            registerMember.CreateDate = DateTime.UtcNow;
            registerMember.EditDate = DateTime.UtcNow;
            registerMember.Save();

            if (!string.IsNullOrWhiteSpace(model.Email))
            {
                ProviderEmail anEmail = new ProviderEmail();
                anEmail.MemberId = registerMember.Id.Value;
                anEmail.IsValidated = false;
                anEmail.CreateDate = DateTime.UtcNow;
                anEmail.EditDate = DateTime.UtcNow;
                anEmail.Email = new MailAddress(model.Email);
                anEmail.Save();
            }

            if(!string.IsNullOrWhiteSpace(model.UserName))
            {
                ProviderUserName aUserName = new ProviderUserName();
                aUserName.MemberId = registerMember.Id.Value;
                aUserName.CreateDate = DateTime.UtcNow;
                aUserName.EditDate = DateTime.UtcNow;
                aUserName.UserName = model.UserName;
                aUserName.Save();
            }

            return true;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Function that fetches the owner of the article
        /// </summary>
        /// <param name="info">Info regarding a particular e-mail article</param>
        /// <returns>The provider member who is the owner of this e-mail article</returns>
        public static ProviderMember GetEmailOwner(MessageInfo info)
        {
            ProviderMember aMember;
            string email = info.Envelope.Sender[0].Address;
            MailAddress address = new MailAddress(email);
            long? memberId = ProviderEmail.FindOwner(address, null);
            if (memberId.HasValue)
            {
                _log.Info("E-mail sender has an account.");
                aMember = new ProviderMember(memberId.Value);
            }
            else
            {
                _log.Info("Person does not have an account. Creating one.");
                aMember = new ProviderMember();
                aMember.CreateDate = DateTime.UtcNow;
                aMember.EditDate = DateTime.UtcNow;
                aMember.Save();

                ProviderEmail memberEmail = new ProviderEmail();
                memberEmail.CreateDate = DateTime.UtcNow;
                memberEmail.EditDate = DateTime.UtcNow;
                memberEmail.Email = address;
                memberEmail.IsValidated = true;
                memberEmail.MemberId = aMember.Id.Value;
                memberEmail.Save();
            }
            return aMember;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Function to help determine the owner of an article. If sufficient information is
        /// provided and the owner does not exist in the system then they will be created.
        /// </summary>
        /// <param name="model">view model containing the data of the new article</param>
        /// <param name="currentMember">the current member using the site</param>
        /// <returns>Returns a ProviderMember who is the owner of the article</returns>
        public static ProviderMember GetArticleOwner(ArticleEditorVM model, ProviderArticle anArticle, ProviderCurrentMember currentMember)
        {
            ProviderMember owningMember;

            if (anArticle.MemberId.HasValue)
            {
                owningMember = new ProviderMember(anArticle.MemberId.Value);
            }
            else if (anArticle.IsNew || !string.IsNullOrEmpty(model.ArticleEmail))
            {
                // Have we been provided with an e-mail of the owner?
                if (!string.IsNullOrEmpty(model.ArticleEmail))
                {
                    MailAddress email = new MailAddress(model.ArticleEmail);
                    long? memberId = ProviderEmail.FindOwner(email, true);
                    if (memberId.HasValue)
                    {
                        // The owner already exists in our system so just retrieve them
                        owningMember = new ProviderMember(memberId.Value);
                    }
                    else
                    {
                        // the owner doesn't exists so create them
                        owningMember = new ProviderMember();
                        owningMember.CreateDate = DateTime.UtcNow;
                        owningMember.EditDate = DateTime.UtcNow;
                        owningMember.Save();

                        // attach the e-mail to this member
                        ProviderEmail anEmail = new ProviderEmail();
                        anEmail.MemberId = owningMember.Id.Value;
                        anEmail.IsValidated = false;
                        anEmail.CreateDate = DateTime.UtcNow;
                        anEmail.EditDate = DateTime.UtcNow;
                        anEmail.Email = email;
                        anEmail.Save();
                    }
                }
                else
                {
                    // no e-mail provided so just use whoever is currently logged on, whether they be anonymous or not
                    owningMember = currentMember;
                }
            }
            else
            {
                // this article has no owner so just return a blank member
                owningMember = new ProviderMember();
            }

            return owningMember;
        }
        /*
        public override bool Copy(Provider untyped)
        {
            //Never copy over the id, otherwise we would be creating
            //a pseudo-reference copy, which we don't want.
            //Do not copy over the system times and only the business logic
            //times since the system times are specific to a given instance.
            ProviderAlternateMemberId anAlternateMemberId = (ProviderAlternateMemberId)untyped;
            _entityAlternateMemberId.MemberId = anAlternateMemberId._entityAlternateMemberId.MemberId;
            _entityAlternateMemberId.AlternateType = anAlternateMemberId._entityAlternateMemberId.AlternateType;
            _entityAlternateMemberId.AlternateId = anAlternateMemberId._entityAlternateMemberId.AlternateId;
            _entityAlternateMemberId.IsValidated = anAlternateMemberId._entityAlternateMemberId.IsValidated;
            _entityAlternateMemberId.IsNonce = anAlternateMemberId._entityAlternateMemberId.IsNonce;
            _entityAlternateMemberId.ExpiryDate = anAlternateMemberId._entityAlternateMemberId.ExpiryDate;
            _entityAlternateMemberId.EditDate = anAlternateMemberId._entityAlternateMemberId.EditDate;
            _entityAlternateMemberId.CreateDate = anAlternateMemberId._entityAlternateMemberId.CreateDate;
            _entityAlternateMemberId.UsePassword = anAlternateMemberId._entityAlternateMemberId.UsePassword;
            _entityAlternateMemberId.IsHidden = anAlternateMemberId._entityAlternateMemberId.IsHidden;
            _entityObject = _entityAlternateMemberId;
            return true;
        }
        */
        public bool ValidateData()
        {
            bool returnValue = true;
            if (!string.IsNullOrWhiteSpace(Data))
            {
                MailAddress email = null;

                // if this is an alt id used to validate an e-mail then do so.
                if (IWStringUtility.TryParse(Data, out email))
                {
                    ProviderEmail altIdEmail = new ProviderEmail();
                    if (altIdEmail.Load(email.Address))
                    {
                        altIdEmail.IsValidated = true;
                        altIdEmail.Save();
                    }
                }
                else
                {
                    Uri domain = null;

                    // if this is an alt id used to validate an a domain then do so.
                    if (Uri.TryCreate(Data, UriKind.Absolute, out domain))
                    {
                        ProviderDomain altIdDomain = new ProviderDomain();
                        if (altIdDomain.Load(domain.AbsoluteUri))
                        {
                            altIdDomain.IsValidated = true;
                            altIdDomain.Save();
                        }
                    }
                }
            }
            return returnValue;
        }