about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/InvalidSession.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/InvalidSession.razor')
-rw-r--r--MatrixRoomUtils.Web/Pages/InvalidSession.razor100
1 files changed, 0 insertions, 100 deletions
diff --git a/MatrixRoomUtils.Web/Pages/InvalidSession.razor b/MatrixRoomUtils.Web/Pages/InvalidSession.razor
deleted file mode 100644
index 7d4769c..0000000
--- a/MatrixRoomUtils.Web/Pages/InvalidSession.razor
+++ /dev/null
@@ -1,100 +0,0 @@
-@page "/InvalidSession"
-@using LibMatrix
-
-<PageTitle>Invalid session</PageTitle>
-
-<h3>Rory&::MatrixUtils - Invalid session encountered</h3>
-<p>A session was encountered that is no longer valid. This can happen if you have logged out of the account on another device, or if the access token has expired.</p>
-
-@if (_login is not null) {
-    <p>It appears that the affected user is @_login.UserId (@_login.DeviceId) on @_login.Homeserver!</p>
-    <LinkButton OnClick="@(OpenRefreshDialog)">Refresh token</LinkButton>
-    <LinkButton OnClick="@(RemoveUser)">Remove</LinkButton>
-
-    @if (_showRefreshDialog) {
-        <ModalWindow MinWidth="300" X="275" Y="300" Title="@($"Password for {_login.UserId}")">
-            <FancyTextBox IsPassword="true" @bind-Value="@_password"></FancyTextBox><br/>
-            <LinkButton OnClick="TryLogin">Log in</LinkButton>
-            @if (_loginException is not null) {
-                <pre style="color: red;">@_loginException.RawContent</pre>
-            }
-        </ModalWindow>
-    }
-}
-else {
-    <b>Something has gone wrong and the login was not passed along!</b>
-}
-
-@code
-{
-    [Parameter]
-    [SupplyParameterFromQuery(Name = "ctx")]
-    public string Context { get; set; }
-
-    private UserAuth? _login { get; set; }
-
-    private bool _showRefreshDialog { get; set; }
-
-    private string _password { get; set; } = "";
-
-    private MatrixException? _loginException { get; set; }
-
-    protected override async Task OnInitializedAsync() {
-        var tokens = await MRUStorage.GetAllTokens();
-        if (tokens is null || tokens.Count == 0) {
-            NavigationManager.NavigateTo("/Login");
-            return;
-        }
-
-        _login = tokens.FirstOrDefault(x => x.AccessToken == Context);
-
-        if (_login is null) {
-            Console.WriteLine($"Could not find {_login} in stored tokens!");
-        }
-
-        await base.OnInitializedAsync();
-    }
-
-    private async Task RemoveUser() {
-        await MRUStorage.RemoveToken(_login!);
-        if ((await MRUStorage.GetCurrentToken())!.AccessToken == _login!.AccessToken)
-            await MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens())?.FirstOrDefault());
-        await OnInitializedAsync();
-    }
-
-    private async Task OpenRefreshDialog() {
-        _showRefreshDialog = true;
-        StateHasChanged();
-        await Task.CompletedTask;
-    }
-
-    private async Task SwitchSession(UserAuth auth) {
-        Console.WriteLine($"Switching to {auth.Homeserver} {auth.AccessToken} {auth.UserId}");
-        await MRUStorage.SetCurrentToken(auth);
-        await OnInitializedAsync();
-    }
-
-    private async Task TryLogin() {
-        if(_login is null) throw new NullReferenceException("Login is null!");
-        try {
-            var result = new UserAuth(await hsProvider.Login(_login.Homeserver, _login.UserId, _password));
-            if (result is null) {
-                Console.WriteLine($"Failed to login to {_login.Homeserver} as {_login.UserId}!");
-                return;
-            }
-            Console.WriteLine($"Obtained access token for {result.UserId}!");
-
-            await RemoveUser();
-            await MRUStorage.AddToken(result);
-            if (result.UserId == (await MRUStorage.GetCurrentToken())?.UserId)
-                await MRUStorage.SetCurrentToken(result);
-            NavigationManager.NavigateTo("/");
-        }
-        catch (MatrixException e) {
-            Console.WriteLine($"Failed to login to {_login.Homeserver} as {_login.UserId}!");
-            Console.WriteLine(e);
-            _loginException = e;
-            StateHasChanged();
-        }
-    }
-}