about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/LoginPage.razor
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-01 02:43:32 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-01 02:43:32 +0200
commitdf9031c47f8e97d8e2df3177093271a458f27267 (patch)
tree4e81dec4048c6e76a928ef69c905560d7c173fdf /MatrixRoomUtils.Web/Pages/LoginPage.razor
downloadMatrixUtils-df9031c47f8e97d8e2df3177093271a458f27267.tar.xz
Initial commit
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/LoginPage.razor')
-rw-r--r--MatrixRoomUtils.Web/Pages/LoginPage.razor46
1 files changed, 46 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Pages/LoginPage.razor b/MatrixRoomUtils.Web/Pages/LoginPage.razor
new file mode 100644
index 0000000..d193f95
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/LoginPage.razor
@@ -0,0 +1,46 @@
+@page "/Login"
+@using MatrixRoomUtils.Authentication
+@using MatrixRoomUtils.Web.Classes
+@using Blazored.LocalStorage
+@inject ILocalStorageService LocalStorage
+<h3>Login</h3>
+
+<label>Homeserver:</label>
+<input @bind="homeserver"/>
+<br/>
+<label>Username:</label>
+<input @bind="username"/>
+<br/>
+<label>Password:</label>
+<input @bind="password" type="password"/>
+<br/>
+<button @onclick="Login">Login</button>
+<br/>
+<br/>
+<LogView></LogView>
+
+@code {
+    string homeserver = "";
+    string username = "";
+    string password = "";
+    async Task Login()
+    {
+        var result = await MatrixAccount.Login(homeserver, username, password);
+        Console.WriteLine($"Obtained access token for {result.UserId}!");
+        
+        RuntimeStorage.AccessToken = result.AccessToken;
+
+        var userinfo = new UserInfo()
+        {
+            LoginResponse = result
+        };
+        userinfo.Profile = await MatrixAccount.GetProfile(result.HomeServer, result.UserId);
+
+        RuntimeStorage.UsersCache.Add(result.AccessToken, userinfo);
+        RuntimeStorage.CurrentHomeserver = await MatrixAccount.ResolveHomeserverFromWellKnown(result.HomeServer);
+        
+
+        await RuntimeStorage.SaveToLocalStorage(LocalStorage);
+
+    }
+}
\ No newline at end of file