custom Provider to integrate CuteChat with existing user login system

  •  11-23-2005, 2:13 AM

    custom Provider to integrate CuteChat with existing user login system

    hai,
    thanx Adam
    I have found the method  for this query
    "How can I hook CuteChat with my existing login system?"

    It is in
    Start >> All programs >> CuteChat >> CuteChat Help

    I followed those steps

    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 to: CuteChat.AspNetForums2Lib
      Set the project property Default Namespace to: 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.

    But Error was occured when i run my application 

    Error
     "The type or namespace name 'SqlDataProvider' could not be found (are you missing a using directive or an assembly reference)"
     

    How to Solve this error?
     
    In this help File
    >>
    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.
     
    Where to get  SqlDataProvider class and IUserIdentityAdapter class?


    plz help me
    We need the soln as early as possible

    thanks
    mekalaasri
     
     
     
View Complete Thread