add users manually,

Last post 08-05-2009, 2:28 AM by pbwbart. 4 replies.
Sort Posts: Previous Next
  •  07-27-2009, 9:47 AM 54301

    add users manually,

    Hi ,
     
    I want to add users into my contact list automaticly,
    But I can't figure out how to do this.
    Whan I want to add the contacts the cutechat is not started.
    I only haven the usernames and the nicknames of the users which are trying to log in.
    Is it somehow possible to add users without creating an identity.
     
    Is there some function I can call for adding contacts?
     
    Greats
     
  •  07-28-2009, 2:25 AM 54327 in reply to 54301

    Re: add users manually,

    Hi,
     
    I decided to start a chatsystem so I can add users using the following code
     
    1. Dim identity as CuteChat.ChatIdentity =new CuteChat.AppChatIdentity(MyUserName , false, "User:" & MyUserName, httpcontext.current.Request.UserHostAddress)    
    2. Dim identity2 as CuteChat.ChatIdentity =new CuteChat.AppChatIdentity(FriendUserName , false, "User:" & FriendUserName , httpcontext.current.Request.UserHostAddress)    
    3. If not CuteChat.ChatSystem.HasStarted then   
    4.   CuteChat.ChatProvider.Instance = New SiennChatProvider()   
    5.   CuteChat.ChatSystem.Start(New CuteChat.AppSystem())   
    6.   CuteChat.ChatSystem.Instance.GetCurrentPortal().DataManager.AddContact(identity, "User:" & FriendUserName)   
    7.   CuteChat.ChatSystem.Instance.GetCurrentPortal().DataManager.AddContact(identity2, "User:" & MyUserName)   
    8.   CuteChat.ChatSystem.Stop()   
    9. else   
    10.   CuteChat.ChatSystem.Instance.GetCurrentPortal().DataManager.AddContact(identity, "User:" & FriendUserName)   
    11.   CuteChat.ChatSystem.Instance.GetCurrentPortal().DataManager.AddContact(identity2, "User:" & MyUserName)   
    12. end if  
    Now the users are add in the buildincontacts of each other.
    But when I open de cutechat the user is nog added and still I can see him in the buildincontacts in de DB.
    When I close the messenger the user will be deleted from buildincontacts.
     
    I can't figure out when the chatsystem loads his contacts but for some reason i don't think it is while starting the client.
     
  •  07-30-2009, 10:25 AM 54406 in reply to 54327

    Re: add users manually,

    Now I'm trying to do something else by overriding the GetContacts in the glabal.asax. But at that point I get this error:
     
    "function 'GetContacts' cannot be declared 'overrides' because it does not override a function in a base class."
     
    and I don't get the feeling I override somthing when I delete overrides. Does anyone has a solution?
    I'm stuck with it.
     
  •  08-04-2009, 12:28 PM 54482 in reply to 54406

    Re: add users manually,

    Hi,
     
    Here is a DNN code which can help you understand it.
     
    You need override the CreateDataManagerInstance
     
    1. Imports System.IO   
    2. Imports System.Security   
    3. Imports System.Security.Principal   
    4. Imports System.Threading   
    5. Imports System.Web   
    6. Imports System.Web.Security   
    7.   
    8. Imports DotNetNuke.Common.Utilities   
    9. Imports DotNetNuke.Entities.Portals   
    10. Imports DotNetNuke.Security.Roles   
    11. Imports DotNetNuke.Services.Exceptions   
    12. Imports DotNetNuke.Services.Log.EventLog   
    13. Imports DotNetNuke.Services.Scheduling   
    14. Imports DotNetNuke.Services.Upgrade   
    15.   
    16. Imports Microsoft.VisualBasic   
    17.   
    18. Public Class DNNChatProvider   
    19.   
    20.     Inherits CuteChat.ChatProvider   
    21.   
    22.     Protected Function CurrentPortal() As DotNetNuke.Entities.Portals.PortalSettings   
    23.   
    24.         Dim ps As DotNetNuke.Entities.Portals.PortalSettings   
    25.   
    26.         ps = PortalController.GetCurrentPortalSettings()   
    27.   
    28.         If ps Is Nothing Then  
    29.   
    30.             Throw (New Exception("PortalSettings Not Ready"))   
    31.   
    32.         End If  
    33.   
    34.         Return ps   
    35.   
    36.     End Function  
    37.   
    38.     Public Function GetLogonUser() As DotNetNuke.Entities.Users.UserInfo   
    39.   
    40.         If Not HttpContext.Current.Request.IsAuthenticated Then  
    41.   
    42.             Return Nothing  
    43.   
    44.         End If  
    45.   
    46.         Dim username As String = HttpContext.Current.User.Identity.Name   
    47.   
    48.         Return DotNetNuke.Entities.Users.UserController.GetUserByName(CurrentPortal().PortalId, username)   
    49.   
    50.     End Function  
    51.   
    52.     Public Overrides Function GetConnectionString() As String  
    53.   
    54.         Return System.Configuration.ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString   
    55.   
    56.     End Function  
    57.   
    58.     Public Overrides Function GetLogonIdentity() As CuteChat.AppChatIdentity   
    59.   
    60.         Dim user As DotNetNuke.Entities.Users.UserInfo = GetLogonUser()   
    61.   
    62.         If user Is Nothing Then  
    63.   
    64.             Return Nothing  
    65.   
    66.         End If  
    67.   
    68.         Return New CuteChat.AppChatIdentity(user.Username, False, ToUserId(user.Username), HttpContext.Current.Request.UserHostAddress)   
    69.   
    70.     End Function  
    71.   
    72.     Public Overrides Function GetUserInfo(ByVal loginName As StringByRef nickName As StringByRef isAdmin As BooleanAs Boolean  
    73.   
    74.         Try  
    75.   
    76.             Dim user As DotNetNuke.Entities.Users.UserInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(CurrentPortal().PortalId, loginName)   
    77.   
    78.             If user Is Nothing Then  
    79.   
    80.                 Return False  
    81.   
    82.             End If  
    83.   
    84.             nickName = user.Username   
    85.   
    86.             isAdmin = user.IsInRole("Administrators"Or (user.Username = "admin")   
    87.   
    88.             Return True  
    89.   
    90.         Catch ex As Exception   
    91.   
    92.             Return False  
    93.   
    94.         End Try  
    95.   
    96.     End Function  
    97.   
    98.     Public Overrides Function FindUserLoginName(ByVal nickName As StringAs String  
    99.   
    100.         Try  
    101.   
    102.             Dim totalRecords As Integer  
    103.   
    104.             For Each user As DotNetNuke.Entities.Users.UserInfo In DotNetNuke.Entities.Users.UserController.GetUsersByUserName(CurrentPortal().PortalId, nickName, 0, 100, totalRecords)   
    105.   
    106.                 If String.Equals(user.Username, nickName, StringComparison.OrdinalIgnoreCase) Then  
    107.   
    108.                     Return user.Username   
    109.   
    110.                 End If  
    111.   
    112.             Next  
    113.   
    114.             Return Nothing  
    115.   
    116.         Catch ex As Exception   
    117.   
    118.             Return Nothing  
    119.   
    120.         End Try  
    121.   
    122.     End Function  
    123.   
    124.     Public Overrides Function ValidateUser(ByVal loginName As StringByVal password As StringAs Boolean  
    125.   
    126.         If System.Web.Security.Membership.ValidateUser(loginName, password) Then  
    127.   
    128.             System.Web.Security.FormsAuthentication.SetAuthCookie(loginName, False)   
    129.   
    130.             Return True  
    131.   
    132.         End If  
    133.   
    134.     End Function  
    135.   
    136.     Public Class MyDataManager   
    137.   
    138.         Inherits CuteChat.AppDataManager   
    139.   
    140.         Public Sub New(ByVal portal As CuteChat.AppPortal)   
    141.   
    142.             MyBase.New(portal)   
    143.   
    144.         End Sub  
    145.   
    146.         Public Overrides Sub AddContact(ByVal identity As CuteChat.ChatIdentity, ByVal userid As String)   
    147.   
    148.         End Sub  
    149.   
    150.         Public Overrides Sub RemoveContact(ByVal identity As CuteChat.ChatIdentity, ByVal userid As String)   
    151.   
    152.         End Sub  
    153.   
    154.         Public Overrides Function GetContacts(ByVal identity As CuteChat.ChatIdentity) As CuteChat.IChatUserInfo()   
    155.   
    156.             Dim portalid As Integer = 0   
    157.   
    158.             Dim list As ArrayList = DotNetNuke.Entities.Users.UserController.GetUsers(portalid)   
    159.   
    160.             Dim res As New ArrayList   
    161.   
    162.             Dim provider As CuteChat.ChatProvider = CuteChat.ChatProvider.Instance   
    163.   
    164.             Dim myname As String = provider.FromUserId(identity.UniqueId)   
    165.   
    166.             For Each info As DotNetNuke.Entities.Users.UserInfo In list   
    167.   
    168.                 If Not String.Equals(info.Username, myname, StringComparison.OrdinalIgnoreCase) Then  
    169.   
    170.                     res.Add(Me.GetUserInfo(provider.ToUserId(info.Username)))   
    171.   
    172.                 End If  
    173.   
    174.             Next  
    175.   
    176.             Return res.ToArray(GetType(CuteChat.IChatUserInfo))   
    177.   
    178.         End Function  
    179.   
    180.     End Class  
    181.   
    182.   
    183.   
    184.     Public Overrides Function CreateDataManagerInstance(ByVal portal As CuteChat.AppPortal) As CuteChat.AppDataManager   
    185.   
    186.         Return New MyDataManager(portal)   
    187.   
    188.     End Function  
    189.   
    190. End Class  
     
    Regards,
    Terry
     
     
  •  08-05-2009, 2:28 AM 54494 in reply to 54482

    Re: add users manually,

    Thank you,
     
    This example helps me a lot, I didn't noticed the CreateDataManagerInstance before.
    I can overrule getContact now,
    I still have to make sure people have the right contacts but that is no problem.
View as RSS news feed in XML