예제 #1
0
        /// <summary>
        /// Removes the identity from group.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="group">The group.</param>
        /// <param name="authenticatedToken">The authenticated token.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Boolean; true if successful, false otherwise.</returns>
        private static bool RemoveIdentityFromGroup(
            Identity identity,
            Group group,
            AuthenticatedToken authenticatedToken,
            ZentityContext context)
        {
            if (!DataAccess.IsAdmin(authenticatedToken.IdentityName, context))
            {
                throw new UnauthorizedAccessException(ConstantStrings.UnauthorizedAccessException);
            }

            Identity originalIdentity = GetIdentity(identity.Id, context);
            Group    originalGroup    = GetGroup(group.Id, context);

            if (originalIdentity == null || originalGroup == null)
            {
                throw new ArgumentException(ConstantStrings.InvalidIdentityOrGroup);
            }

            originalIdentity.Groups.Load();
            if (!originalIdentity.Groups.Contains(originalGroup))
            {
                return(true);
            }

            if (group.GroupName == AdminGroupName)
            {
                ZentityUserAdmin admin = new ZentityUserAdmin(authenticatedToken);
                admin.UnsetAdmin(identity.IdentityName);
            }

            originalIdentity.Groups.Remove(originalGroup);
            return(context.SaveChanges() == 0 ? false : true);
        }
예제 #2
0
    /// <summary>
    /// Initialize the server controls on page load.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        userToken = (AuthenticatedToken)Session[Constants.AuthenticationTokenKey];

        if (!userToken.IsAdmin(Utility.CreateContext()))
        {
            throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture,
                                                                Resources.Resources.UnauthorizedAccessException, UserResourcePermissions.Read));
        }

        id = Convert.ToString(Request.QueryString[Resources.Resources.QuerystringResourceId], CultureInfo.InvariantCulture);
        if (id != null)
        {
            using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
            {
                identity = (Identity)dataAccess.GetResource(new Guid(id));
                identity.Groups.Load();
                loginName = identity.IdentityName;
            }
        }

        InitializeControls();

        if (!string.IsNullOrEmpty(loginName) && !Page.IsPostBack)
        {
            ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);
            currentUserProfile = adminObject.GetUserProfile(loginName);

            txtLoginName.Text          = loginName;
            txtLoginName.Enabled       = false;
            passwordRow.Visible        = false;
            reEnterPasswordRow.Visible = false;
            securityQuesRow.Visible    = false;
            answerRow.Visible          = false;

            txtFirstName.Text  = currentUserProfile.FirstName;
            txtMiddlename.Text = currentUserProfile.MiddleName;
            txtLastName.Text   = currentUserProfile.LastName;
            txtEmail.Text      = currentUserProfile.Email;
            txtCity.Text       = currentUserProfile.City;
            txtState.Text      = currentUserProfile.State;
            txtCountry.Text    = currentUserProfile.Country;
            if (currentUserProfile.AccountStatus == AccountStatus.Active.ToString())
            {
                chkAccountStatus.Checked = true;
            }
            else if (currentUserProfile.AccountStatus == AccountStatus.InActive.ToString())
            {
                chkAccountStatus.Checked = false;
            }

            currentUser = new ZentityUser(loginName, userToken, currentUserProfile);
        }
        else
        {
            if (!string.IsNullOrEmpty(loginName) && Page.IsPostBack)
            {
                ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);
                currentUserProfile = adminObject.GetUserProfile(loginName);
                currentUser        = new ZentityUser(loginName, userToken, currentUserProfile);
            }
            else
            {
                currentUserProfile = new ZentityUserProfile();
            }
        }

        if (!Page.IsPostBack)
        {
            FillUserGrid();
        }

        UserTable.DeleteClicked += new EventHandler <ZentityGridEventArgs>(UserTable_DeleteClicked);
    }
예제 #3
0
    /// <summary>
    /// Event will Save or Update the User information.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            bool result = false;

            GetUserInformation();
            ZentityUserAdmin adminObject = new ZentityUserAdmin(userToken);

            if (!string.IsNullOrEmpty(loginName))
            {
                currentUser = new ZentityUser(loginName, userToken, currentUserProfile);

                if (userInfoPanel.Enabled)
                {
                    result = UserManager.UpdateUser(currentUser, userToken);
                }

                if (groupAssignment.IsEnable)
                {
                    if (result)
                    {
                        result = adminObject.SetAccountStatus(currentUser.LogOnName, GetAccountStatus());
                        using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
                        {
                            List <String> groupList     = AddGroupsInIdentity();
                            List <String> allSearchList = groupAssignment.GetSearchList();

                            Identity identity = (Identity)dataAccess.GetResource(new Guid(id));
                            identity.Groups.Load();

                            List <string> existingGroups = identity.Groups
                                                           .Select(group => group.Id.ToString())
                                                           .ToList();

                            foreach (string exsitingId in existingGroups)
                            {
                                if (!groupList.Contains(exsitingId))
                                {
                                    if (allSearchList.Contains(exsitingId))
                                    {
                                        Group group = (Group)dataAccess.GetResource(new Guid(exsitingId));
                                        dataAccess.RemoveIdentityFromGroup(identity, group, userToken);
                                    }
                                }
                            }

                            foreach (string selectedId in groupList)
                            {
                                if (!existingGroups.Contains(selectedId))
                                {
                                    Group group = (Group)dataAccess.GetResource(new Guid(selectedId));
                                    result = dataAccess.AddIdentityToGroup(group, identity, userToken);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                using (ResourceDataAccess dataAccess = new ResourceDataAccess(Utility.CreateContext()))
                {
                    result = dataAccess.CreateUser(currentUser, userToken);
                    if (result)
                    {
                        result = adminObject.SetAccountStatus(currentUser.LogOnName, GetAccountStatus());
                        Identity      identity  = UserManager.GetIdentity(currentUser.LogOnName, Utility.CreateContext());
                        List <String> groupList = AddGroupsInIdentity();
                        foreach (String groupId in groupList)
                        {
                            Group group = (Group)dataAccess.GetResource(new Guid(groupId));
                            result = dataAccess.AddIdentityToGroup(group, identity, userToken);
                        }
                    }
                }
            }

            if (!result)
            {
                if (string.IsNullOrEmpty(loginName))
                {
                    Utility.ShowMessage(lblMessage, Resources.Resources.LabelErrorRegistrationFail, true);
                }
                else
                {
                    Utility.ShowMessage(lblMessage, Resources.Resources.LabelErrorUpdateUserFail, true);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(loginName))
                {
                    Utility.ShowMessage(lblMessage,
                                        string.Format(CultureInfo.InvariantCulture, Resources.Resources.LabelUserInfoUpdated, currentUser.LogOnName),
                                        false);
                }
                else
                {
                    Utility.ShowMessage(lblMessage,
                                        string.Format(CultureInfo.InvariantCulture, Resources.Resources.LabelRegistrationCompleted, currentUser.LogOnName),
                                        false);
                    ResetRegistrationForm();
                }
                FillUserGrid();
            }
        }
        catch (Exception ex)
        {
            Utility.ShowMessage(lblMessage, ex.Message, true);
        }
    }