public static void Handle(Rate temp, Socket socket) { bool VoteExist = UsersInfos.VoteExist(temp.MusicRatedMID, Program.MyServer.Clients[socket]); UsersInfos.AddVoteMusic(temp.MusicRatedMID, Program.MyServer.Clients[socket]); if (temp.Type == ElementType.Music) { var m = Indexation.GetMusicByID(temp.MusicRatedMID); if (m != null) { if (VoteExist) { m.Rating--; } else { m.Rating++; Program.MyServer.Clients.TryGetValue(socket, out string uid); Program.MyServer.SendObject(new RequestAnswer(UsersInfos.GetLikedMusics(uid)), socket); } Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, m.Rating), socket); MusicsInfo.SaveMusicInfo(m); } } else { UsersInfos.RatePlaylist(temp.MusicRatedMID, !VoteExist); Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, UsersInfos.GetPlaylist(temp.MusicRatedMID).Rating), socket); } }
void ReceiveAuthInfo(Login received, Socket socket) { if (received is Login) { Login auth = received as Login; Program.MyServer.Log.Warn("Client try to login"); var foundUser = UsersInfos.GetAllUsers().SingleOrDefault(u => u.UID == auth.LoginInfo.UID); var isRegister = foundUser != null; AuthInfo authInfo; if (isRegister) { authInfo = new AuthInfo(isRegister, Rank.Viewer, foundUser); Program.MyServer.Clients.AddUser(auth.LoginInfo, socket); Program.MyServer.Log.Warn($"Client succefuly logged in ({authInfo.User.Name})"); } else { authInfo = new AuthInfo(true, Rank.Viewer, new User(auth.LoginInfo)); Program.MyServer.AuthService.SignupUser(auth.LoginInfo); Program.MyServer.Clients.Remove(socket); Program.MyServer.Clients.AddUser(auth.LoginInfo, socket); Program.MyServer.Log.Warn($"Client succefuly signed up ({authInfo.User.Name})"); } authInfo.Send(socket); } }
private static void DoPlaylist(RequestSearch requestSearch, Socket asker) { string userUID = MyServer.Clients.GetUser(asker).UID; var playlists = UsersInfos.GetPlaylists(userUID).Where(p => Search.Find(requestSearch.Name, p.Name)); (new RequestAnswer(playlists.Cast <IElement>().ToList(), ElementType.Playlist, requestSearch.Name)).Send(asker); }
public void RatePlaylistTest() { //2e1047e01b9f0d927651f33ec8ddce63 Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); User ur = new User(new Utility.Network.Users.CryptedCredentials("User1", "abc")); a.SignupUser(ur); var m = new Music("Music1", new Author("Albert", "path2"), new Album(new Author("Albert", "path2"), "AlbertAlum"), "path", 0); Playlist pl = new Playlist(ur, "Playlist1", new List <Music>() { m }, false) { Rating = 1 }; UsersInfos.SaveUserPlaylist("abc", pl); UsersInfos.RatePlaylist(pl.MID, false); Assert.AreEqual("2e1047e01b9f0d927651f33ec8ddce63", Function.GetMD5(@"users.xml")); UsersInfos.RatePlaylist(pl.MID, true); Assert.AreEqual("76fdfae945157b5ec9732d9416c080c4", Function.GetMD5(@"users.xml")); }
private static void TreatEditRequest(Socket socket, EditRequest editRequest) { switch (editRequest.TypeOfEdit) { case TypesEdit.Users: if (UsersInfos.GetRankOfUser(MyServer.Clients.GetUser(socket).UID) > editRequest.NewRankOfUser && UsersInfos.GetRankOfUser(MyServer.Clients.GetUser(socket).UID) > UsersInfos.GetRankOfUser(editRequest.UserToEdit)) { PromoteUser(editRequest.UserToEdit, editRequest.NewRankOfUser); List <User> tmpU = new List <User> { UsersInfos.GetUser(editRequest.UserToEdit) }; MyServer.SendObject(new RequestAnswer(tmpU, true), socket); MyServer.Log.Warn($"User promoted { editRequest.UserToEdit} to " + editRequest.NewRankOfUser.ToString()); } else { MyServer.Log.Warn($"Promoting the user {editRequest.UserToEdit} to {editRequest.NewRankOfUser.ToString()} failed !"); } break; case TypesEdit.Musics: if (MyServer.Clients.GetUser(socket).Rank > Rank.User) { Indexation.ModifyElement(editRequest.ObjectToEdit as Element, editRequest.NewName, editRequest.NewGenres); MyServer.Log.Warn($"The musics {editRequest.NewName} has been edited !"); } else { MyServer.Log.Warn($"The musics {editRequest.NewName } couldn't be edited"); } break; } }
public void GetRankOfUserTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); Assert.AreEqual(true, UsersInfos.GetRankOfUser("abc") == Rank.Viewer); Assert.AreEqual(true, UsersInfos.GetRankOfUser("abC") == Rank.Viewer);//TODO: add some test for other rank }
public static void PromoteUser(string UID, Rank rank) { UsersInfos.SetRankOfUser(UID, rank); if (MyServer.Clients.IsConnected(UID)) { var userUpdated = UsersInfos.GetUser(UID); new EditUserReport(true, userUpdated).Send(MyServer.Clients.GetSocket(UID)); } }
public override void Execute(IEnumerable <string> args) { Log.Info("Getting all users"); foreach (var u in UsersInfos.GetAllUsers()) { Log.Info($" - {u.Name} {u.Rank.ToString()} {u.UID}"); } Log.Info("End."); }
public void SetRankOfUserTest() { //59fdab60bac3fb5c3bdf9e8cb772e637 Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); UsersInfos.SetRankOfUser("abc", Rank.Creator); Assert.AreEqual("59fdab60bac3fb5c3bdf9e8cb772e637", Function.GetMD5(@"users.xml")); }
public void SearchUserTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); var getuser = UsersInfos.SearchUser("User1"); Assert.AreEqual(true, getuser[0].Name == "User1"); Assert.AreEqual(true, getuser[0].UID == "abc"); }
public void VoteExistTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("IncorrectMID", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "IncorrectUID")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "abc")); UsersInfos.AddVoteMusic("MusicMID", "abc"); Assert.AreEqual(false, UsersInfos.VoteExist("IncorrectMID", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "IncorrectUID")); Assert.AreEqual(true, UsersInfos.VoteExist("MusicMID", "abc")); }
public void AddVoteMusicTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); UsersInfos.AddVoteMusic("MusicMID", "abC"); Assert.AreEqual("e0c5d6856147fbaf2888fc1720e9f7c8", Function.GetMD5(@"users.xml")); UsersInfos.AddVoteMusic("MusicMID", "abc"); Assert.AreEqual("3f8c88f5cad87ebbae3ad701842c876e", Function.GetMD5(@"users.xml")); UsersInfos.AddVoteMusic("MusicMID", "abc"); Assert.AreEqual("e0424ec3aad221f0f22836728db397f7", Function.GetMD5(@"users.xml")); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new UsersInfos { UserName = Input.UserName, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); // THE CODE BELOW IS FOR EMAIL CONFIRMATION. I AM NOT USING EMAIL CONFIRMATION AT THE MOMENT //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); //var callbackUrl = Url.Page( // "/Account/ConfirmEmail", // pageHandler: null, // values: new { area = "Identity", userId = user.Id, code = code }, // protocol: Request.Scheme); //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //if (_userManager.Options.SignIn.RequireConfirmedAccount) //{ // return RedirectToPage("RegisterConfirmation", new { email = Input.Email }); //} //else //{ // await _signInManager.SignInAsync(user, isPersistent: false); // return LocalRedirect(returnUrl); //} } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public void GetAllUsersTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User2", "abc2")); var getall = UsersInfos.GetAllUsers(); Assert.AreEqual(true, getall[0].Name == "User1"); Assert.AreEqual(true, getall[0].UID == "abc"); Assert.AreEqual(true, getall[1].Name == "User2"); Assert.AreEqual(true, getall[1].UID == "abc2"); }
private static void Edituser(Socket socket, EditRequest editRequest) { if (UsersInfos.GetRankOfUser(Program.MyServer.Clients.GetUser(socket).UID) > editRequest.NewRankOfUser && UsersInfos.GetRankOfUser(Program.MyServer.Clients.GetUser(socket).UID) > UsersInfos.GetRankOfUser(editRequest.UserToEdit)) { Program.PromoteUser(editRequest.UserToEdit, editRequest.NewRankOfUser); List <User> tmpU = new List <User> { UsersInfos.GetUser(editRequest.UserToEdit) }; (new RequestAnswer(tmpU, true)).Send(socket); Program.MyServer.Log.Warn($"User promoted { editRequest.UserToEdit} to " + editRequest.NewRankOfUser.ToString()); } else { Program.MyServer.Log.Warn($"Promoting the user {editRequest.UserToEdit} to {editRequest.NewRankOfUser.ToString()} failed !"); } }
public void RemoveVoteByNodeTest() { //e0424ec3aad221f0f22836728db397f7 Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); XmlDocument doc = new XmlDocument(); doc.Load(@"users.xml"); XmlNodeList nodes = doc.DocumentElement.SelectNodes("User"); UsersInfos.CreateVoteByNode("MusicMID", doc, nodes[0]); UsersInfos.RemoveVoteByNode("MusicMID", nodes[0]); doc.Save(@"users.xml"); Assert.AreEqual("e0424ec3aad221f0f22836728db397f7", Function.GetMD5(@"users.xml")); }
public void CreateVoteByNodeTest() { //3f8c88f5cad87ebbae3ad701842c876e Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); XmlDocument doc = new XmlDocument(); doc.Load(@"users.xml"); XmlNodeList nodes = doc.DocumentElement.SelectNodes("User"); UsersInfos.CreateVoteByNode("MusicMID", doc, nodes[0]); doc.Save(@"users.xml"); Assert.AreEqual("3f8c88f5cad87ebbae3ad701842c876e", Function.GetMD5(@"users.xml")); }
public static void PromoteUser(string UID, Rank rank) { UsersInfos.SetRankOfUser(UID, rank); if (MyServer.Clients.IsConnected(UID)) { var userUpdated = UsersInfos.GetUser(UID); MyServer.SendObject(new EditUserReport(true, userUpdated), MyServer.Clients.GetSocket(UID)); } //User tmpUser = MyServer.Clients.GetUser(UID); //if (tmpUser != null) //{ // tmpUser.Rank = rank; // Socket tmpSocket = MyServer.Clients.GetSocket(UID); // MyServer.Clients.Remove(tmpSocket); // MyServer.Clients.AddUser(tmpUser, tmpSocket); // MyServer.SendObject(new EditUserReport(true, MyServer.Clients.GetUser(UID)), MyServer.Clients.GetSocket(UID)); //} }
public void Handle(Request request, Socket socket) { switch (request.RequestsType) { case RequestsTypes.Search: Console.WriteLine("Request by client :" + (request as RequestSearch).Name); MusicsManagement.ClientSearch.SearchAnswer.Do(request as RequestSearch, socket); break; case RequestsTypes.MusicsBinaries: if (Indexation.TryGetMusicByID((request as RequestBinairies).RequestedBinaries.MID, out Music m)) { Music answer = new Music(m.Title, new Author(m.Author.Name), m.Album, Indexation.GetFileBinary(m)) { Format = m.Format, Rating = m.Rating }; new RequestAnswer(answer).Send(socket); } break; case RequestsTypes.Favorites: List <Music> tmp = UsersInfos.GetLikedMusics((request as RequestFavorites).UserID); new RequestAnswer(tmp).Send(socket); break; case RequestsTypes.Users: if (Program.MyServer.Clients.GetUser(socket).Rank != Rank.Viewer) { new RequestAnswer(UsersInfos.SearchUser((request as RequestUser).Username), true).Send(socket); } else { new RequestAnswer(null, false).Send(socket); } break; } }
public static void TreatRequest(byte[] Buffer, Socket socket) { object received; try { received = Function.Deserialize(new MessageTCP(Buffer)); } catch { return; } bool ClientLogin; try { ClientLogin = MyServer.Clients.GetUser(socket).UID != null; } catch { ClientLogin = false; } if (ClientLogin) { if (!MyServer.Tokenlist.CheckTokenValidity((received as Packet).Token, socket)) { MyServer.Log.Warn($"Client Token not valide (THash : {(received as Packet).Token?.THash})"); return; } switch (received) { case Request request: TreatRequest(socket, request); break; case Rate rate: TreatRate(socket, rate); break; case Disconnect disconnect: TreatDisconnect(socket); break; case EditUser editUser: TreatEditUser(socket, editUser); break; case EditRequest editRequest: TreatEditRequest(socket, editRequest); break; case SavePlaylist savePlayList: TreatSavePlayList(savePlayList); break; case UploadMusic uploadMusic: TreatUploadMusic(socket, uploadMusic); break; } } else { if (received is Login) { Login auth = received as Login; MyServer.Log.Warn("Client try to login"); if (auth.IsSignup) { AuthInfo authInfo = new AuthInfo(true, Rank.Viewer, auth.LoginInfo.UID); MyServer.AuthService.SignupUser(auth.LoginInfo); MyServer.Clients.Remove(socket); MyServer.Clients.AddUser(auth.LoginInfo, socket); MyServer.SendObject(authInfo, socket); } else { // if (MyServer.AuthService.SigninUser(auth.LoginInfo) && !MyServer.Clients.Contains(auth.LoginInfo.UID)) if (true) { var foundUser = UsersInfos.GetAllUsers().SingleOrDefault(u => u.UID == auth.LoginInfo.UID); var isRegister = foundUser != null; AuthInfo authInfo = new AuthInfo(true, Rank.Viewer, foundUser); if (!MyServer.Tokenlist.AddToken(socket, authInfo.Token)) { return; } if (isRegister) { // MyServer.Clients.Remove(socket); MyServer.Clients.AddUser(auth.LoginInfo, socket); } MyServer.SendObject(authInfo, socket); } else { //MyServer.SendObject(new AuthInfo(false, Rank.Viewer), socket); } } } } }
private static void TreatSavePlayList(SavePlaylist savePlayList) { UsersInfos.SaveUserPlaylist(savePlayList.UID, savePlayList.Playlist); Program.MyServer.Log.Info($"The playlist {savePlayList.Playlist.Name} has been created"); }