예제 #1
0
        public async Task <string> ResetUserPasswordAsync(string userPrincipalName)
        {
            var newPassword = Security.ToInsecureString(Security.GetRandomPassword(8, true, true, true, true));

            await GraphClient.Users[userPrincipalName].Request().UpdateAsync(new User()
            {
                PasswordProfile = new PasswordProfile()
                {
                    Password = newPassword,
                    ForceChangePasswordNextSignIn = true
                }
            });

            return(newPassword);
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Gets ad user object from user list item. </summary>
        ///
        /// <remarks>   Sebastian Schütze, 07/04/2018. </remarks>
        ///
        /// <param name="listItem"> The list item. </param>
        ///
        /// <returns>   The ad user object from user list item. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static User GetAdUserObjectFromUserListItem(ListItem listItem)
        {
            var fields = listItem.Fields.AdditionalData;

            var title          = fields.ContainsKey("Title") ? (string)fields["Title"] : "";
            var firstname      = fields.ContainsKey("UserFirstName") ? (string)fields["UserFirstName"] : "";
            var lastname       = fields.ContainsKey("UserLastName") ? (string)fields["UserLastName"] : "";
            var department     = fields.ContainsKey("UserDomain") ? (string)fields["UserDomain"] : "";
            var state          = fields.ContainsKey("State") ? (string)fields["State"] : "";
            var alternateEmail = fields.ContainsKey("AlternateEMail") ? (string)fields["AlternateEMail"] : "";
            var userHomePhone  = fields.ContainsKey("UserHomePhone") ? (string)fields["UserHomePhone"] : "";
            var city           = fields.ContainsKey("UserCity") ? (string)fields["UserCity"] : "";
            var mobilePhone    = fields.ContainsKey("UserMobilePhone") ? (string)fields["UserMobilePhone"] : "";
            var forwardEmail   = fields.ContainsKey("ForwardingActive") && (bool)fields["ForwardingActive"];
            var userCircle     = fields.ContainsKey("UserCircle") ? (string)fields["UserCircle"] : "";

            var userPrincipalName = O365UserPropertyHelper.UserPrincipalName(firstname, lastname, department);

            //var searchableDisplayName = O365UserPropertyHelper.GetSearchableDisplayName(title, firstname, lastname);
            var displayName = O365UserPropertyHelper.GetDisplayName(title, firstname, lastname);

            return(new WkUser()
            {
                AccountEnabled = true,
                UserPrincipalName = userPrincipalName,
                MobilePhone = userHomePhone,
                BusinessPhones = new[] { mobilePhone },
                Department = department,
                PasswordPolicies = "DisablePasswordExpiration",
                PasswordProfile = new PasswordProfile
                {
                    ForceChangePasswordNextSignIn = true,
                    Password = Security.ToInsecureString(Security.GetRandomPassword(8, true, true, true, true))
                },
                MailNickname = $"{firstname}{lastname[0].ToString().ToUpper()}",
                GivenName = firstname,
                Surname = lastname,
                AlternativeMail = alternateEmail,
                ForwardMail = forwardEmail,
                DisplayName = displayName,
                City = city,
                State = state,
                UsageLocation = "DE"
            });
        }