Ejemplo n.º 1
0
 public void addUser(string userName, string password)
 {
     if (userName.Count() < 4)
     {
         MessageBox.Show("Your UserName must be of at least 4 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return;
     }
     if (password.Count() < 6)
     {
         MessageBox.Show("Your Password must be of at least 6 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return;
     }
     using (System.Security.Cryptography.MD5 md5Hash = System.Security.Cryptography.MD5.Create())
     {
         string hash = GetMd5Hash(md5Hash, password);
         if (this._users.getUsers().Any(u => u.UserName == userName))
         {
             MessageBox.Show("Error: UserName already exists.", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
             return;
         }
         User user = new User(userName, hash);
         this._users.add(user);
         this.save();
         if (!Directory.Exists(PlaylistManager.PlaylistPath + userName))
             Directory.CreateDirectory(PlaylistManager.PlaylistPath + userName);
         MessageBox.Show("Your account has been saved, please login.", "Login", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
     }
 }
Ejemplo n.º 2
0
 public void addUser(User user)
 {
     if (user.UserName.Count() < 4)
     {
         MessageBox.Show("Your UserName must be of at least 4 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return;
     }
     if (this._users.getUsers().Any(u => u.UserName == user.UserName))
     {
         MessageBox.Show("Error: UserName already exists.", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return;
     }
     this._users.add(user);
     this.save();
     if (!Directory.Exists(PlaylistManager.PlaylistPath + user.UserName))
         Directory.CreateDirectory(PlaylistManager.PlaylistPath + user.UserName);
 }
Ejemplo n.º 3
0
 public bool AddFolder(User user, string name)
 {
     if (name == "")
         return false;
     else if (user == null)
     {
         MessageBox.Show("You must be logged to create folders", "Playlist Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return false;
     }
     else if (name == "" || this._tree.ContainsKey(name) || !_regexName.Match(name).Success)
     {
         MessageBox.Show("Folder's name invalid", "Playlist Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return false;
     }
     Directory.CreateDirectory(PlaylistPath + user.UserName + "/" + name);
     this._tree.Add(name, new List<string>());
     return true;
 }
Ejemplo n.º 4
0
 public void removeUser(User user)
 {
     this._users.remove(user);
 }
Ejemplo n.º 5
0
 public void removeUser(string userName, string password)
 {
     User user = new User(userName, password);
     this._users.remove(user);
 }
Ejemplo n.º 6
0
 public void logoutUser()
 {
     this._loggedInUser = null;
 }
Ejemplo n.º 7
0
 public bool checkUser(User user)
 {
     if (user.UserName.Count() < 4)
     {
         MessageBox.Show("Your UserName must be of at least 4 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return false;
     }
     if (!this._users.getUsers().Contains(user))
         return false;
     this._loggedInUser = user;
     MessageBox.Show("Your have successfully logged in.", "Login", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
     return true;
 }
Ejemplo n.º 8
0
 public bool checkUser(string userName, string password)
 {
     if (userName.Count() < 4)
     {
         MessageBox.Show("Your UserName must be of at least 4 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return false;
     }
     if (password.Count() < 6)
     {
         MessageBox.Show("Your Password must be of at least 6 characters.", "Name Change", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.None);
         return false;
     }
     using (System.Security.Cryptography.MD5 md5Hash = System.Security.Cryptography.MD5.Create())
     {
         string hash = GetMd5Hash(md5Hash, password);
         if (!this._users.getUsers().Any(u => u.UserName ==  userName && u.Password == hash))
         {
             MessageBox.Show("Error: UserName or password is incorrect.", "Login Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
             return false;
         }
         User user = this._users.getUsers().Select(u => u).Where(u => u.UserName == userName && u.Password == hash).First();
         this._loggedInUser = user;
         return true;
     }
 }
Ejemplo n.º 9
0
 public bool AddPlaylistToFolder(User user, string name, string folder)
 {
     if (name == "")
         return false;
     else if (this._tree[folder].Contains(name) || !_regexName.Match(name).Success)
     {
         MessageBox.Show("playlist's name invalid", "Playlist Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return false;
     }
     string pls = PlaylistPath + user.UserName + "/" + folder + "/" + name;
     FileStream fs = File.Create(pls);
     fs.Close();
     this._tree[folder].Add(name);
     this.loadPlaylist(pls);
     return true;
 }
Ejemplo n.º 10
0
 public Playlist selectPlaylistInFolder(User user, string name, string folder)
 {
     string pls = PlaylistPath + user.UserName + "/" + folder + "/" + name;
     return (this._playlists[pls]);
 }
Ejemplo n.º 11
0
 public bool removePlaylistFromFolder(User user, string name, string folder)
 {
     try
     {
         if (MessageBox.Show("Do you really want to delete this playlist ?", "Playlist Change", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
             return false;
         string pls = PlaylistPath + user.UserName + "/" + folder + "/" + name;
         File.Delete(pls);
         this._tree[folder].Remove(name);
         this._playlists.Remove(pls);
         return true;
     }
     catch
     {
         MessageBox.Show("Can't delete playlist", "Playlist Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return false;
     }
 }
Ejemplo n.º 12
0
 public bool removeFolder(User user, string name)
 {
     try
     {
         Directory.Delete(PlaylistPath + user.UserName + "/" + name, true);
         this._tree.Remove(name);
         return true;
     }
     catch
     {
         MessageBox.Show("Can't delete folder", "Playlist Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.None);
         return false;
     }
 }
Ejemplo n.º 13
0
        public List<TreeViewItem> reload(User user)
        {
            List<TreeViewItem> res = new List<TreeViewItem>();

            this._tree.Clear();
            this._playlists.Clear();
            res.Add(new TreeViewItem { Header = "default playlist", Tag = "LibraryItem" });
            if (user != null)
            {
                string[] dirs = Directory.GetDirectories(PlaylistPath + user.UserName);

                foreach (string dir in dirs)
                {
                    string[] files = Directory.GetFiles(dir);
                    string folder = Path.GetFileName(dir);
                    TreeViewItem item = new TreeViewItem { Header = folder, Tag = "PlaylistFolder" };

                    this._tree.Add(folder, new List<string>());
                    res.Add(item);
                    foreach (string file in files)
                    {
                        string pls = Path.GetFileName(file);
                        this._tree[folder].Add(pls);
                        this.loadPlaylist(file);
                        item.Items.Add(new TreeViewItem { Header = pls, Tag = "Playlist" });
                    }
                }
            }
            return res;
        }
Ejemplo n.º 14
0
 public void remove(User user)
 {
     this._content.Remove(user);
 }
Ejemplo n.º 15
0
 public void add(User user)
 {
     this._content.Add(user);
 }