Example #1
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 #2
0
        // *********************************************************************
        //  GetUserInfo
        //
        /// <summary>
        /// Вернуть информацию о конкретном форуме.
        /// </summary>
        /// <param name="username">The user whose information you are interested in.</param>
        /// <param name="updateIsOnline">Updates user's online datetime stamp.</param>
        /// <returns>Instance of User with details about a given forum user.</returns>
        /// <remarks>
        /// If the specified user is not found, a UserNotFoundException exception is thrown. Feel
        /// free to call this multiple times during the request as the value is stored in Context once
        /// read from the data source.
        /// </remarks>
        // ***********************************************************************/
        public static User GetUserInfo( String username )
        {
            User user = new User();
            UlterSystems.PortalLib.BusinessObjects.Person UlterUser = new UlterSystems.PortalLib.BusinessObjects.Person();
            UlterUser.Load( Int32.Parse( username ) );
            user.Username = username;
            user.DisplayName = UlterUser.FirstName.ToString() + "&nbsp;" + UlterUser.LastName.ToString();
            user.IsApproved = !UlterUser.IsInRole( "ForumBannedUser" );
            user.IsAdministrator = UlterUser.IsInRole( "ForumAdministrator" );

            return user;
        }
    /// <summary>
    /// Add user to role.
    /// </summary>
    /// <param name="person">User.</param>
    /// <param name="role">Role.</param>
    private void addUserRole(Person person, Role role)
    {
        if (role.RoleID != RolesEnum.PublicUser.ToString())
        {
            if (!person.IsInRole(role.RoleID))
                role.AddUser(person.ID.Value);
            return;
        }

        if (String.IsNullOrEmpty(tbPassword.Text))
            return;

        IList<PersonAttribute> attributes =
            PersonAttributes.GetPersonAttributesByKeyword(person.ID.Value
                                                          , PersonAttributeTypes.PublicPassword.ToString());
        if (attributes == null || attributes.Count == 0)
            person.AddStandardStringAttribute(PersonAttributeTypes.PublicPassword,
                                                                     tbPassword.Text);
        else
        {
            attributes[0].StringField = tbPassword.Text;
            attributes[0].Save();
        }
        role.AddUser(person.ID.Value);
    }