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.
|
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)
{
return
CommunityServer.Users.FindUserByUsername(useruniquename).IsAdministrator;
}
//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()
{
CommunityServer.UserQuery query = new
CommunityServer.UserQuery();
CommunityServer.Components.UserSet
userset = CommunityServer.Users.GetUsers(query, true);
ArrayList names = new ArrayList();
foreach
(CommunityServer.Components.User user in userset.Users)
{
if
(user.IsAnonymous) continue;
names.Add(user.Username);
}
return
(string[])names.ToArray(typeof(string));
}
//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;
CommunityServer.Components.User
user=CommunityServer.Users.FindUserByUsername(useruniquename);
if(user==null)
return
false;
if
(lobby.Integration.StartsWith("Forum:"))
{
int forumid
= int.Parse(lobby.Integration.Substring(6));
CommunityServer.Discussions.Components.Forum forum =
CommunityServer.Discussions.Components.Forums.GetForum(forumid);
if (forum ==
null)
{
return false;
}
return
CommunityServer.Components.Permissions.ValidatePermissions(forum
, CommunityServer.Components.Permission.Administer
, user);
}
return false;
}
|
|
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;
//does the user exist?
CommunityServer.Components.User user
= CommunityServer.Users.FindUserByUsername(username);
if (user == null)
return
false;
//use CommunityServer API to validate the user
user = new
CommunityServer.Components.User();
user.Username = username;
user.Password = password;
CommunityServer.Components.LoginUserStatus status =
CommunityServer.Users.ValidUser(user);
if(status!=CommunityServer.Components.LoginUserStatus.Success)
{
return
false;
}
//FORM-Authentication ,
System.Web.Security.FormsAuthentication.SetAuthCookie(user.Username, false,
"/");
return true;
}
//Fire when the conversation start.
public void SupportInit()
Code Example
public void SupportInit()
{
}
|