Example #1
0
        public void LoadByDomainName_False()
        {
            Person p = new Person();
            Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));

            m_Person = new Person();
            m_Person.LastName = new MLText("en", "Yakimov");
            m_Person.PersonGender = Person.Gender.Male;
            Assert.IsFalse(m_Person.ID.HasValue);
            m_Person.Save();
            Assert.IsTrue(m_Person.ID.HasValue);

            try
            {
                Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));

                PersonAttribute pa = new PersonAttribute();
                pa.PersonID = m_Person.ID.Value;
                pa.InsertionDate = DateTime.Now;
                pa.KeyWord = PersonAttributeTypes.DomainName.ToString();
                pa.ValueType = typeof(string).AssemblyQualifiedName;
                pa.StringField = @"ultersysyar\yim1";
                pa.Save();
                Assert.IsNotNull(pa.ID);

                try
                {
                    Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));
                }
                finally
                { pa.Delete(); }
            }
            finally
            { m_Person.Delete(); }
        }
Example #2
0
    /// <summary>
    /// Обработчик аутентификации пользователя.
    /// </summary>
    protected virtual void OnLogin(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(logIn.UserName) || HttpContext.Current == null)
            return;

        Person currentUser = new Person(HttpContext.Current.User.Identity);
        if (!currentUser.LoadByDomainName(logIn.UserName))
            return;

        if (!currentUser.IsInRole(RolesEnum.PublicUser))
        {
            logIn.FailureText = "User cant work with the public portal.";
            return;
        }

        IList<PersonAttribute> attributes =
            PersonAttributes.GetPersonAttributesByKeyword(currentUser.ID.Value
                                                          , PersonAttributeTypes.PublicPassword.ToString());

        if (logIn.Password == (string)attributes[0].Value)
        {
            Session["UserID"] = currentUser.ID.Value;
            FormsAuthentication.RedirectFromLoginPage(logIn.UserName, logIn.RememberMeSet);
        }
        logIn.FailureText = "Incorrect information.";
    }
Example #3
0
        /// <summary>
        /// Returns person with given domain name. Uses caching.
        /// </summary>
        /// <param name="domainName">Domain name.</param>
        /// <returns>Person with given domain name.</returns>
        public static Person GetPersonByDomainName( string domainName )
        {
            if( string.IsNullOrEmpty( domainName ) )
                return null;

            try
            {
                string cacheKey = String.Format("Person with domain name '{0}'", domainName.ToLower());
                if (Cache.Contains(cacheKey))
                {
                    DateTime now = DateTime.Now;
                    DateTime insertDate = Cache.InsertDate(cacheKey).Value;
                    if (insertDate < (now - Settings.Default.PersonExpireTime))
                        Cache.Remove(cacheKey);
                    else
                        return (Person) Cache.GetObject(cacheKey);
                }

                Person p = new Person();
                if (p.LoadByDomainName(domainName))
                {
                    Cache.Add(cacheKey, p);
                    return p;
                }

                return null;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(ex.Message, ex);
                return null;
            }
        }
Example #4
0
 public void LoadByDomainName_True()
 {
     Person p = new Person();
     Assert.IsTrue( p.LoadByDomainName( domainName.ToUpper() ) );
     Assert.AreEqual( person.ID.Value, p.ID.Value );
 }
Example #5
0
 public void LoadByDomainName_False()
 {
     Person p = new Person();
     Assert.IsFalse( p.LoadByDomainName( "unknown" ) );
 }
Example #6
0
 public void LoadByDomainName_Exception()
 {
     Person p = new Person();
     p.LoadByDomainName( null );
 }