public static bool?BindDeviceAndLogin(string macAddress, string username, string password) { JObject deviceBindDataJson = new JObject(); deviceBindDataJson["mac_address"] = macAddress; deviceBindDataJson["username"] = username; deviceBindDataJson["password"] = password; List <double> encryptedData = MatrixCryptography.Encrypt(deviceBindDataJson.ToString()); bool? success = null; ServerHub.WorkingInstance.ServerHubProxy.Invoke <bool>("BindDeviceWithExistingAccount", encryptedData).ContinueWith(task => { if (!task.IsFaulted) { success = task.Result; } else { success = null; } }).Wait(); if (success == true) { deviceBindDataJson["from_cookie"] = false; return(SetLoggedInUser(deviceBindDataJson)); } return(success); }
public static long?SignupUser(JObject signupDataJson) { List <double> encryptedData = MatrixCryptography.Encrypt(signupDataJson.ToString()); long? userId = null; ServerHub.WorkingInstance.ServerHubProxy.Invoke <long>("SignupUser", encryptedData).ContinueWith(task => { if (!task.IsFaulted) { userId = task.Result; } else { userId = null; } }).Wait(); return(userId); }
public static bool?SetLoggedInUser(JObject loginDataJson) { List <double> encryptedCookieData = MatrixCryptography.Encrypt(loginDataJson.ToString()); List <double> encryptedFetchedUserData = null; ServerHub.WorkingInstance.ServerHubProxy.Invoke <List <double> >("LoginWithEncryptedData", encryptedCookieData).ContinueWith(task => { if (!task.IsFaulted) { encryptedFetchedUserData = task.Result; } else { Console.WriteLine(task.Exception.InnerException.Message); } }).Wait(); if (encryptedFetchedUserData == null) { return(null); } JObject fetchedUserDataJson = JObject.Parse(MatrixCryptography.Decrypt(encryptedFetchedUserData)); User loggedInUser = null; if (bool.Parse(fetchedUserDataJson["found"].ToString()) == true) { string type = fetchedUserDataJson["type"].ToString(); if (type == "consumer") { Consumer.LoggedIn = new Consumer(fetchedUserDataJson); loggedInUser = Consumer.LoggedIn; if (fetchedUserDataJson.ContainsKey("profile_img_id") && fetchedUserDataJson["profile_img_id"].ToString().Length >= 5) { ServerFileRequest.RefetchProfileImage(fetchedUserDataJson["profile_img_id"].ToString()); Consumer.LoggedIn.SetProfileImage(fetchedUserDataJson["profile_img_id"].ToString()); } } } else { return(false); } User.LoggedIn = loggedInUser; return(true); }