public class AspNetChatProvider : ChatProvider
{
public override string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings[CuteChatConnectionStringConfigName].ConnectionString;
}
public override AppChatIdentity GetLogonIdentity()
{
if (HttpContext.Current == null)
return null;
if (HttpContext.Current.Session == null)
return null;
if(HttpContext.Current.Session["User"] == null)
return null;
string _user = HttpContext.Current.Session["User"].ToString();
mySite.DAL.Member _mem = new mySite.DAL.Member(mySite.DAL.Member.Columns.MemberId, _user);
//System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser();
//if (user != null && user.IsApproved)
//{
// return new AppChatIdentity(user.UserName, false, ToUserId(user.UserName), HttpContext.Current.Request.UserHostAddress);
//}
if (_mem != null)
{
return new AppChatIdentity(_mem.Email, false, ToUserId( _mem.MemberId), HttpContext.Current.Request.UserHostAddress);
}
return null;
}
public override string FindUserLoginName(string nickName)
{
//if (nickName == "admin")
//{
// return "Admin";
//}
mySite.DAL.Member _mem = new mySite.DAL.Member(mySite.DAL.Member.Columns.Email, nickName);
if (_mem != null && !string.IsNullOrEmpty(_mem.MemberId))
{
return _mem.FirstName + " " + _mem.FullName;
}
//System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(nickName, false);
//if (user != null && user.IsApproved)
// return user.UserName;
return null;
}
public override bool GetUserInfo(string loginName, ref string nickName, ref bool isAdmin)
{
//System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(loginName, false);
//if (user != null && user.IsApproved)
//{
// nickName = user.UserName;
// isAdmin = Roles.IsUserInRole(user.UserName, "Administrators");
// return true;
//}
////return false;
//if (loginName == "admin")
//{
// nickName = "Admin";
// isAdmin = true;
// return true;
//}
mySite.DAL.Member _mem = new mySite.DAL.Member(mySite.DAL.Member.Columns.Email, loginName);
if (_mem != null && !string.IsNullOrEmpty(_mem.MemberId))
{
nickName = _mem.Email;
isAdmin = _mem.Email == "myemail@mydomain.com" ? true : false;
return true;
}
return false;
}
public override bool ValidateUser(string username, string password)
{
//if (username == "admin" && password == "admin")
// return true;
mySite.Business.Member _member = new mySite.Business.Member();
if (_member.LoadMemberByEmail(username))
{
if (_member.CheckPassword(password))
{
System.Web.Security.FormsAuthentication.SetAuthCookie(username, false, HttpRuntime.AppDomainAppVirtualPath);
//HttpContext.Current.Session["User"] = _member.ID;
return true;
}
else
return false;
}
else
{
return false;
}
}
}
Thanks