CSModules - PostUserUpdate

rated by 0 users
This post has 8 Replies | 4 Followers

Not Ranked
Posts 41
Points 745
sgettis Posted: Sun, Mar 4 2007 10:00 PM

I am trying to write a module that updates a user but I cant seem to get it to work

Public class UpdateUser : CommunityServer.Components.ICSModule{

public void Init(CSApplication csa, XmlNode node){

csa.PostUserUpdate += new CSUserEventHandler(csa_PostUserUpdate);

}

private void csa_PostUserUpdate(User user, CSEventArgs e){user.Profile.Location = "LA";

user.Profile.Save();

}

 

I added this to the community server config file

<add name = "UpdateUser" type ="Evanta.UpdateUser, Evanta" />

Copied the dll to the bin directory.  I touched the web.config file. But this does not seem to work.  It does not update the users profile on creation or update.  I tried to debug by attaching to the aspnet worker process but that also did not work

 

  • | Post Points: 20
Top 25 Contributor
Posts 939
Points 17,385
CS Developers

To be efficient about this you may want to perform this action before the user is updated so that when the user profile is written to the database only a single trip is required.  Here is what the entire module would like like if you do this.

 

public class UpdateUser : CommunityServer.Components.ICSModule
{
public void Init(CSApplication csa, XmlNode node)
{ csa.PreUserUpdate += new CSUserEventHandler(csa_PreUserUpdate); }
void csa_PreUserUpdate(User user, CSEventArgs e)
{
user.Profile.Location = "LA";
}


Alternatively you can also try updating the entire User object with Users.UpdateUser(user);

 

Wyatt Preul
Wyatt - The Geek Cowboy

  • | Post Points: 20
Not Ranked
Posts 6
Points 60

Hi Everybody,

After searching information about upgrading user email in the database, I found this post very interesting. Indeed, my update process is necessary in order to get the real email adress contained in our Active Directory.

I want to replace login@mydomain.com by mysamplegood@mydomain.com

Here is my code :

using System;
using System.Xml;
using System.Collections.Generic;
using CommunityServer.Components;
using System.Text;
using System.DirectoryServices;
using System.IO;

namespace ActiveDirectoryUpdate
{
    class UpdateUser : CommunityServer.Components.ICSModule
    {
        public UpdateUser(){ }

        public void Init(CSApplication csa, XmlNode node)
        {
            //wire up an event which is fired after the user change has been committed to the database
            csa.PostUserUpdate += new CSUserEventHandler(csa_PostUserUpdate);
        }

        private void csa_PostUserUpdate(User user, CSEventArgs e)
        {
            //we only care about new users, so let's filter for it
            if (e.State == ObjectState.Create)
            {
                //now we can do something such as assign roles, send email, etc.

                User editableUser = CommunityServer.Users.GetUserWithWriteableProfile(user.UserID, null, true);
                string mail = this.GetUserMail("", "", "", "", editableUser.Username);
                if (mail != null)
                {
                    editableUser.Email = mail.ToLower();
                    this.WriteToLogFile(DateTime.Now.ToString() + " " + editableUser.Username + " " + editableUser.Email);
                }
                user.Profile.Save();
                this.WriteToLogFile(CommunityServer.Users.UpdateUser(editableUser).ToString());
                CommunityServer.Users.UpdateUserLastPostDate(editableUser);

            }
        }

        /// <summary>
        /// Check login
        /// </summary>
        /// <param name="login_"></param>
        /// <param name="pwd_"></param>
        /// <returns></returns>
        private string GetUserMail(string login_, string pwd_, string ldapPath, string ldapDomain, string userLogin)
        {
            login_ = login_.ToLower();
            ldapPath = "LDAP://myserver/OU=ou12,DC=mydomain,DC=com";
            ldapDomain = "mydomain\\";
            login_ = "login";
            pwd_ = "**********";

            DirectoryEntry entry = new DirectoryEntry(ldapPath, ldapDomain + login_, pwd_);
            try
            {
                DirectorySearcher search = new DirectorySearcher(entry);
                if (userLogin != null && userLogin != "")
                {
                    search.Filter = "(&(objectClass=user)(objectCategory=person))";
                    search.Filter = String.Format("(SAMAccountName={0})", userLogin);
                }

                search.PropertiesToLoad.Add("cn");
                search.PropertiesToLoad.Add("mail");
                System.DirectoryServices.SearchResult Sresult = search.FindOne();

                if (Sresult != null)
                {
                    string loginUser = (string)Sresult.Properties["cn"][0];
                    string userEmail = (string)Sresult.Properties["mail"][0];

                    return (userEmail);
                }

                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                entry.Close();
            }
        }

        /// <summary>
        /// Gets Values From The Config File.
        /// </summary>
        public static bool IsDirectoryPresent(string directory, bool create)
        {
            try
            {
                if (!Directory.Exists(directory))
                {
                    if (create == true)
                    {
                        Directory.CreateDirectory(directory);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
            }
        }

        /// <summary>
        /// Gets The Directory Path from the FilePath
        /// </summary>
        public static string StripDirectoryName(string path)
        {
            string direcoryPath = @"";
            int indexOfLastSlash = 0;

            try
            {
                indexOfLastSlash = path.LastIndexOf(@"\");
                direcoryPath = path.Substring(0, indexOfLastSlash);
                return direcoryPath;
            }
            catch (Exception ex)
            {
                return "";
            }
            finally
            {
            }
        }

        /// <summary>
        /// Writes the message to the FileSystem Watcher Log File
        /// </summary>
        public void WriteToLogFile(string message)
        {
            string logFileName = "D:\\CS.txt";
            if (IsDirectoryPresent(StripDirectoryName(logFileName), true))
            {
                FileStream fs = null;
                StreamWriter sw = null;
                //string formattedDate;
                string fileName;
                //int indexOfPeriod;

                try
                {
                    //formattedDate = "(" + DateTime.Now.ToString("dd - MM - yyyy") + ")";
                    //indexOfPeriod = logFileName.LastIndexOf(".");
                    fileName = logFileName; //.Insert(indexOfPeriod,formattedDate);

                    fs = new FileStream(fileName, FileMode.Append, FileAccess.Write);
                    sw = new StreamWriter(fs);
                    sw.WriteLine(message);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Flush();
                        sw.Close();
                    }

                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
        }
    }
}


The result in the CS.txt file is good. Data seems to be recorded as well when a new user logs into.

However, the SSO module is implemented. So in order to understand, I traced all the requested done on the database:

RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec dbo.cs_SiteSettings_Get @SiteUrl = N'pordaf065/cs', @SettingsID = -1, @ReturnAll = 0    .Net SqlClient Data Provider    login    mydomain\login    0    12    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec dbo.cs_user_Get @UserName = N'mysample', @UserID = 0, @IsOnline = 1, @LastAction = N'', @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    11    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:053P'    .Net SqlClient Data Provider    login    mydomain\login    0    4    0    0    4964    52    2007-07-09 18:23:16.050    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.083    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:083P'    .Net SqlClient Data Provider    login    mydomain\login    0    4    0    0    4964    52    2007-07-09 18:23:16.083    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.097    
RPC:Completed    -- 'password' was found in the text of this event.
-- The text has been replaced with this comment for security reasons.    .Net SqlClient Data Provider    login    mydomain\login    0    17    0    0    4964    52    2007-07-09 18:23:16.097    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.097    
RPC:Completed    exec dbo.aspnet_Profile_GetProperties @ApplicationName = N'dev', @UserName = N'mysample', @CurrentTimeUtc = 'juil  9 2007  4:23:16:100P'    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    52    2007-07-09 18:23:16.097    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.097    
RPC:Completed    declare @P1 int
set @P1=2126
exec dbo.cs_user_CreateUpdateDelete @Action = 0, @cs_UserID = @P1 output, @UserID = 'F458DFD6-A44E-4C95-83E6-CB04A01E288C', @UserName = N'mysample', @Email = N'login@mydomain.com', @UserAccountStatus = 1, @IsAnonymous = 0, @IsIgnored = 0, @ForceLogin = 0, @AppUserToken = '', @CreateDate = 'juil  9 2007  6:23:16:000P', @IsApproved = 1, @PropertyNames = default, @PropertyValues = default, @TimeZone = 0.000000000000000e+000, @PostRank = default, @PostSortOrder = 0, @IsAvatarApproved = 1, @ModerationLevel = 0, @EnableThreadTracking = 1, @EnableAvatar = 0, @EnableDisplayInMemberList = 1, @EnablePrivateMessages = 0, @EnableOnlineStatus = 0, @EnableEmail = 1, @EnableHtmlEmail = 1, @FavoritesShared = 0, @AllowSiteToContact = 0, @AllowSitePartnersToContact = 0, @SettingsID = 1000
select @P1    .Net SqlClient Data Provider    login    mydomain\login    0    14    0    16    4964    52    2007-07-09 18:23:16.097
    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec dbo.cs_user_Get @UserName = N'mysample', @UserID = 0, @IsOnline = 1, @LastAction = N'', @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    17    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    55    2007-07-09 18:23:16.113    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:117P'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    55    2007-07-09 18:23:16.113    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec dbo.cs_EventLog_Add @EventType = 0, @EventID = 401, @SettingsID = 1000, @Message = N'mysample was added from the role Everyone by mysample', @Category = N'Role Update', @MachineName = N'PORDAF065'    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec dbo.aspnet_UsersInRoles_IsUserInRole @ApplicationName = N'dev', @UserName = N'mysample', @RoleName = N'Everyone'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec dbo.aspnet_UsersInRoles_AddUsersToRoles @ApplicationName = N'dev', @RoleNames = N'Everyone', @UserNames = N'mysample', @CurrentTimeUtc = 'juil  9 2007  4:23:16:117P'    .Net SqlClient Data Provider    login    mydomain\login    16    523    0    16    4964    52    2007-07-09 18:23:16.113    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec dbo.cs_EventLog_Add @EventType = 0, @EventID = 401, @SettingsID = 1000, @Message = N'mysample was added from the role Registered Users by mysample', @Category = N'Role Update', @MachineName = N'PORDAF065'    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec dbo.aspnet_UsersInRoles_IsUserInRole @ApplicationName = N'dev', @UserName = N'mysample', @RoleName = N'Registered Users'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec dbo.aspnet_UsersInRoles_AddUsersToRoles @ApplicationName = N'dev', @RoleNames = N'Registered Users', @UserNames = N'mysample', @CurrentTimeUtc = 'juil  9 2007  4:23:16:147P'    .Net SqlClient Data Provider    login    mydomain\login    0    517    0    16    4964    52    2007-07-09 18:23:16.143    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.177    
RPC:Completed    exec dbo.cs_ApplicationConfigurationSettings_Get @SettingsID = 1000, @ApplicationType = 1    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    52    2007-07-09 18:23:16.177    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.190    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    55    2007-07-09 18:23:16.190    
RPC:Completed    exec dbo.cs_ApplicationConfigurationSettings_Get @SettingsID = 1000, @ApplicationType = 2    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    55    2007-07-09 18:23:16.190    
RPC:Completed    exec dbo.cs_SiteSettings_Get @SiteUrl = N'pordaf065/cs', @SettingsID = -1, @ReturnAll = 0    .Net SqlClient Data Provider    login    mydomain\login    0    12    0    0    4964    52    2007-07-09 18:23:16.190    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    55    2007-07-09 18:23:16.190    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.190    
RPC:Completed    exec dbo.cs_user_Get @UserID = 2126, @IsOnline = 1, @LastAction = N'', @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    13    0    0    4964    55    2007-07-09 18:23:16.190    
RPC:Completed    exec dbo.cs_user_Get @UserName = N'mysample', @UserID = 0, @IsOnline = 1, @LastAction = N'', @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    17    0    0    4964    52    2007-07-09 18:23:16.190    
Audit Login    -- network protocol: LPC
set quoted_identifier on
set implicit_transactions off
set cursor_close_on_commit off
set ansi_warnings on
set ansi_padding on
set ansi_nulls on
set concat_null_yields_null on
set language Français
set dateformat dmy
set datefirst 1
    .Net SqlClient Data Provider        mydomain\login                    4964    61    2007-07-09 18:23:16.207    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:210P'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    61    2007-07-09 18:23:16.207    
Audit Login    -- network protocol: LPC
set quoted_identifier on
set implicit_transactions off
set cursor_close_on_commit off
set ansi_warnings on
set ansi_padding on
set ansi_nulls on
set concat_null_yields_null on
set language Français
set dateformat dmy
set datefirst 1
    .Net SqlClient Data Provider        mydomain\login                    4964    64    2007-07-09 18:23:16.207    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:210P'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    64    2007-07-09 18:23:16.223    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.347    
RPC:Completed    exec dbo.aspnet_Profile_GetProperties @ApplicationName = N'dev', @UserName = N'mysample', @CurrentTimeUtc = 'juil  9 2007  4:23:16:350P'    .Net SqlClient Data Provider    login    mydomain\login    0    6    0    0    4964    52    2007-07-09 18:23:16.347    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.473    
RPC:Completed    exec dbo.aspnet_Profile_SetProperties @ApplicationName = N'dev', @UserName = N'mysample', @PropertyNames = N'publicEmail:S:0:0:yahooIM:S:0:0:commonName:S:0:0:signatureFormatted:S:0:0:signature:S:0:0:webLog:S:0:0:location:S:0:0:bio:S:0:0:webAddress:S:0:0:interests:S:0:0:icqIM:S:0:0:aolIM:S:0:0:occupation:S:0:0:msnIM:S:0:0:', @PropertyValuesString = N'', @PropertyValuesBinary = 0x, @IsUserAnonymous = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:473P'    .Net SqlClient Data Provider    login    mydomain\login    0    15    0    0    4964    52    2007-07-09 18:23:16.473    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.473    
RPC:Completed    exec dbo.aspnet_Membership_UpdateUser @ApplicationName = N'dev', @UserName = N'mysample', @Email = N'mysampleGood@mydomain.com', @Comment = NULL, @IsApproved = 1, @LastLoginDate = 'juil  9 2007  4:23:16:000P', @LastActivityDate = 'juil  9 2007  4:23:16:000P', @UniqueEmail = 1, @CurrentTimeUtc = 'juil  9 2007  4:23:16:473P'    .Net SqlClient Data Provider    login    mydomain\login    16    21    0    16    4964    52    2007-07-09 18:23:16.473    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.490    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:490P'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    52    2007-07-09 18:23:16.490    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.490    
RPC:Completed    exec dbo.cs_user_CreateUpdateDelete @Action = 1, @cs_UserID = 2126, @UserID = 'F458DFD6-A44E-4C95-83E6-CB04A01E288C', @UserName = N'mysample', @Email = N'mysampleGood@mydomain.com', @UserAccountStatus = 1, @IsAnonymous = 0, @IsIgnored = 0, @ForceLogin = 0, @AppUserToken = '', @CreateDate = 'juil  9 2007  6:23:16:000P', @IsApproved = 1, @PropertyNames = default, @PropertyValues = default, @TimeZone = 0.000000000000000e+000, @PostRank = 0x00, @PostSortOrder = 0, @IsAvatarApproved = 1, @ModerationLevel = 0, @EnableThreadTracking = 1, @EnableAvatar = 0, @EnableDisplayInMemberList = 1, @EnablePrivateMessages = 0, @EnableOnlineStatus = 0, @EnableEmail = 1, @EnableHtmlEmail = 1, @FavoritesShared = 0, @AllowSiteToContact = 0, @AllowSitePartnersToContact = 0, @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    9    0    0    4964    52    2007-07-09 18:23:16.490    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec dbo.aspnet_Profile_SetProperties @ApplicationName = N'dev', @UserName = N'mysample', @PropertyNames = N'publicEmail:S:0:0:yahooIM:S:0:0:timezone:S:0:1:commonName:S:1:0:signatureFormatted:S:1:0:signature:S:1:0:webLog:S:1:0:location:S:1:0:bio:S:1:0:webAddress:S:1:0:interests:S:1:0:icqIM:S:1:0:aolIM:S:1:0:occupation:S:1:0:msnIM:S:1:0:', @PropertyValuesString = N'1', @PropertyValuesBinary = 0x, @IsUserAnonymous = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:600P'    .Net SqlClient Data Provider    login    mydomain\login    0    13    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec dbo.aspnet_Membership_UpdateUser @ApplicationName = N'dev', @UserName = N'mysample', @Email = N'login@mydomain.com', @Comment = NULL, @IsApproved = 1, @LastLoginDate = 'juil  9 2007  4:23:16:000P', @LastActivityDate = 'juil  9 2007  4:23:16:000P', @UniqueEmail = 1, @CurrentTimeUtc = 'juil  9 2007  4:23:16:600P'    .Net SqlClient Data Provider    login    mydomain\login    0    20    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec dbo.aspnet_Membership_GetUserByName @ApplicationName = N'dev', @UserName = N'mysample', @UpdateLastActivity = 0, @CurrentTimeUtc = 'juil  9 2007  4:23:16:600P'    .Net SqlClient Data Provider    login    mydomain\login    0    7    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec dbo.cs_user_CreateUpdateDelete @Action = 1, @cs_UserID = 2126, @UserID = 'F458DFD6-A44E-4C95-83E6-CB04A01E288C', @UserName = N'mysample', @Email = N'login@mydomain.com', @UserAccountStatus = 1, @IsAnonymous = 0, @IsIgnored = 0, @ForceLogin = 0, @AppUserToken = '', @CreateDate = 'juil  9 2007  6:23:16:000P', @IsApproved = 1, @PropertyNames = default, @PropertyValues = default, @TimeZone = 1.000000000000000e+000, @PostRank = default, @PostSortOrder = 0, @IsAvatarApproved = 1, @ModerationLevel = 0, @EnableThreadTracking = 1, @EnableAvatar = 0, @EnableDisplayInMemberList = 1, @EnablePrivateMessages = 0, @EnableOnlineStatus = 0, @EnableEmail = 1, @EnableHtmlEmail = 1, @FavoritesShared = 0, @AllowSiteToContact = 0, @AllowSitePartnersToContact = 0, @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    13    0    0    4964    52    2007-07-09 18:23:16.597    
RPC:Completed    exec sp_reset_connection    .Net SqlClient Data Provider    login    mydomain\login    0    0    0    0    4964    52    2007-07-09 18:23:16.723    
RPC:Completed    exec dbo.cs_weblog_Weblogs_Get @SettingsID = 1000    .Net SqlClient Data Provider    login    mydomain\login    0    149    0    0    4964    52    2007-07-09 18:23:16.723    

If you analyse, you will see 3 sets of update in bold. Why the last one replaces the previous ?

 

Thanks for your help !!!

 I'm lost !

 
Antony
 

  • | Post Points: 20
Top 25 Contributor
Posts 939
Points 17,385
CS Developers

I think if you change these two lines you might fix it:

user.Profile.Save();
this.WriteToLogFile(CommunityServer.Users.UpdateUser(editableUser).ToString());

Try changing it to

this.WriteToLogFile(CommunityServer.Users.UpdateUser(editableUser).ToString());

 

I am not sure that you need to get the profile and update it.

Wyatt Preul
Wyatt - The Geek Cowboy

  • | Post Points: 20
Not Ranked
Posts 6
Points 60

Dear Wyatt,

 

Maybe my previous message was not clear. The idea is I want to save the right email adress from our active directory because CS uses the login + the domain key contained in the configuration file. Thus, I got the code and created a library that is able to connect to the AD. After building it, I deploy it on the server, modified the xml file of community server. Then a new user connnects to the application. Unfortunately, the email is not updated. I tried to understand what happened on the database and used the microsoft Trace utility to get the sql commands. These are available in the previous post. As you can see, the email is well obtained from  the AD and is recorded but for an unknown reason, the right email is replaced. 

 What changes in the code you gave me ?

 Thanks in advance for your answer.

 Antony

  • | Post Points: 20
Top 25 Contributor
Posts 939
Points 17,385
CS Developers

The previous code that I suggested changing would have removed the save to the profile.  It looked like the profile did not need to be updated.  However, I have an alternative idea for what to change the code to.  Instead of updating a user a second time in your module and saving that, you might want to try running the module before the initial user is saved to the datastore.  This way you only make one trip to the database and update the user object just before its initial save.  Here is what your code could look like to do this.

public void Init(CSApplication csa, XmlNode node)
{
    //wire up an event which is fired after the user change has been committed to the database
   
csa.PreUserUpdate += new CSUserEventHandler(csa_PreUserUpdate);
}

private void csa_PreUserUpdate(User user, CSEventArgs e)
{
   
//we only care about new users, so let's filter for it
   
if (e.State == ObjectState.Create)
    {
       
string mail = this.GetUserMail("", "", "", "", user.Username);
       
if (mail != null)
        {
             user.Email = mail.ToLower();
            
this.WriteToLogFile(DateTime.Now.ToString() + " " + user.Username + " " + user.Email);
        }
    }

}

Wyatt Preul
Wyatt - The Geek Cowboy

  • | Post Points: 35
Not Ranked
Posts 6
Points 60
audouanto1 replied on Thu, Oct 11 2007 10:22 AM

 It works !

 Thanks a lot

  • | Post Points: 5
Not Ranked
Posts 6
Points 90
ctisn replied on Mon, Jan 14 2008 8:22 AM

Hi Paul, I'm using the same method and when creating users its works fine, but as soon as I call:

 

if(e.State == ObjectState.Delete)

{

    Methods 

Nothing happens, and I expect the methods to be initated once a user is deleted from the membership area within CS...am I wrong here? If so, is there another way to initate a method when deleting a user in CS? Because I have a few custom tables that are being used within the system that are becoming messy with users being deleted and there custom data not.

 Any help is appreciated.

Thanks

 

  • | Post Points: 20
Not Ranked
Posts 18
Points 395

Though my intention is to get the similer thing, I am lost in the whole post.  we are using windows authentication and and it is just works fine.

However, the email id it creates is the userid@mycompany.com. where as the intended email is first_lastname@mycompany.com

For ex:

First Name : Joe              Last Name = Bennett               windows active directory id = jbennett  and the actual email to be created is joe_bennett@mycompany.com

However, CS 2007 SSO creates jbennett@mycompany.com

I do not know how to get this done and am a novice to all the code that is posted. I am looking for a simple aspx or .cs file and which folder it needs to be placed. I need to get the first name and last name from the active directory up on login or when the user is created. the private email should be populated as firstname_lastname@mycompany.com

another issue I observed is that, I thought to go change the email id manually after it got created. However, it doesn't allow me to change it. I guess the email id it creates is the private email id in the edit profile. so when I tried to changed, it gave me error. Is this what is expected?

 

Thanks for any help in advance.

 

  • | Post Points: 5
Page 1 of 1 (9 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com