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); } }
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); }
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; }
public void removeUser(User user) { this._users.remove(user); }
public void removeUser(string userName, string password) { User user = new User(userName, password); this._users.remove(user); }
public void logoutUser() { this._loggedInUser = null; }
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; }
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; } }
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; }
public Playlist selectPlaylistInFolder(User user, string name, string folder) { string pls = PlaylistPath + user.UserName + "/" + folder + "/" + name; return (this._playlists[pls]); }
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; } }
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; } }
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; }
public void remove(User user) { this._content.Remove(user); }
public void add(User user) { this._content.Add(user); }