Skip to content

Cute Chat / Web Messenger Developer's Guide - Integration with an existing user membership database

Cute Chat / Web Messenger Developer's Guide Prev Page Prev Page
FAQ
Embed mode
Localization
Oracle and Access
Cute Chat

Integration with an existing user membership database (C#)

Integration with an existing user membership database (C#)


Before you get started, you need to understand the 'UniqueName' in CuteChat. In CuteChat, UniqueName means the unique data of your user. Depending on how you implement the user system, in some systems, the best unique data is the user ID; in some system, every user have a unique account name; some systems like MSN, the unique data is the user email. It could be string(username, email), integer(user ID) or GUID.

Unzip the integration package zip file and open cs/Global.asax file.

The older product-specific sample packages are no longer included. Use the extension points below to connect CuteChat to your own membership provider or application database.

Implement IHttpApplicationConnectionStringProvider interface and Let CuteChat know the database connection string


In this step, you need to implement one simple method:

//Retrieves the Cute Chat database connection string
public string GetConnectionString(CuteSoft.Chat.UserIdentity user)

Code Example

public string GetConnectionString(CuteSoft.Chat.UserIdentity user)

{

    return System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];

}

Implement IHttpApplicationUserAdapter interface and Let CuteChat know who has logged in the website


In this step, you need to implement one simple method:

//Retrieves the unique identity of the current user
public CuteSoft.Chat.UserIdentity GetUserIdentity()

Code Example

public string GetUserUniqueName()

{    
     if (Context.User.Identity.IsAuthenticated)
        return Context.User.Identity.Name; 
    return null;

}

public CuteSoft.Chat.UserIdentity GetUserIdentity()

{

    string uniquename = GetUserUniqueName();

    if (uniquename == null)

    {

        return CuteSoft.Chat.UserIdentity.CreateNull();

    }

    CuteSoft.Chat.UserIdentity identity = new CuteSoft.Chat.UserIdentity(uniquename, null, Request.UserHostAddress);

    return identity;

}

Implement IHttpApplicationDataProvider interface and Let CuteChat know your membership database information


In this step, you need to implement five methods:

//Check the user is an administrator or not.
public bool IsAdministrator(string useruniquename)

Code Example
public bool IsAdministrator(string useruniquename)
{
     MembershipUser user = Membership.GetUser(useruniquename);
     return user != null && Roles.IsUserInRole(useruniquename, "Administrators");

}


//Return user's display name
public string GetUserDisplayName(string useruniquename)

Code Example

public string GetUserDisplayName(string useruniquename)
 {
     if( !Context.Request.IsAuthenticated )
        return null;
     return Context.User.Identity.Name;

}

//Retrieves all the user's unique names in the database.
public string[] ListUserUniqueName()

Code Example

public string[] ListUserUniqueName()

{

    List<string> names = new List<string>();

    foreach (MembershipUser user in Membership.GetAllUsers())

    {

        if (user == null || string.IsNullOrEmpty(user.UserName)) continue;

        names.Add(user.UserName);

    }

    return names.ToArray();

}


//Return an array of user names containing the input string.
public string[] SearchUserUniqueNameByDisplayName(string userDisplaName)

Code Example

public string[] SearchUserUniqueNameByDisplayName(string userDisplaName)
 {

    if (userDisplaName == null || userDisplaName == "") return new string[0];

    userDisplaName = userDisplaName.ToLower();

    AdminDB admin = new AdminDB();

    SqlDataReader reader = admin.GetUsers();

    ArrayList names = new ArrayList();

   while (reader.Read())

   {

      try

     {

         string val = reader.GetString(1);

         if (val.ToLower().IndexOf(userDisplaName) != -1)

            names.Add(val);

     }

     catch { }

   }

   return (string[])names.ToArray(typeof(string));
}


//Check the user is a lobby admin or not (only for integrated room).
public bool IsLobbyAdmin(string useruniquename, CuteSoft.Chat.CuteChatLobby lobby)

Code Example
public bool IsLobbyAdmin(string useruniquename, CuteSoft.Chat.CuteChatLobby lobby)
{     
        if (lobby.Integration == null) return false;
        if (!lobby.Integration.StartsWith("Room:", StringComparison.OrdinalIgnoreCase)) return false;
        return Roles.IsUserInRole(useruniquename, "Moderators")
            || Roles.IsUserInRole(useruniquename, "Administrators");

}

 

Implement IHttpApplicationSupportLogin interface and Let CuteChat can verify the operator's credentials


In this step, you need to implement two methods:

//Check the user is an operator or not (only for live support).
public bool SupportLogin(string username, string password)

Code Example

public bool SupportLogin(string username, string password)
{     

       if (username == null) return false;
        username = username.Trim();
        if (username == "") return false;
        if (password == null) return false;

        //IMPORTANT: if the user is not the operator, do not return true;
        //use the CuteChat API to check it
        if (CuteSoft.Chat.ChatApi.FindOperator(username) == null)
            return false;

        //validate the user against your own membership system
        if (!Membership.ValidateUser(username, password))
            return false;

        //FORM-Authentication ,
        System.Web.Security.FormsAuthentication.SetAuthCookie(username, false, "/");

        return true;

}



//Fire when the conversation start.
public void SupportInit()

Code Example

public void SupportInit()
{     

}