public GestionnaireCommunication(Membre membreCourant) { this.membreCourant = membreCourant; isReading = true; tcpClient = new TcpClient(HOSTNAME, PORT); reader = new StreamReader(tcpClient.GetStream()); writer = new StreamWriter(tcpClient.GetStream()); writer.AutoFlush = true; writer.WriteLine(Convert.ToString(membreCourant.id)); }
/// <summary> /// Ajout d'un membre /// </summary> /// <param name="nouveauMembre"></param> /// <returns>Retourne l'id du membre inséré</returns> public int InsertMember(Membre nouveauMembre) { FileStream fs; BinaryReader br; string passwordCrypte = CryptPassword(nouveauMembre.password); command = connection.CreateCommand(); command.CommandText = "INSERT INTO utilisateur (username, password," + "Nom, Prenom, email, sexe, image, imgFile_name, imgFile_size) " + "VALUES (@nom_utilisateur, @mdp, @nom," + "@prenom, @email, @sexe, @image, @imgFile_name, @imgFile_size)"; command.Parameters.AddWithValue("@nom_utilisateur", nouveauMembre.username); command.Parameters.AddWithValue("@mdp", passwordCrypte); command.Parameters.AddWithValue("@nom", nouveauMembre.lastName); command.Parameters.AddWithValue("@prenom", nouveauMembre.firstName); command.Parameters.AddWithValue("@email", nouveauMembre.email); command.Parameters.AddWithValue("@sexe", Enum.GetName(typeof(Genre), nouveauMembre.gender)); command.Parameters.AddWithValue("@image", nouveauMembre.imageData); command.Parameters.AddWithValue("@imgFile_name", nouveauMembre.imgFileName); command.Parameters.AddWithValue("@imgFile_size", nouveauMembre.fileSize); // connection.Open(); command.ExecuteNonQuery(); return Convert.ToInt32(command.LastInsertedId); }
/// <summary> /// Récupération d'un membre par son username et password /// </summary> /// <param name="username_membre"></param> /// <param name="password_membre"></param> /// <returns>Retourne le membre en question</returns> public Membre GetMember(string username_membre, string password_membre) { String crypt = CryptPassword(password_membre); Membre membre = null; string query = "SELECT * FROM utilisateur where username='******' and password='******'"; command = new MySqlCommand(query, this.connection); MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); membre = new Membre(); membre.id = reader.GetInt32("id_utilisateur"); membre.username = reader.GetString("username"); membre.password = passwordCrypte; membre.firstName = reader.GetString("Prenom"); membre.lastName = reader.GetString("Nom"); membre.email = reader.GetString("email"); membre.gender = (Genre) Enum.Parse(typeof(Genre),reader.GetString("sexe")); } reader.Close(); return membre; }
/// <summary> /// Recherche le membre demander et le garde en mémoire /// </summary> /// <param name="username">Le nom d'utilisateur</param> /// <param name="password">Le mot de passe</param> /// <returns>vrai si le login a réussi faux sinon</returns> public bool Login(string username, string password) { membreCourant = dao.GetMember(username, password); // membreCourant = new Membre(id, "m", "m", "m" + id, "m", "m", Genre.MALE, "m", new byte[1], 1); if (membreCourant != null) { gestionnaireCommunication = new GestionnaireCommunication(membreCourant); gestionnaireCommunication.StartReading(); } return membreCourant != null; }