/// <summary> /// Retrieve the user ID by their name. /// </summary> /// <param name="user"></param> /// <returns></returns> //public static async Task<string> UserIdByName(string user) //{ // var collection = CreateMongoConnection("users"); // var users = await collection.Find(new BsonDocument("user", user)).ToListAsync(); // //Make sure that the user name exists. // if(users.Count != 0) // { // return users[0].Values.ElementAt(0).ToString(); // } // //User name didn't exist. Bad things! // else // { // return null; // } //} public static async Task <bool> doesUserExist(string user, Client socket) { bool?exist = null; if (socket.IsConnected) { socket.On("does_user_exist", (fn) => { exist = fn.Json.Args[0] == "false" ? false : true; }); socket.Emit("does_user_exist", user); } TimeoutCounter counter = new TimeoutCounter(); var thread = new Thread( () => { exist = counter.start(Global.serverTimeout); }); thread.Start(); while (exist == null) { ; } counter.Stop(); thread.Abort(); if (counter.timeout) { throw new Exception("TIMEOUT"); } return((bool)exist); }
/// <summary> /// Find all movies attached to a user ID. /// </summary> /// <param name="user"></param> /// <returns>Returned tuple contains: MovieID, UserRating, PosterID</returns> public static async Task <List <Movie> > AllMoviesByUser(string userID, Client socket) { List <Movie> toReturn = null; bool? timeout = false; socket.On("request_movie_information", (fn) => { toReturn = MiscHelpers.moivesFromDynamic(fn.Json.Args[0]); }); socket.Emit("request_movie_information", "plz"); TimeoutCounter counter = new TimeoutCounter(); var thread = new Thread( () => { timeout = counter.start(Global.serverTimeout * 10); }); thread.Start(); while (toReturn == null && (bool)!timeout) { ; } counter.Stop(); thread.Abort(); if (counter.timeout) { throw new Exception("TIMEOUT"); } return(toReturn); }
/// <summary> /// Returns true if the user's information is correct. /// </summary> /// <param name="user"></param> /// <param name="pass"></param> /// <returns></returns> public static async Task <string> VerifyCredentials(string user, string pass, Client socket) { bool? auth = null; string uid = ""; socket.On("disconnect", (fn) => { auth = false; }); socket.On("authenticate", (fn) => { string authMessage = fn.Json.Args[0].ToString().Split(' ')[0]; uid = fn.Json.Args[0].ToString().Split(' ')[1]; if (authMessage == "authenitcated") { auth = true; } else { auth = false; } }); if (socket.IsConnected) { socket.Emit("authenticate", new { user = user.ToLower(), password = pass.ToLower() }); } TimeoutCounter counter = new TimeoutCounter(); var thread = new Thread( () => { auth = counter.start(Global.serverTimeout); }); thread.Start(); while (auth == null) { ; } thread.Abort(); counter.Stop(); if (counter.timeout) { throw new Exception("TIMEOUT"); } if (auth == true) { return(uid); } else { return(""); } }