// Creates mainUser and goes to convo screen void signInToServerResponse(object sender, EventArgs e) { int messageIndex = serverConnection.unreadMessages.Count - 1; if (messageIndex < 0) { return; } JObject message = JObject.Parse(serverConnection.unreadMessages[messageIndex]); string type = serverConnection.interpretMessageType(message); if (type == "signedIn") { User newUser = new User(); newUser.username = message[type]["username"].ToString(); newUser.email = message[type]["email"].ToString(); newUser.user_id = message[type]["id"].ToString(); newUser.pubKey = message[type]["pubKey"].ToString(); // Load storage. If not same user, reset loadChatsAndUsersFromStorage(); if (mainUser == null || newUser.user_id != mainUser.user_id) { // Deletes all storage SecureStorageHelper ssHelper = new SecureStorageHelper(); ssHelper.RemoveAllItems(); // Loads new users and resets memory of users&chats mainUser = newUser; otherUsers = new Dictionary <string, User> { }; // username:user usernameIdMatches = new Dictionary <string, string> { }; //user_id:username myChats = new Dictionary <string, Chat> { }; // chatname:chat chatNameMatches = new Dictionary <string, string> { }; // chat_id:chatname // Creates a new public key and updates server AsymmetricKeyHelper akh = new AsymmetricKeyHelper(myAsymKeyPairAlias + mainUser.username); akh.CreateKey(); string pubKey = akh.GetSharablePublicKey(); updatePubKey(pubKey); } // Post sign-in activities getAllUsers(); getMyChats(); } if (type == "noAccount") { RunOnUiThread(() => { createAccountScreen(); }); } }
void createUser(string username) { AsymmetricKeyHelper akh = new AsymmetricKeyHelper(myAsymKeyPairAlias + username); akh.CreateKey(); string pubKey = akh.GetSharablePublicKey(); string message = "{\"access_id\": \"" + this.access_id + "\", \"username\": \"" + username + "\", \"pubKey\": \"" + pubKey + "\"}"; serverConnection.WriteMessage("createUser", message); }