Example #1
0
 public bool HasValidAltId(ProviderAlternateMemberId.AlternateType anAltType)
 {
     return Id.HasValue && _entityMember.AlternateMemberIds
                                             .Any(altId => altId.IsValidated &&
                                                             altId.AlternateType == (int)anAltType);
 }
        /// <summary>
        /// Function to validate and login an active member
        /// </summary>
        /// <param name="alternateId">one of all possible alternateIds a member could have</param>
        /// <param name="password">password of the member we wish to login. Password can be null/empty if no password is expected with this alternateId.</param>
        /// <param name="rememberMe">If true then the system will give the member a cookie that will last a month. The system will use this cookie to auto-login the member.</param>
        /// <param name="errorList">if the login fails for whatever reason then all the errors will be returned in the errorList</param>
        /// <returns>true if the function succeeded in login the member in and false otherwise.</returns>
        public LoginEnum Login(string alternateId, string password, bool rememberMe, ref List<string> errorList)
        {
            LoginEnum returnValue = LoginEnum.unknown;
            _isLoggedOn = false;

            ProviderAlternateMemberId anAltId = new ProviderAlternateMemberId();
            if (!anAltId.Load(alternateId) ||
                 (anAltId.UsePassword && !Exists(anAltId.MemberId, password)))
            {
                returnValue = LoginEnum.unknown;
                errorList.Add("Invalid Id or Password.");
            }
            else if (anAltId.HasExpired)
            {
                returnValue = LoginEnum.expired;
                // The id has expired and was decommissioned so return an error
                errorList.Add("Your Id has expired.");
            }
            else
            {
                try
                {
                    Load(anAltId.MemberId);

                    if (!anAltId.IsValidated)
                    {
                        returnValue = LoginEnum.invalid;
                        errorList.Add("Id has not been validated.");
                    }
                    else if (IsBanned)
                    {
                        returnValue = LoginEnum.banned;
                        errorList.Add("Your account has been banned.");
                    }
                    else
                    {
                        returnValue = LoginEnum.success;
                        anAltId.ValidateData();
                        CurrentWorkSpace.Save(this);
                        CreateLoginCookie(rememberMe, ref errorList);
                        _isLoggedOn = true;
                    }

                    if (_isLoggedOn)
                    {
                        // Try and decommission the alternate id
                        if (!anAltId.TryDecommission())
                        {
                            // The alternate id was not decommissioned and is still valid so mark it as used
                            anAltId.Used();
                            anAltId.Save();
                        }
                    }
                }
                catch (Exception caughtException)
                {
                    InsideWordWebLog.Instance.Log.Error(caughtException);
                    errorList.Add("Invalid Id or Password.");
                }
            }

            return returnValue;
        }