Re: Chat administration problems

  •  08-24-2009, 1:20 AM

    Re: Chat administration problems

      public class ChatClient : ChatProvider
        {
          
            private class RelationshipFile
            {
                public UserApi.Relationship Relationship { get; set; }
                public MediaApi.File File { get; set; }
            }

            #region        //TODO:integration code for friend list:
            public override AppDataManager CreateDataManagerInstance(AppPortal portal)
            {
                return new MyDataManager(portal);
            }

            class MyDataManager : AppDataManager
            {

                public override IChatUserInfo[] GetContacts(ChatIdentity identity)
                {
                    string myname = ChatProvider.Instance.FromUserId(identity.UniqueId);

                    UserData userdata = new UserData();

                    string[] friends = userdata.GetUsersFriends(myname);
                    IChatUserInfo[] arr = null;
                    if (friends != null)
                    {
                        arr = new IChatUserInfo[friends.Length];
                        for (int i = 0; i < friends.Length; i++)
                        {
                            string friendid = ChatProvider.Instance.ToUserId(friends[i]);
                            arr[i] = base.GetUserInfo(friendid);
                            //arr[i].DisplayName = "";
                        }
                    }
                    else
                    {
                        arr = new IChatUserInfo[0];
                    }
                   
                    return arr;
                }

                public override void AddIgnore(ChatIdentity identity, string userid)
                {
                    base.AddIgnore(identity, userid);
                }
                public override void RemoveIgnore(ChatIdentity identity, string userid)
                {
                    base.RemoveIgnore(identity, userid);
                }
                public override IChatUserInfo[] GetIgnores(ChatIdentity identity)
                {
                    return base.GetIgnores(identity);
                }


                public MyDataManager(AppPortal portal)
                    : base(portal)
                {
                }
            }
            #endregion

            public override String GetConnectionString()
            {
                //return System.Configuration.ConfigurationSettings.AppSettings["Site.Properties.Settings.DatabaseConnection]"];

                return Properties.Settings.Default.DatabaseConnection;
                
            }

            /// <summary>
            /// find the username by the displayname
            /// </summary>
            public override string FindUserLoginName(string nickName)
            {
                UserData userdata = new UserData();
                if (userdata.IsUserExistByScreename(nickName))
                    return nickName;
                return null;
            }

            public override bool GetUserInfo(string loginName, ref string nickName)
            {
                UserData userdata = new UserData();
                if (!userdata.IsUsernameExists(loginName))
                    return false;

                nickName = loginName;

                Huzu.UserModule.Classes.User userObj = Huzu.UserModule.Classes.User.CreateByUsername(loginName);

                if (userObj != null)
                {
                    nickName = userObj.Screenname;
                }

                return true;
            }

            /// <summary>
            /// get the information from the user
            /// This function is very important and be called very frequently.
            /// </summary>
            public override bool GetUserInfo(string loginName, ref string nickName, ref bool isAdmin)
            {
                UserData userdata = new UserData();

                if (!userdata.IsUsernameExists(loginName))
                    return false;

                nickName = loginName;

                isAdmin = false; //SamplePortal.Global.IsUserInRole("Admins", loginName);

                Huzu.UserModule.Classes.User userObj = Huzu.UserModule.Classes.User.CreateByUsername(loginName);


                if (userObj != null)
                {
                    if (userObj.IsInRole(Properties.Settings.Default.AdminUserRoleId))
                    {
                        isAdmin = true;
                    }
                    nickName = userObj.Screenname;
                }
                
                return true;
            }

            /// <summary>
            /// validate the user , and set the cookie
            /// </summary>
            public override bool ValidateUser(string loginName, string pwd)
            {
                UserData userdata = new UserData();
                if (!userdata.Login(loginName, pwd))
                    return false;

                System.Web.Security.FormsAuthentication.SetAuthCookie(loginName, false, "/");

                return true;
            }

            public override AppChatIdentity GetLogonIdentity()
            {
                string loginname = "";
                string nickname = "";
                if (UserApi.User.IsLoggedIn)
                {
                    loginname = UserApi.User.LoggedInUser.Username;
                    nickname = UserApi.User.LoggedInUser.Username; //this needs to be changed to Screename
                    return new AppChatIdentity(nickname, false, ToUserId(loginname), HttpContext.Current.Request.UserHostAddress);
                }
                else
                {
                    return null; //TODO: Redirect to login page
                }
                
            }

        }
View Complete Thread