Re: Confusing issues with the installation of CuteChat

  •  09-15-2004, 11:13 AM

    Re: Confusing issues with the installation of CuteChat

    Ghazala,
     
    There is an article in the user manual show you how to hook CuteChat with the existing login system. I paste as followings:
     

    How can I hook CuteChat with my existing login system?

     

    The CuteChat 1.0 ships with seven pre-built providers:

    IBuySpyProvider
    DotNetNukeProvider
    RainbowPortalProvider
    AspNetForumsProvider
    AspNetForums2Provider
    SharePointProvider
    CuteChatSampleProvider

     

     

    Integrating with existing user login system

    If your portal is not based on the above projects. You need to create a custom Provider to integrate CuteChat with existing user login system. To implement a custom CuteChat Provider, you will need to provide a concrete implementation of the SqlDataProvider class and IUserIdentityAdapter class, and plug it into the system through appropriate configuration settings.

    In this section we will look at the steps that you can follow. To do this, we will build a CuteChat provider for the lastest ASPNetForums 2.0. The Provider for ASPNetForums 2.0 will allow CuteChat communicate with the existing ASPNetForums 2.0 login system.

     

    We assume the develpers use the Visual Studio .NET development environment in the following example.

    1. Open Microsoft Visual Studio .NET.
    2. On the File menu, click New Project.
    3. In the New Project dialog box, in Project Types, click Visual C# Projects.
    4. In the right pane, click Class Library.
    5. In the Name box, type a name (CuteChat.AspNetForums2Lib) for the new project and delete the Class1.cs that was auto create for us.  

      Set the project property Assembly Name t  CuteChat.AspNetForums2Lib
      Set the project property Default Namespace t CuteChat.AspNetForums2Lib

      Add your copyright and version requrements to the class file, AssemblyInfo.cs.
    6. In the Location box, select the location you want to save the file to.
    7. Add a reference to CuteChat.dll.  

      Add a Reference reference to the  System, System.Data, System.Web,System.XML  namespace 
    8. Derive a class from the SqlDataProvider abstract base class and name it AspNetForumsSqlDataProvider .

      public class AspNetForumsSqlDataProvider : SqlDataProvider 
      					{
      					}
      					


      To provide a complete implementation, we will need to provide overrides for all of the methods and properties of the SqlDataProvider class as followings:

      The implementation of the ListUserUniqueName method

      Description :
      Retrieves all the user names in the database.

      public override string[] ListUserUniqueName() { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText="select UserName from "+OwnerPrefix+"Forums_Users";
      return SqlDataAccess.ExecuteStringArray(cmd);
      }
      }

      The implementation of the ListRoleUniqueName method

      Description :
      Retrieves all the role names available to all users.

      public override string[] ListRoleUniqueName() { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText="select Name from "+OwnerPrefix+"Forums_Roles";
      return SqlDataAccess.ExecuteStringArray(cmd);
      }
      }

      The implementation of the IsUserNickNameExists method

      Description :
      Check if a username is already in use in the database .

      public override bool IsUserNickNameExists(string nickname) { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText="select count(*) from "+OwnerPrefix+"forums_Users where UserName=@nickname";
      SqlDataAccess.AddParameter(cmd.Parameters,"@nickname",nickname);
      int c=Convert.ToInt32(cmd.ExecuteScalar());
      return c>0;
      }
      }

      The implementation of the ListRoleUniqueNameOfUser method

      Description :
      Retrieves all the roles the current user belongs to.

      public override string[] ListRoleUniqueNameOfUser(string useruniquename) { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText=@" SELECT r.Name FROM "+OwnerPrefix+@"forums_Users u INNER JOIN "+OwnerPrefix+@"forums_UsersInRoles ur ON u.UserID = ur.UserID INNER JOIN "+OwnerPrefix+@"forums_Roles r ON ur.RoleID = r.RoleID where u.UserName=@uniquename ";
      SqlDataAccess.AddParameter(cmd.Parameters,"@uniquename",useruniquename);
      return SqlDataAccess.ExecuteStringArray(cmd);
      }
      }

      The implementation of the ListUserUniqueNameOfRole method

      Description :
      Retrieves all the user names of the input role name

      public override string[] ListUserUniqueNameOfRole(string roleuniquename) { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText=@" SELECT u.UserName FROM "+OwnerPrefix+@"forums_Users u INNER JOIN "+OwnerPrefix+@"forums_UsersInRoles ur ON u.UserID = ur.UserID INNER JOIN "+OwnerPrefix+@"forums_Roles r ON ur.RoleID = r.RoleID where r.Name=@uniquename ";
      SqlDataAccess.AddParameter(cmd.Parameters,"@uniquename",roleuniquename);
      return SqlDataAccess.ExecuteStringArray(cmd);
      }
      }

      The implementation of the GetUserInfo method

      Description :
      Get the current user information from the AspNetForums2 login system

      public override UserInfoData GetUserInfo(string useruniquename) { 
      string username;
      using(SqlCommand cmd=CreateCommand())
      {
      cmd.CommandText="select UserName from "+OwnerPrefix+"Forums_Users where UserName=@username"; SqlDataAccess.AddParameter(cmd.Parameters,"@username",useruniquename); using(SqlDataReader sdr=cmd.ExecuteReader()) {
      bool haverecord=sdr.Read(); if(!haverecord)
      return null;
      username=sdr.GetString(0);
      }
      }

      bool isadmin=false; foreach(string rolename in ListRoleUniqueNameOfUser(useruniquename))
      {
      if((string.Compare(rolename,"Global Administrators",true)==0)||(string.Compare(rolename,"Forum Administrators",true)==0))
      {
      isadmin=true;
      }
      }
      return new UserInfoData(useruniquename,username,isadmin);
      }

      The implementation of the GetRoleInfo method

      Description :
      Retrieves role information of the input role name

      public override RoleInfoData GetRoleInfo(string roleuniquename) { 
      using(SqlCommand cmd=CreateCommand()) {
      cmd.CommandText="select Name from "+OwnerPrefix+"Forums_Roles where Name=@roleid";
      SqlDataAccess.AddParameter(cmd.Parameters,"@roleid",roleuniquename);
      using(SqlDataReader sdr=cmd.ExecuteReader()) {
      bool haverecord=sdr.Read();
      if(!haverecord)
      return null;
      return new RoleInfoData(roleuniquename,sdr.GetString(0));
      }
      }
      }

    9. Create a class which implements the IUserIdentityAdapter interface and name it SqlServerUserIdentityAdapter .

      public class SqlServerUserIdentityAdapter : IUserIdentityAdapter 
      					{
      					}
      					


      To provide a complete implementation, we will need to provide overrides for the two methos of the SqlServerUserIdentityAdapter class as followings:

      The implementation of the GetCurrentUserUniqueName method

      Description :
      Retrieves the user name of the current user.

      public string GetCurrentUserUniqueName(HttpContext context) { 
      IIdentity iden=context.User.Identity;
      if(iden==null||!iden.IsAuthenticated)
      return null;
      if(iden.Name==null||iden.Name.Length==0)
      return null;
      return iden.Name;
      }

      The implementation of the IsAdministrators method

      Description :
      Check the current user is an administrator or not..

      public bool IsAdministrators(string useruniquename) { 
      using(IDataAccess da=ChatConfig.CreateDataAccess()) {
      int userid=da.GetUserInternalId(useruniquename);
      if(userid==0)
      return false;
      DataRow row=da.SelectUser(userid);
      if(row==null)
      return false;
      return Convert.ToBoolean(row["isadmin"]);
      }
      }


    10. Start the application: Press F5, or click Start on the Debug menu.  The classes will be compiled into an assembly CuteChat.AspNetForum2Lib.dll . Test and deploy the new assembly to a running server bin directory.
    11. Modify the configuration file to point the CuteChat default provider to our new provider CuteChat.AspNetForum2Lib.dll .

      The web.config file contains a number of critical sections to enable the Provider pattern. The first section registers the Providers and their corresponding ConfigurationSectionHandlers.  

          <configSections>
            <section name="cuteChat" type="CuteChat.ChatConfigurationHandler,CuteChat" />
          </configSections>

       

       

      The <cutechat> section includes a <providers> collection specification where all of the implementations for <cutechat> are identified. At a bare minimum, each provider must include a name, type, and providerPath attribute ( name is generic but usually refers to the classname, type refers to the strong classname of the provider, and providerPath refers to the location where provider specific resources such as scripts can be found  ).  

      The <cutechat> section should contain a defaultProvider attribute which relates to a specific instance in the <providers> collection below. The defaultProvider is used as the single switch for changing from one provider to another.

      In our case, the defaultProvider should be " AspNetForums2 "

        

      <cuteChat 
      WebFilePath="~/CuteChat/" IPAddressPolicy="*" BadWords="kill,hate" AllowAnonymous="Allow"           LoginUrl="~/" Culture="en-US" UpdateMessageInterval="1" ConnectionString="server=localhost;database=test;uid=test;pwd=test;App=ASP.NET Forums">            <fonts clear="true">                 <add font="Arial"/>
      <add font="Verdana"/>
      </fonts>           <providers defaultProvider="AspNetForums2">
      <provider name="AspNetForums2"
      sqlDataProviderType="CuteChat.AspNetForums2Lib.AspNetForums2SqlDataProvider,CuteChat.AspNetForums2Lib"
      userIdentityAdapterType="CuteChat.AspNetForums2Lib.SqlServerUserIdentityAdapter,CuteChat.AspNetForums2Lib" />
      </providers>

      </cuteChat>


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View Complete Thread