public bool BindDeviceWithExistingAccount(List <double> encryptedData) { JObject deviceBindDataJson = JObject.Parse(MatrixCryptography.Decrypt(encryptedData)); string macAddress = deviceBindDataJson["mac_address"].ToString(); string username = deviceBindDataJson["username"].ToString(); string password = deviceBindDataJson["password"].ToString(); Output.ShowLog("BindDeviceWithExistingAccount() => mac: " + macAddress + " Username: " + username); bool?success = UserRepository.Instance.BindMacAddressByUsername(username, macAddress); if (success == null || success == false) { return(false); } return(true); }
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); }
public long SignupUser(List <double> encryptedData) //receives encrypted json string { //type:consumer"; //username:example" //email:[email protected]" //name:example" //mac_address:E1234567890AB" try { JObject signupDataJson = JObject.Parse(MatrixCryptography.Decrypt(encryptedData)); Output.ShowLog("SignupUser() => " + signupDataJson.ToString()); string accountType = signupDataJson["type"].ToString(); long? insertedId = null; User newUser = null; if (accountType == "consumer") { newUser = new Consumer(signupDataJson["username"].ToString(), signupDataJson["email"].ToString(), signupDataJson["name"].ToString()); insertedId = UserRepository.Instance.Insert(newUser); if (insertedId == null) { return(-1); } newUser.Id = (long)insertedId; ConsumerRepository.Instance.Insert((Consumer)newUser); } if (insertedId != null) { UserRepository.Instance.BindMacAddressById((long)insertedId, signupDataJson["mac_address"].ToString()); } return(insertedId ?? -1); //if the insertedId is null, we will return -1 } catch (Exception ex) { Output.ShowLog(ex.InnerException.Message); return(-1); } }
public List <double> LoginWithEncryptedData(List <double> encryptedLoginData) //receives encrypted json string { try { JObject credentials = JObject.Parse(MatrixCryptography.Decrypt(encryptedLoginData)); string macAddress = credentials["mac_address"].ToString(); string password = credentials["password"].ToString(); bool isDataSourceFromCookie = bool.Parse(credentials["from_cookie"].ToString()); Output.ShowLog("LoginWithEncryptedData() => " + macAddress + " Credentials from cookie? " + isDataSourceFromCookie); if (isDataSourceFromCookie && Time.TimeDistanceInMinute(new Time(credentials["last_login_time"].ToString()), Time.CurrentTime) > 4320) { return(DataProcessor.ProcessLoggedInUserData(null)); } User loggedInUser = ClientManager.Instance.RegisterLoggedInUser(macAddress, password); return(DataProcessor.ProcessLoggedInUserData(loggedInUser)); } catch (Exception ex) { Output.ShowLog(ex.Message); return(null); } }