├── Docs └── screenshot.png ├── Source └── AppStatServer │ ├── AppStatServerLite │ ├── AppStat.db │ ├── AppStat-log.db │ ├── Sentry │ │ ├── EnvelopeResponse.cs │ │ ├── SectionEntry.cs │ │ ├── SdkEntry.cs │ │ ├── SessionInfo.cs │ │ ├── EnvelopeHandler.cs │ │ └── Event.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── AppStatServerLite.http │ ├── IEventStorage.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Data │ │ └── AppEvent.cs │ ├── AppStatServerLite.csproj │ ├── Program.cs │ └── LiteDbEventStorage.cs │ ├── AppStatServer │ ├── AppStatServer │ │ ├── Components │ │ │ ├── Account │ │ │ │ ├── Pages │ │ │ │ │ ├── _Imports.razor │ │ │ │ │ ├── Manage │ │ │ │ │ │ ├── _Imports.razor │ │ │ │ │ │ ├── PersonalData.razor │ │ │ │ │ │ ├── ResetAuthenticator.razor │ │ │ │ │ │ ├── Disable2fa.razor │ │ │ │ │ │ ├── GenerateRecoveryCodes.razor │ │ │ │ │ │ ├── Index.razor │ │ │ │ │ │ ├── DeletePersonalData.razor │ │ │ │ │ │ ├── SetPassword.razor │ │ │ │ │ │ ├── TwoFactorAuthentication.razor │ │ │ │ │ │ ├── ChangePassword.razor │ │ │ │ │ │ ├── Email.razor │ │ │ │ │ │ ├── ExternalLogins.razor │ │ │ │ │ │ └── EnableAuthenticator.razor │ │ │ │ │ ├── InvalidUser.razor │ │ │ │ │ ├── InvalidPasswordReset.razor │ │ │ │ │ ├── AccessDenied.razor │ │ │ │ │ ├── ForgotPasswordConfirmation.razor │ │ │ │ │ ├── Lockout.razor │ │ │ │ │ ├── ResetPasswordConfirmation.razor │ │ │ │ │ ├── ConfirmEmail.razor │ │ │ │ │ ├── ConfirmEmailChange.razor │ │ │ │ │ ├── RegisterConfirmation.razor │ │ │ │ │ ├── ResendEmailConfirmation.razor │ │ │ │ │ ├── ForgotPassword.razor │ │ │ │ │ ├── LoginWithRecoveryCode.razor │ │ │ │ │ ├── LoginWith2fa.razor │ │ │ │ │ ├── ResetPassword.razor │ │ │ │ │ ├── Login.razor │ │ │ │ │ ├── Register.razor │ │ │ │ │ └── ExternalLogin.razor │ │ │ │ ├── Shared │ │ │ │ │ ├── ManageLayout.razor │ │ │ │ │ ├── ShowRecoveryCodes.razor │ │ │ │ │ ├── AccountLayout.razor │ │ │ │ │ ├── StatusMessage.razor │ │ │ │ │ ├── ManageNavMenu.razor │ │ │ │ │ └── ExternalLoginPicker.razor │ │ │ │ ├── IdentityUserAccessor.cs │ │ │ │ ├── IdentityNoOpEmailSender.cs │ │ │ │ ├── IdentityRedirectManager.cs │ │ │ │ ├── PersistingServerAuthenticationStateProvider.cs │ │ │ │ └── IdentityComponentsEndpointRouteBuilderExtensions.cs │ │ │ ├── Pages │ │ │ │ ├── Home.razor │ │ │ │ ├── Error.razor │ │ │ │ ├── Event.razor │ │ │ │ └── Events.razor │ │ │ ├── Routes.razor │ │ │ ├── _Imports.razor │ │ │ ├── App.razor │ │ │ └── Layout │ │ │ │ ├── MainLayout.razor │ │ │ │ ├── MainLayout.razor.css │ │ │ │ ├── NavMenu.razor │ │ │ │ └── NavMenu.razor.css │ │ ├── Sentry │ │ │ ├── EnvelopeResponse.cs │ │ │ ├── SectionEntry.cs │ │ │ ├── SdkEntry.cs │ │ │ ├── SessionInfo.cs │ │ │ ├── EnvelopeHandler.cs │ │ │ └── Event.cs │ │ ├── wwwroot │ │ │ ├── favicon.png │ │ │ └── app.css │ │ ├── appsettings.Development.json │ │ ├── appsettings.Sample.Development.json │ │ ├── Properties │ │ │ ├── serviceDependencies.json │ │ │ ├── serviceDependencies.local.json │ │ │ └── launchSettings.json │ │ ├── .config │ │ │ └── dotnet-tools.json │ │ ├── Common │ │ │ └── DateTimeToDateTimeUtc.cs │ │ ├── Data │ │ │ ├── ApplicationUser.cs │ │ │ ├── AppSession.cs │ │ │ ├── ApplicationDbContext.cs │ │ │ └── AppEvent.cs │ │ ├── appsettings.Sample.json │ │ ├── Migrations │ │ │ └── 20240418201243_EventStackTrace.cs │ │ ├── AppStatServer.csproj │ │ └── Program.cs │ └── AppStatServer.Client │ │ ├── wwwroot │ │ ├── appsettings.json │ │ └── appsettings.Development.json │ │ ├── RedirectToLogin.razor │ │ ├── Pages │ │ ├── Auth.razor │ │ └── EventTest.razor │ │ ├── UserInfo.cs │ │ ├── _Imports.razor │ │ ├── Program.cs │ │ ├── AppStatServer.Client.csproj │ │ └── PersistentAuthenticationStateProvider.cs │ ├── ConsoleTestClient │ ├── ConsoleTestClient.csproj │ └── Program.cs │ └── AppStatServer.sln ├── README.md ├── LICENSE └── .gitignore /Docs/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/AppStatServer/main/Docs/screenshot.png -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/AppStat.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/AppStatServer/main/Source/AppStatServer/AppStatServerLite/AppStat.db -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using AppStatServer.Components.Account.Shared 2 | @layout AccountLayout 3 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/EnvelopeResponse.cs: -------------------------------------------------------------------------------- 1 | public class EnvelopeResponse 2 | { 3 | public string Id { get; set; } 4 | } 5 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/AppStat-log.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/AppStatServer/main/Source/AppStatServer/AppStatServerLite/AppStat-log.db -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/_Imports.razor: -------------------------------------------------------------------------------- 1 | @layout ManageLayout 2 | @attribute [Microsoft.AspNetCore.Authorization.Authorize] 3 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/EnvelopeResponse.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Sentry; 2 | 3 | public class EnvelopeResponse 4 | { 5 | public string Id { get; set; } 6 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/wwwroot/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/AppStatServer/main/Source/AppStatServer/AppStatServer/AppStatServer/wwwroot/favicon.png -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/SectionEntry.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Sentry; 2 | 3 | public class SectionEntry 4 | { 5 | public string type { get; set; } 6 | public int length { get; set; } 7 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/InvalidUser.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/InvalidUser" 2 | 3 | Invalid user 4 | 5 |

Invalid user

6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/SectionEntry.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServer.Sentry; 2 | 3 | public class SectionEntry 4 | { 5 | public string type { get; set; } 6 | public int length { get; set; } 7 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/wwwroot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/appsettings.Sample.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/wwwroot/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql.local", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "LiteDbFilePath": "AppStat.db", 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/InvalidPasswordReset.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/InvalidPasswordReset" 2 | 3 | Invalid password reset 4 | 5 |

Invalid password reset

6 |

7 | The password reset link is invalid. 8 |

9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "8.0.4", 7 | "commands": [ 8 | "dotnet-ef" 9 | ], 10 | "rollForward": false 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AppStatServer 2 | Senry sdk compatible dotnet core server to gather app events and crashes 3 | using dotnet 8, entity framework and blazor web 4 | 5 | inspired by glitchtip.com project 6 | 7 | ![screenshot](Docs/screenshot.png "AppStatServer screenshot") 8 | 9 | current status: proof of concept 10 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/AppStatServerLite.http: -------------------------------------------------------------------------------- 1 | @AppStatServerLite_HostAddress = http://localhost:5012 2 | 3 | GET {{AppStatServerLite_HostAddress}}/events/ 4 | Accept: application/json 5 | 6 | ### 7 | 8 | GET {{AppStatServerLite_HostAddress}}/events/1 9 | Accept: application/json 10 | 11 | ### 12 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Common/DateTimeToDateTimeUtc.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 2 | 3 | namespace AppStatServer.Common; 4 | 5 | public class DateTimeToDateTimeUtc() 6 | : ValueConverter(c => DateTime.SpecifyKind(c, DateTimeKind.Utc), c => c); -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/AccessDenied.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/AccessDenied" 2 | 3 | Access denied 4 | 5 |
6 |

Access denied

7 |

You do not have access to this resource.

8 |
9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ForgotPasswordConfirmation.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ForgotPasswordConfirmation" 2 | 3 | Forgot password confirmation 4 | 5 |

Forgot password confirmation

6 |

7 | Please check your email to reset your password. 8 |

9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Lockout.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Lockout" 2 | 3 | Locked out 4 | 5 |
6 |

Locked out

7 |

This account has been locked out, please try again later.

8 |
9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/IEventStorage.cs: -------------------------------------------------------------------------------- 1 | using AppStatServerLite.Data; 2 | using System.Collections.Immutable; 3 | 4 | namespace AppStatServerLite; 5 | 6 | public interface IEventStorage 7 | { 8 | Task SaveEventsAsync(IEnumerable appEvent); 9 | Task> GetRecentEventsAsync(); 10 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/RedirectToLogin.razor: -------------------------------------------------------------------------------- 1 | @inject NavigationManager NavigationManager 2 | 3 | @code { 4 | protected override void OnInitialized() 5 | { 6 | NavigationManager.NavigateTo($"Account/Login?returnUrl={Uri.EscapeDataString(NavigationManager.Uri)}", forceLoad: true); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Data/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace AppStatServer.Data 4 | { 5 | // Add profile data for application users by adding properties to the ApplicationUser class 6 | public class ApplicationUser : IdentityUser 7 | { 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ResetPasswordConfirmation.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ResetPasswordConfirmation" 2 | Reset password confirmation 3 | 4 |

Reset password confirmation

5 |

6 | Your password has been reset. Please click here to log in. 7 |

8 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/Pages/Auth.razor: -------------------------------------------------------------------------------- 1 | @page "/auth" 2 | 3 | @using Microsoft.AspNetCore.Authorization 4 | 5 | @attribute [Authorize] 6 | @rendermode InteractiveWebAssembly 7 | 8 | Auth 9 | 10 |

You are authenticated

11 | 12 | 13 | Hello @context.User.Identity?.Name! 14 | 15 | -------------------------------------------------------------------------------- /Source/AppStatServer/ConsoleTestClient/ConsoleTestClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/UserInfo.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServer.Client 2 | { 3 | // Add properties to this class and update the server and client AuthenticationStateProviders 4 | // to expose more information about the authenticated user to the client. 5 | public class UserInfo 6 | { 7 | public required string UserId { get; set; } 8 | public required string Email { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Data/AppSession.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServer.Data; 2 | 3 | public class AppSession 4 | { 5 | public string Id { get; set; } 6 | public DateTime Started { get; set; } 7 | public DateTime Timestamp { get; set; } 8 | public int Duration { get; set; } 9 | public int Errors { get; set; } 10 | public string Release { get; set; } 11 | public string Environment { get; set; } 12 | public string Os { get; set; } 13 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/ManageLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | @layout AccountLayout 3 | 4 |

Manage your account

5 | 6 |
7 |

Change your account settings

8 |
9 |
10 |
11 | 12 |
13 |
14 | @Body 15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "http": { 5 | "commandName": "Project", 6 | "dotnetRunMessages": true, 7 | "launchBrowser": true, 8 | "launchUrl": "events", 9 | "applicationUrl": "http://localhost:5012", 10 | "environmentVariables": { 11 | "ASPNETCORE_ENVIRONMENT": "Development" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Pages/Home.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @inject NavigationManager NavigationManager 3 | 4 | Home 5 | 6 |

How to connect sdk

7 | 8 |
9 | 10 | SentrySdk.Init(o => o.Dsn = "@url"); 11 | 12 |
13 | 14 | @code 15 | { 16 | string url => $"{NavigationManager.BaseUri}1".Replace("://", "://5e79a97ae19d4187becbc9e4cdf2de52@"); 17 | } 18 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using static Microsoft.AspNetCore.Components.Web.RenderMode 8 | @using Microsoft.AspNetCore.Components.Web.Virtualization 9 | @using Microsoft.JSInterop 10 | @using AppStatServer.Client 11 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/Program.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Client; 2 | using Microsoft.AspNetCore.Components.Authorization; 3 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 4 | 5 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 6 | 7 | builder.Services.AddAuthorizationCore(); 8 | builder.Services.AddCascadingAuthenticationState(); 9 | builder.Services.AddSingleton(); 10 | 11 | await builder.Build().RunAsync(); 12 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Routes.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using static Microsoft.AspNetCore.Components.Web.RenderMode 8 | @using Microsoft.AspNetCore.Components.Web.Virtualization 9 | @using Microsoft.JSInterop 10 | @using AppStatServer 11 | @using AppStatServer.Client 12 | @using AppStatServer.Components 13 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/SdkEntry.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Sentry; 2 | 3 | public class Sdk 4 | { 5 | public string name { get; set; } 6 | public string version { get; set; } 7 | } 8 | public class Trace 9 | { 10 | public string trace_id { get; set; } 11 | public string public_key { get; set; } 12 | public string release { get; set; } 13 | public string environment { get; set; } 14 | } 15 | 16 | public class SdkEntry 17 | { 18 | public Sdk sdk { get; set; } 19 | public string event_id { get; set; } 20 | public Trace trace { get; set; } 21 | public DateTime sent_at { get; set; } 22 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/SessionInfo.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Sentry; 2 | 3 | public class Attrs 4 | { 5 | public string release { get; set; } 6 | public string environment { get; set; } 7 | } 8 | 9 | public class SessionEntry 10 | { 11 | public string sid { get; set; } 12 | public string did { get; set; } 13 | public bool init { get; set; } 14 | public DateTime started { get; set; } 15 | public DateTime timestamp { get; set; } 16 | public int seq { get; set; } 17 | public int duration { get; set; } 18 | public int errors { get; set; } 19 | public Attrs attrs { get; set; } 20 | } 21 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/SdkEntry.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServer.Sentry; 2 | 3 | public class Sdk 4 | { 5 | public string name { get; set; } 6 | public string version { get; set; } 7 | } 8 | public class Trace 9 | { 10 | public string trace_id { get; set; } 11 | public string public_key { get; set; } 12 | public string release { get; set; } 13 | public string environment { get; set; } 14 | } 15 | 16 | public class SdkEntry 17 | { 18 | public Sdk sdk { get; set; } 19 | public string event_id { get; set; } 20 | public Trace trace { get; set; } 21 | public DateTime sent_at { get; set; } 22 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/SessionInfo.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServer.Sentry; 2 | 3 | public class Attrs 4 | { 5 | public string release { get; set; } 6 | public string environment { get; set; } 7 | } 8 | 9 | public class SessionEntry 10 | { 11 | public string sid { get; set; } 12 | public string did { get; set; } 13 | public bool init { get; set; } 14 | public DateTime started { get; set; } 15 | public DateTime timestamp { get; set; } 16 | public int seq { get; set; } 17 | public int duration { get; set; } 18 | public int errors { get; set; } 19 | public Attrs attrs { get; set; } 20 | } 21 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Layout/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 | 7 | 8 |
9 |
10 | About 11 |
12 | 13 |
14 | @Body 15 |
16 |
17 |
18 | 19 |
20 | An unhandled error has occurred. 21 | Reload 22 | 🗙 23 |
24 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/appsettings.Sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "PostgresConnection": "Host=localhost;Port=5432;Database=appstat;Username=appstat;Password=1q2w3e", 4 | "MsSqlConnection": "Server=(localdb)\\mssqllocaldb;Database=appstat;Trusted_Connection=True;", 5 | "SqliteConnection": "Data Source=appstat.db", 6 | "MySqlConnection": "server=localhost;port=3306;database=appstat;user=appstat;password=1q2w3e" 7 | }, 8 | "UseConnection": "MySqlConnection", 9 | "Logging": { 10 | "LogLevel": { 11 | "Default": "Information", 12 | "Microsoft.AspNetCore": "Warning" 13 | } 14 | }, 15 | "AllowedHosts": "*" 16 | } 17 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Data/AppEvent.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Data; 2 | 3 | public class AppEvent 4 | { 5 | public string Id { get; set; } 6 | public DateTime Timestamp { get; set; } 7 | 8 | public string? EventEntry { get; set; } 9 | public string Release { get; set; } 10 | 11 | public bool IsCrash { get; set; } 12 | public bool IsError { get; set; } 13 | 14 | public string Message { get; set; } 15 | public string SessionId { get; set; } 16 | 17 | public string Level { get; set; } 18 | 19 | public string? SpanId { get; set; } 20 | public string? TraceId { get; set; } 21 | public string? Os { get; set; } 22 | public string UserId { get; set; } 23 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Common; 2 | using AppStatServer.Sentry; 3 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore; 5 | 6 | namespace AppStatServer.Data; 7 | 8 | 9 | public class ApplicationDbContext(DbContextOptions options) : IdentityDbContext(options) 10 | { 11 | public DbSet Events { get; set; } = null!; 12 | protected sealed override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) 13 | { 14 | configurationBuilder.Properties() 15 | .HaveConversion(typeof(DateTimeToDateTimeUtc)); 16 | } 17 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/AppStatServerLite.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | true 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/AppStatServer.Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | true 8 | Default 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Data/AppEvent.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Sentry; 2 | 3 | namespace AppStatServer.Data; 4 | 5 | public class AppEvent 6 | { 7 | public string Id { get; set; } 8 | public DateTime Timestamp { get; set; } 9 | 10 | public string? EventEntry { get; set; } 11 | public string Release { get; set; } 12 | 13 | public bool IsCrash { get; set; } 14 | public bool IsError { get; set; } 15 | 16 | public string Message { get; set; } 17 | public string SessionId { get; set; } 18 | 19 | public string Level { get; set; } 20 | 21 | public string? SpanId { get; set; } 22 | public string? TraceId { get; set; } 23 | public string? Os { get; set; } 24 | public string UserId { get; set; } 25 | public string? StackTrace { get; set; } 26 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/IdentityUserAccessor.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Data; 2 | using Microsoft.AspNetCore.Identity; 3 | 4 | namespace AppStatServer.Components.Account 5 | { 6 | internal sealed class IdentityUserAccessor(UserManager userManager, IdentityRedirectManager redirectManager) 7 | { 8 | public async Task GetRequiredUserAsync(HttpContext context) 9 | { 10 | var user = await userManager.GetUserAsync(context.User); 11 | 12 | if (user is null) 13 | { 14 | redirectManager.RedirectToWithStatus("Account/InvalidUser", $"Error: Unable to load user with ID '{userManager.GetUserId(context.User)}'.", context); 15 | } 16 | 17 | return user; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/ShowRecoveryCodes.razor: -------------------------------------------------------------------------------- 1 | 2 |

Recovery codes

3 | 11 |
12 |
13 | @foreach (var recoveryCode in RecoveryCodes) 14 | { 15 |
16 | @recoveryCode 17 |
18 | } 19 |
20 |
21 | 22 | @code { 23 | [Parameter] 24 | public string[] RecoveryCodes { get; set; } = []; 25 | 26 | [Parameter] 27 | public string? StatusMessage { get; set; } 28 | } 29 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Program.cs: -------------------------------------------------------------------------------- 1 | using AppStatServerLite; 2 | using AppStatServerLite.Sentry; 3 | 4 | var builder = WebApplication.CreateSlimBuilder(args); 5 | 6 | var dbFileName = builder.Configuration["LiteDbFilePath"]; 7 | builder.Services.AddSingleton(services => new LiteDbEventStorage(dbFileName)); 8 | 9 | //builder.Services.ConfigureHttpJsonOptions(options => 10 | //{ 11 | // options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); 12 | //}); 13 | 14 | var app = builder.Build(); 15 | 16 | var todosApi = app.MapGroup("/events"); 17 | todosApi.MapGet("/", (IEventStorage es) => es.GetRecentEventsAsync()); 18 | todosApi.MapGet("/{id}", async (string id, IEventStorage es) => 19 | (await es.GetRecentEventsAsync()).FirstOrDefault(a => a.Id == id) is { } todo 20 | ? Results.Ok(todo) 21 | : Results.NotFound()); 22 | 23 | _ = new EnvelopeHandler(app); 24 | 25 | app.Run(); -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/AccountLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | @layout AppStatServer.Components.Layout.MainLayout 3 | @inject NavigationManager NavigationManager 4 | 5 | @if (HttpContext is null) 6 | { 7 |

Loading...

8 | } 9 | else 10 | { 11 | @Body 12 | } 13 | 14 | @code { 15 | [CascadingParameter] 16 | private HttpContext? HttpContext { get; set; } 17 | 18 | protected override void OnParametersSet() 19 | { 20 | if (HttpContext is null) 21 | { 22 | // If this code runs, we're currently rendering in interactive mode, so there is no HttpContext. 23 | // The identity pages need to set cookies, so they require an HttpContext. To achieve this we 24 | // must transition back from interactive mode to a server-rendered page. 25 | NavigationManager.Refresh(forceReload: true); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Migrations/20240418201243_EventStackTrace.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace AppStatServer.Migrations 6 | { 7 | /// 8 | public partial class EventStackTrace : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.AddColumn( 14 | name: "StackTrace", 15 | table: "Events", 16 | type: "longtext", 17 | nullable: true) 18 | .Annotation("MySql:CharSet", "utf8mb4"); 19 | } 20 | 21 | /// 22 | protected override void Down(MigrationBuilder migrationBuilder) 23 | { 24 | migrationBuilder.DropColumn( 25 | name: "StackTrace", 26 | table: "Events"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/StatusMessage.razor: -------------------------------------------------------------------------------- 1 | @if (!string.IsNullOrEmpty(DisplayMessage)) 2 | { 3 | var statusMessageClass = DisplayMessage.StartsWith("Error") ? "danger" : "success"; 4 | 7 | } 8 | 9 | @code { 10 | private string? messageFromCookie; 11 | 12 | [Parameter] 13 | public string? Message { get; set; } 14 | 15 | [CascadingParameter] 16 | private HttpContext HttpContext { get; set; } = default!; 17 | 18 | private string? DisplayMessage => Message ?? messageFromCookie; 19 | 20 | protected override void OnInitialized() 21 | { 22 | messageFromCookie = HttpContext.Request.Cookies[IdentityRedirectManager.StatusCookieName]; 23 | 24 | if (messageFromCookie is not null) 25 | { 26 | HttpContext.Response.Cookies.Delete(IdentityRedirectManager.StatusCookieName); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/LiteDbEventStorage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Immutable; 2 | using AppStatServerLite.Data; 3 | using LiteDB; 4 | 5 | namespace AppStatServerLite; 6 | 7 | public class LiteDbEventStorage : IEventStorage, IDisposable 8 | { 9 | private readonly string? _dbFileName; 10 | private readonly LiteDatabase _db; 11 | 12 | public LiteDbEventStorage(string? dbFileName = "AppStat.db") 13 | { 14 | _dbFileName = dbFileName; 15 | _db = new LiteDatabase(_dbFileName); 16 | } 17 | 18 | public Task SaveEventsAsync(IEnumerable appEvents) 19 | { 20 | var col = _db.GetCollection("events"); 21 | col.Insert(appEvents); 22 | return Task.CompletedTask; 23 | } 24 | 25 | public Task> GetRecentEventsAsync() 26 | { 27 | var col = _db.GetCollection("events"); 28 | var result = col.Find(x => true, 0, 100); 29 | return Task.FromResult(result.ToImmutableList()); 30 | } 31 | 32 | public void Dispose() => _db.Dispose(); 33 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Igor Gritsenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/PersonalData.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/PersonalData" 2 | 3 | @inject IdentityUserAccessor UserAccessor 4 | 5 | Personal Data 6 | 7 | 8 |

Personal Data

9 | 10 |
11 |
12 |

Your account contains personal data that you have given us. This page allows you to download or delete that data.

13 |

14 | Deleting this data will permanently remove your account, and this cannot be recovered. 15 |

16 |
17 | 18 | 19 | 20 |

21 | Delete 22 |

23 |
24 |
25 | 26 | @code { 27 | [CascadingParameter] 28 | private HttpContext HttpContext { get; set; } = default!; 29 | 30 | protected override async Task OnInitializedAsync() 31 | { 32 | _ = await UserAccessor.GetRequiredUserAsync(HttpContext); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/AppStatServer/ConsoleTestClient/Program.cs: -------------------------------------------------------------------------------- 1 | Console.WriteLine("Test sentry"); 2 | 3 | Task.Run(async () => 4 | { 5 | using (SentrySdk.Init(o => 6 | { 7 | o.Dsn = "http://5e79a97ae19d4187becbc9e4cdf2de52@localhost:5012/1"; 8 | o.SendClientReports = false; 9 | o.AutoSessionTracking = true; 10 | o.StackTraceMode = StackTraceMode.Enhanced; 11 | o.IsGlobalModeEnabled = true; 12 | //o.Debug = true; 13 | o.ReportAssembliesMode = ReportAssembliesMode.None; 14 | //o.RequestBodyCompressionLevel = System.IO.Compression.CompressionLevel.NoCompression; 15 | })) 16 | { 17 | SentrySdk.ConfigureScope(s => s.User.Id = Guid.NewGuid().ToString()); 18 | 19 | var rnd = new Random(); 20 | await Parallel.ForAsync(0, 1, async (j, ct) => 21 | { 22 | for (int i = 0; i < 10000; i++) 23 | { 24 | var msg = "Console test error"; 25 | SentrySdk.CaptureException(new Exception(msg)); 26 | Console.WriteLine(msg); 27 | await Task.Delay(rnd.Next(1,2)); 28 | } 29 | }); 30 | 31 | Console.WriteLine("Finished"); 32 | } 33 | }); 34 | 35 | Console.ReadLine(); -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/IdentityNoOpEmailSender.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Data; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.AspNetCore.Identity.UI.Services; 4 | 5 | namespace AppStatServer.Components.Account 6 | { 7 | // Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation. 8 | internal sealed class IdentityNoOpEmailSender : IEmailSender 9 | { 10 | private readonly IEmailSender emailSender = new NoOpEmailSender(); 11 | 12 | public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink) => 13 | emailSender.SendEmailAsync(email, "Confirm your email", $"Please confirm your account by clicking here."); 14 | 15 | public Task SendPasswordResetLinkAsync(ApplicationUser user, string email, string resetLink) => 16 | emailSender.SendEmailAsync(email, "Reset your password", $"Please reset your password by clicking here."); 17 | 18 | public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode) => 19 | emailSender.SendEmailAsync(email, "Reset your password", $"Please reset your password using the following code: {resetCode}"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Pages/Error.razor: -------------------------------------------------------------------------------- 1 | @page "/Error" 2 | @using System.Diagnostics 3 | 4 | Error 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (ShowRequestId) 10 | { 11 |

12 | Request ID: @RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | 27 | @code{ 28 | [CascadingParameter] 29 | private HttpContext? HttpContext { get; set; } 30 | 31 | private string? RequestId { get; set; } 32 | private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 33 | 34 | protected override void OnInitialized() => 35 | RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; 36 | } 37 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/ManageNavMenu.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @using AppStatServer.Data 3 | 4 | @inject SignInManager SignInManager 5 | 6 | 29 | 30 | @code { 31 | private bool hasExternalLogins; 32 | 33 | protected override async Task OnInitializedAsync() 34 | { 35 | hasExternalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).Any(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/AppStatServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | aspnet-AppStatServer-f04e0f25-46ac-4859-a3bc-aced914eb618 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | all 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5411", 8 | "sslPort": 44348 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 17 | "applicationUrl": "http://localhost:5218", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 27 | "applicationUrl": "https://localhost:7019;http://localhost:5218", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ConfirmEmail.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ConfirmEmail" 2 | 3 | @using System.Text 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.WebUtilities 6 | @using AppStatServer.Data 7 | 8 | @inject UserManager UserManager 9 | @inject IdentityRedirectManager RedirectManager 10 | 11 | Confirm email 12 | 13 |

Confirm email

14 | 15 | 16 | @code { 17 | private string? statusMessage; 18 | 19 | [CascadingParameter] 20 | private HttpContext HttpContext { get; set; } = default!; 21 | 22 | [SupplyParameterFromQuery] 23 | private string? UserId { get; set; } 24 | 25 | [SupplyParameterFromQuery] 26 | private string? Code { get; set; } 27 | 28 | protected override async Task OnInitializedAsync() 29 | { 30 | if (UserId is null || Code is null) 31 | { 32 | RedirectManager.RedirectTo(""); 33 | } 34 | 35 | var user = await UserManager.FindByIdAsync(UserId); 36 | if (user is null) 37 | { 38 | HttpContext.Response.StatusCode = StatusCodes.Status404NotFound; 39 | statusMessage = $"Error loading user with ID {UserId}"; 40 | } 41 | else 42 | { 43 | var code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(Code)); 44 | var result = await UserManager.ConfirmEmailAsync(user, code); 45 | statusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email."; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Shared/ExternalLoginPicker.razor: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Authentication 2 | @using Microsoft.AspNetCore.Identity 3 | @using AppStatServer.Data 4 | 5 | @inject SignInManager SignInManager 6 | @inject IdentityRedirectManager RedirectManager 7 | 8 | @if (externalLogins.Length == 0) 9 | { 10 |
11 |

12 | There are no external authentication services configured. See this article 13 | about setting up this ASP.NET application to support logging in via external services. 14 |

15 |
16 | } 17 | else 18 | { 19 |
20 |
21 | 22 | 23 |

24 | @foreach (var provider in externalLogins) 25 | { 26 | 27 | } 28 |

29 |
30 |
31 | } 32 | 33 | @code { 34 | private AuthenticationScheme[] externalLogins = []; 35 | 36 | [SupplyParameterFromQuery] 37 | private string? ReturnUrl { get; set; } 38 | 39 | protected override async Task OnInitializedAsync() 40 | { 41 | externalLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToArray(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/Pages/EventTest.razor: -------------------------------------------------------------------------------- 1 | @page "/eventSend" 2 | @using System.Diagnostics 3 | @using System.Net.Http.Headers 4 | @rendermode InteractiveWebAssembly 5 | 6 | Test sentry backend 7 | 8 |

Send events

9 | 10 |

Events sent: @currentCount

11 | 12 | 13 | 14 | @Message 15 | 16 | @code { 17 | private int currentCount = 0; 18 | private string Message { get; set; } = ""; 19 | 20 | private async Task TestSentry() 21 | { 22 | using (SentrySdk.Init(o => 23 | { 24 | o.Dsn = "https://5e79a97ae19d4187becbc9e4cdf2de52@localhost:7019/1"; 25 | o.SendClientReports = false; 26 | o.AutoSessionTracking = true; 27 | o.StackTraceMode = StackTraceMode.Enhanced; 28 | o.IsGlobalModeEnabled = true; 29 | o.ReportAssembliesMode = ReportAssembliesMode.None; 30 | //o.Debug = true; 31 | //o.RequestBodyCompressionLevel = System.IO.Compression.CompressionLevel.NoCompression; 32 | })) 33 | { 34 | SentrySdk.ConfigureScope(s => s.User.Id = Guid.NewGuid().ToString()); 35 | 36 | Message = $"Sending events..."; 37 | StateHasChanged(); 38 | var rnd = new Random(); 39 | 40 | for (int i = 0; i < 50; i++) 41 | { 42 | currentCount = i; 43 | StateHasChanged(); 44 | var msg = $"Web Assembly test error"; 45 | SentrySdk.CaptureException(new Exception(msg)); 46 | await Task.Delay(rnd.Next(10, 40)); 47 | } 48 | 49 | Message = $"Finished sending {currentCount} events"; 50 | StateHasChanged(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Pages/Event.razor: -------------------------------------------------------------------------------- 1 | @page "/event" 2 | @using AppStatServer.Data 3 | @using Humanizer 4 | @using Microsoft.EntityFrameworkCore 5 | @attribute [StreamRendering] 6 | 7 | Events 8 | 9 |

Events

10 | 11 | @if (_events == null) 12 | { 13 |

Loading...

14 | } 15 | else 16 | { 17 |

@Title

18 |

@EventType

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | @foreach (var ev in _events.OrderByDescending(x => x.Timestamp)) 30 | { 31 | 32 | 33 | 34 | 35 | 36 | 37 | } 38 | 39 |
osversionlast occuredStack trace
@ev.Os@ev.Release@ev.Timestamp.Humanize(false)@ev.StackTrace
40 | } 41 | 42 | @code { 43 | [Inject] ApplicationDbContext DbContext { get; set; } = null!; 44 | 45 | [Parameter, SupplyParameterFromQuery] 46 | public string EventName { get; set; } 47 | 48 | private List? _events = new(); 49 | 50 | public string? Title { get; set; } = "Message"; 51 | public string? EventType { get; set; } = "Info"; 52 | 53 | 54 | protected override async Task OnInitializedAsync() 55 | { 56 | _events = await DbContext.Events 57 | .Where(x => x.Message == EventName) 58 | .ToListAsync(); 59 | 60 | var firstEvent = _events.FirstOrDefault(); 61 | 62 | if (firstEvent != null) 63 | { 64 | Title = firstEvent.Message; 65 | EventType = firstEvent.Level; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Pages/Events.razor: -------------------------------------------------------------------------------- 1 | @page "/events" 2 | @using System.Web 3 | @using AppStatServer.Data 4 | @using Humanizer 5 | @using Microsoft.EntityFrameworkCore 6 | @attribute [StreamRendering] 7 | 8 | Events 9 | 10 |

Events

11 | 12 | @if (_events == null) 13 | { 14 |

Loading...

15 | } 16 | else 17 | { 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | @foreach (var ev in _events.OrderByDescending(x=>x.lastOccured)) 31 | { 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | } 41 | 42 |
nameosversioncountlevellast occured
@ev.Name @ev.os@ev.ver@ev.count@ev.level@ev.lastOccured.Humanize(false)
43 | } 44 | 45 | @code { 46 | [Inject] ApplicationDbContext DbContext { get; set; } = null!; 47 | 48 | private readonly List? _events = new(); 49 | 50 | protected override async Task OnInitializedAsync() 51 | { 52 | var groups = await DbContext.Events 53 | .GroupBy(x => new { x.Message, x.Os, x.Release, x.Level }) 54 | .ToListAsync(); 55 | 56 | 57 | foreach (var group in groups) 58 | { 59 | var lastOccured = group.Max(x => x.Timestamp); 60 | 61 | _events.Add(new EventGroup( 62 | group.Key.Message, 63 | group.Count(), 64 | group.Key.Release, 65 | group.Key.Os ?? "", 66 | group.Key.Level, 67 | lastOccured 68 | )); 69 | } 70 | } 71 | 72 | private record EventGroup(string Name, int count, string ver, string os, string level, DateTime lastOccured); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/ResetAuthenticator.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/ResetAuthenticator" 2 | 3 | @using Microsoft.AspNetCore.Identity 4 | @using AppStatServer.Data 5 | 6 | @inject UserManager UserManager 7 | @inject SignInManager SignInManager 8 | @inject IdentityUserAccessor UserAccessor 9 | @inject IdentityRedirectManager RedirectManager 10 | @inject ILogger Logger 11 | 12 | Reset authenticator key 13 | 14 | 15 |

Reset authenticator key

16 | 26 |
27 |
28 | 29 | 30 | 31 |
32 | 33 | @code { 34 | [CascadingParameter] 35 | private HttpContext HttpContext { get; set; } = default!; 36 | 37 | private async Task OnSubmitAsync() 38 | { 39 | var user = await UserAccessor.GetRequiredUserAsync(HttpContext); 40 | await UserManager.SetTwoFactorEnabledAsync(user, false); 41 | await UserManager.ResetAuthenticatorKeyAsync(user); 42 | var userId = await UserManager.GetUserIdAsync(user); 43 | Logger.LogInformation("User with ID '{UserId}' has reset their authentication app key.", userId); 44 | 45 | await SignInManager.RefreshSignInAsync(user); 46 | 47 | RedirectManager.RedirectToWithStatus( 48 | "Account/Manage/EnableAuthenticator", 49 | "Your authenticator app key has been reset, you will need to configure your authenticator app using the new key.", 50 | HttpContext); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer.Client/PersistentAuthenticationStateProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.AspNetCore.Components.Authorization; 3 | using System.Security.Claims; 4 | 5 | namespace AppStatServer.Client 6 | { 7 | // This is a client-side AuthenticationStateProvider that determines the user's authentication state by 8 | // looking for data persisted in the page when it was rendered on the server. This authentication state will 9 | // be fixed for the lifetime of the WebAssembly application. So, if the user needs to log in or out, a full 10 | // page reload is required. 11 | // 12 | // This only provides a user name and email for display purposes. It does not actually include any tokens 13 | // that authenticate to the server when making subsequent requests. That works separately using a 14 | // cookie that will be included on HttpClient requests to the server. 15 | internal class PersistentAuthenticationStateProvider : AuthenticationStateProvider 16 | { 17 | private static readonly Task defaultUnauthenticatedTask = 18 | Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()))); 19 | 20 | private readonly Task authenticationStateTask = defaultUnauthenticatedTask; 21 | 22 | public PersistentAuthenticationStateProvider(PersistentComponentState state) 23 | { 24 | if (!state.TryTakeFromJson(nameof(UserInfo), out var userInfo) || userInfo is null) 25 | { 26 | return; 27 | } 28 | 29 | Claim[] claims = [ 30 | new Claim(ClaimTypes.NameIdentifier, userInfo.UserId), 31 | new Claim(ClaimTypes.Name, userInfo.Email), 32 | new Claim(ClaimTypes.Email, userInfo.Email) ]; 33 | 34 | authenticationStateTask = Task.FromResult( 35 | new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(claims, 36 | authenticationType: nameof(PersistentAuthenticationStateProvider))))); 37 | } 38 | 39 | public override Task GetAuthenticationStateAsync() => authenticationStateTask; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Layout/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row ::deep .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | text-decoration: none; 28 | } 29 | 30 | .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { 31 | text-decoration: underline; 32 | } 33 | 34 | .top-row ::deep a:first-child { 35 | overflow: hidden; 36 | text-overflow: ellipsis; 37 | } 38 | 39 | @media (max-width: 640.98px) { 40 | .top-row { 41 | justify-content: space-between; 42 | } 43 | 44 | .top-row ::deep a, .top-row ::deep .btn-link { 45 | margin-left: 0; 46 | } 47 | } 48 | 49 | @media (min-width: 641px) { 50 | .page { 51 | flex-direction: row; 52 | } 53 | 54 | .sidebar { 55 | width: 250px; 56 | height: 100vh; 57 | position: sticky; 58 | top: 0; 59 | } 60 | 61 | .top-row { 62 | position: sticky; 63 | top: 0; 64 | z-index: 1; 65 | } 66 | 67 | .top-row.auth ::deep a:first-child { 68 | flex: 1; 69 | text-align: right; 70 | width: 0; 71 | } 72 | 73 | .top-row, article { 74 | padding-left: 2rem !important; 75 | padding-right: 1.5rem !important; 76 | } 77 | } 78 | 79 | #blazor-error-ui { 80 | background: lightyellow; 81 | bottom: 0; 82 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 83 | display: none; 84 | left: 0; 85 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 86 | position: fixed; 87 | width: 100%; 88 | z-index: 1000; 89 | } 90 | 91 | #blazor-error-ui .dismiss { 92 | cursor: pointer; 93 | position: absolute; 94 | right: 0.75rem; 95 | top: 0.5rem; 96 | } 97 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ConfirmEmailChange.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ConfirmEmailChange" 2 | 3 | @using System.Text 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.WebUtilities 6 | @using AppStatServer.Data 7 | 8 | @inject UserManager UserManager 9 | @inject SignInManager SignInManager 10 | @inject IdentityRedirectManager RedirectManager 11 | 12 | Confirm email change 13 | 14 |

Confirm email change

15 | 16 | 17 | 18 | @code { 19 | private string? message; 20 | 21 | [CascadingParameter] 22 | private HttpContext HttpContext { get; set; } = default!; 23 | 24 | [SupplyParameterFromQuery] 25 | private string? UserId { get; set; } 26 | 27 | [SupplyParameterFromQuery] 28 | private string? Email { get; set; } 29 | 30 | [SupplyParameterFromQuery] 31 | private string? Code { get; set; } 32 | 33 | protected override async Task OnInitializedAsync() 34 | { 35 | if (UserId is null || Email is null || Code is null) 36 | { 37 | RedirectManager.RedirectToWithStatus( 38 | "Account/Login", "Error: Invalid email change confirmation link.", HttpContext); 39 | } 40 | 41 | var user = await UserManager.FindByIdAsync(UserId); 42 | if (user is null) 43 | { 44 | message = "Unable to find user with Id '{userId}'"; 45 | return; 46 | } 47 | 48 | var code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(Code)); 49 | var result = await UserManager.ChangeEmailAsync(user, Email, code); 50 | if (!result.Succeeded) 51 | { 52 | message = "Error changing email."; 53 | return; 54 | } 55 | 56 | // In our UI email and user name are one and the same, so when we update the email 57 | // we need to update the user name. 58 | var setUserNameResult = await UserManager.SetUserNameAsync(user, Email); 59 | if (!setUserNameResult.Succeeded) 60 | { 61 | message = "Error changing user name."; 62 | return; 63 | } 64 | 65 | await SignInManager.RefreshSignInAsync(user); 66 | message = "Thank you for confirming your email change."; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/Disable2fa.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/Disable2fa" 2 | 3 | @using Microsoft.AspNetCore.Identity 4 | @using AppStatServer.Data 5 | 6 | @inject UserManager UserManager 7 | @inject IdentityUserAccessor UserAccessor 8 | @inject IdentityRedirectManager RedirectManager 9 | @inject ILogger Logger 10 | 11 | Disable two-factor authentication (2FA) 12 | 13 | 14 |

Disable two-factor authentication (2FA)

15 | 16 | 25 | 26 |
27 |
28 | 29 | 30 | 31 |
32 | 33 | @code { 34 | private ApplicationUser user = default!; 35 | 36 | [CascadingParameter] 37 | private HttpContext HttpContext { get; set; } = default!; 38 | 39 | protected override async Task OnInitializedAsync() 40 | { 41 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 42 | 43 | if (HttpMethods.IsGet(HttpContext.Request.Method) && !await UserManager.GetTwoFactorEnabledAsync(user)) 44 | { 45 | throw new InvalidOperationException("Cannot disable 2FA for user as it's not currently enabled."); 46 | } 47 | } 48 | 49 | private async Task OnSubmitAsync() 50 | { 51 | var disable2faResult = await UserManager.SetTwoFactorEnabledAsync(user, false); 52 | if (!disable2faResult.Succeeded) 53 | { 54 | throw new InvalidOperationException("Unexpected error occurred disabling 2FA."); 55 | } 56 | 57 | var userId = await UserManager.GetUserIdAsync(user); 58 | Logger.LogInformation("User with ID '{UserId}' has disabled 2fa.", userId); 59 | RedirectManager.RedirectToWithStatus( 60 | "Account/Manage/TwoFactorAuthentication", 61 | "2fa has been disabled. You can reenable 2fa when you setup an authenticator app", 62 | HttpContext); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/IdentityRedirectManager.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using System.Diagnostics.CodeAnalysis; 3 | 4 | namespace AppStatServer.Components.Account 5 | { 6 | internal sealed class IdentityRedirectManager(NavigationManager navigationManager) 7 | { 8 | public const string StatusCookieName = "Identity.StatusMessage"; 9 | 10 | private static readonly CookieBuilder StatusCookieBuilder = new() 11 | { 12 | SameSite = SameSiteMode.Strict, 13 | HttpOnly = true, 14 | IsEssential = true, 15 | MaxAge = TimeSpan.FromSeconds(5), 16 | }; 17 | 18 | [DoesNotReturn] 19 | public void RedirectTo(string? uri) 20 | { 21 | uri ??= ""; 22 | 23 | // Prevent open redirects. 24 | if (!Uri.IsWellFormedUriString(uri, UriKind.Relative)) 25 | { 26 | uri = navigationManager.ToBaseRelativePath(uri); 27 | } 28 | 29 | // During static rendering, NavigateTo throws a NavigationException which is handled by the framework as a redirect. 30 | // So as long as this is called from a statically rendered Identity component, the InvalidOperationException is never thrown. 31 | navigationManager.NavigateTo(uri); 32 | throw new InvalidOperationException($"{nameof(IdentityRedirectManager)} can only be used during static rendering."); 33 | } 34 | 35 | [DoesNotReturn] 36 | public void RedirectTo(string uri, Dictionary queryParameters) 37 | { 38 | var uriWithoutQuery = navigationManager.ToAbsoluteUri(uri).GetLeftPart(UriPartial.Path); 39 | var newUri = navigationManager.GetUriWithQueryParameters(uriWithoutQuery, queryParameters); 40 | RedirectTo(newUri); 41 | } 42 | 43 | [DoesNotReturn] 44 | public void RedirectToWithStatus(string uri, string message, HttpContext context) 45 | { 46 | context.Response.Cookies.Append(StatusCookieName, message, StatusCookieBuilder.Build(context)); 47 | RedirectTo(uri); 48 | } 49 | 50 | private string CurrentPath => navigationManager.ToAbsoluteUri(navigationManager.Uri).GetLeftPart(UriPartial.Path); 51 | 52 | [DoesNotReturn] 53 | public void RedirectToCurrentPage() => RedirectTo(CurrentPath); 54 | 55 | [DoesNotReturn] 56 | public void RedirectToCurrentPageWithStatus(string message, HttpContext context) 57 | => RedirectToWithStatus(CurrentPath, message, context); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/RegisterConfirmation.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/RegisterConfirmation" 2 | 3 | @using System.Text 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.WebUtilities 6 | @using AppStatServer.Data 7 | 8 | @inject UserManager UserManager 9 | @inject IEmailSender EmailSender 10 | @inject NavigationManager NavigationManager 11 | @inject IdentityRedirectManager RedirectManager 12 | 13 | Register confirmation 14 | 15 |

Register confirmation

16 | 17 | 18 | 19 | @if (emailConfirmationLink is not null) 20 | { 21 |

22 | This app does not currently have a real email sender registered, see these docs for how to configure a real email sender. 23 | Normally this would be emailed: Click here to confirm your account 24 |

25 | } 26 | else 27 | { 28 |

Please check your email to confirm your account.

29 | } 30 | 31 | @code { 32 | private string? emailConfirmationLink; 33 | private string? statusMessage; 34 | 35 | [CascadingParameter] 36 | private HttpContext HttpContext { get; set; } = default!; 37 | 38 | [SupplyParameterFromQuery] 39 | private string? Email { get; set; } 40 | 41 | [SupplyParameterFromQuery] 42 | private string? ReturnUrl { get; set; } 43 | 44 | protected override async Task OnInitializedAsync() 45 | { 46 | if (Email is null) 47 | { 48 | RedirectManager.RedirectTo(""); 49 | } 50 | 51 | var user = await UserManager.FindByEmailAsync(Email); 52 | if (user is null) 53 | { 54 | HttpContext.Response.StatusCode = StatusCodes.Status404NotFound; 55 | statusMessage = "Error finding user for unspecified email"; 56 | } 57 | else if (EmailSender is IdentityNoOpEmailSender) 58 | { 59 | // Once you add a real email sender, you should remove this code that lets you confirm the account 60 | var userId = await UserManager.GetUserIdAsync(user); 61 | var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); 62 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 63 | emailConfirmationLink = NavigationManager.GetUriWithQueryParameters( 64 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, 65 | new Dictionary { ["userId"] = userId, ["code"] = code, ["returnUrl"] = ReturnUrl }); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/GenerateRecoveryCodes.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/GenerateRecoveryCodes" 2 | 3 | @using Microsoft.AspNetCore.Identity 4 | @using AppStatServer.Data 5 | 6 | @inject UserManager UserManager 7 | @inject IdentityUserAccessor UserAccessor 8 | @inject IdentityRedirectManager RedirectManager 9 | @inject ILogger Logger 10 | 11 | Generate two-factor authentication (2FA) recovery codes 12 | 13 | @if (recoveryCodes is not null) 14 | { 15 | 16 | } 17 | else 18 | { 19 |

Generate two-factor authentication (2FA) recovery codes

20 | 33 |
34 |
35 | 36 | 37 | 38 |
39 | } 40 | 41 | @code { 42 | private string? message; 43 | private ApplicationUser user = default!; 44 | private IEnumerable? recoveryCodes; 45 | 46 | [CascadingParameter] 47 | private HttpContext HttpContext { get; set; } = default!; 48 | 49 | protected override async Task OnInitializedAsync() 50 | { 51 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 52 | 53 | var isTwoFactorEnabled = await UserManager.GetTwoFactorEnabledAsync(user); 54 | if (!isTwoFactorEnabled) 55 | { 56 | throw new InvalidOperationException("Cannot generate recovery codes for user because they do not have 2FA enabled."); 57 | } 58 | } 59 | 60 | private async Task OnSubmitAsync() 61 | { 62 | var userId = await UserManager.GetUserIdAsync(user); 63 | recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); 64 | message = "You have generated new recovery codes."; 65 | 66 | Logger.LogInformation("User with ID '{UserId}' has generated new 2FA recovery codes.", userId); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ResendEmailConfirmation.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ResendEmailConfirmation" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Text 5 | @using System.Text.Encodings.Web 6 | @using Microsoft.AspNetCore.Identity 7 | @using Microsoft.AspNetCore.WebUtilities 8 | @using AppStatServer.Data 9 | 10 | @inject UserManager UserManager 11 | @inject IEmailSender EmailSender 12 | @inject NavigationManager NavigationManager 13 | @inject IdentityRedirectManager RedirectManager 14 | 15 | Resend email confirmation 16 | 17 |

Resend email confirmation

18 |

Enter your email.

19 |
20 | 21 |
22 |
23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 | @code { 37 | private string? message; 38 | 39 | [SupplyParameterFromForm] 40 | private InputModel Input { get; set; } = new(); 41 | 42 | private async Task OnValidSubmitAsync() 43 | { 44 | var user = await UserManager.FindByEmailAsync(Input.Email!); 45 | if (user is null) 46 | { 47 | message = "Verification email sent. Please check your email."; 48 | return; 49 | } 50 | 51 | var userId = await UserManager.GetUserIdAsync(user); 52 | var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); 53 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 54 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 55 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, 56 | new Dictionary { ["userId"] = userId, ["code"] = code }); 57 | await EmailSender.SendConfirmationLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl)); 58 | 59 | message = "Verification email sent. Please check your email."; 60 | } 61 | 62 | private sealed class InputModel 63 | { 64 | [Required] 65 | [EmailAddress] 66 | public string Email { get; set; } = ""; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ForgotPassword.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ForgotPassword" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Text 5 | @using System.Text.Encodings.Web 6 | @using Microsoft.AspNetCore.Identity 7 | @using Microsoft.AspNetCore.WebUtilities 8 | @using AppStatServer.Data 9 | 10 | @inject UserManager UserManager 11 | @inject IEmailSender EmailSender 12 | @inject NavigationManager NavigationManager 13 | @inject IdentityRedirectManager RedirectManager 14 | 15 | Forgot your password? 16 | 17 |

Forgot your password?

18 |

Enter your email.

19 |
20 |
21 |
22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 | @code { 37 | [SupplyParameterFromForm] 38 | private InputModel Input { get; set; } = new(); 39 | 40 | private async Task OnValidSubmitAsync() 41 | { 42 | var user = await UserManager.FindByEmailAsync(Input.Email); 43 | if (user is null || !(await UserManager.IsEmailConfirmedAsync(user))) 44 | { 45 | // Don't reveal that the user does not exist or is not confirmed 46 | RedirectManager.RedirectTo("Account/ForgotPasswordConfirmation"); 47 | } 48 | 49 | // For more information on how to enable account confirmation and password reset please 50 | // visit https://go.microsoft.com/fwlink/?LinkID=532713 51 | var code = await UserManager.GeneratePasswordResetTokenAsync(user); 52 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 53 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 54 | NavigationManager.ToAbsoluteUri("Account/ResetPassword").AbsoluteUri, 55 | new Dictionary { ["code"] = code }); 56 | 57 | await EmailSender.SendPasswordResetLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl)); 58 | 59 | RedirectManager.RedirectTo("Account/ForgotPasswordConfirmation"); 60 | } 61 | 62 | private sealed class InputModel 63 | { 64 | [Required] 65 | [EmailAddress] 66 | public string Email { get; set; } = ""; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/PersistingServerAuthenticationStateProvider.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Client; 2 | using Microsoft.AspNetCore.Components; 3 | using Microsoft.AspNetCore.Components.Authorization; 4 | using Microsoft.AspNetCore.Components.Server; 5 | using Microsoft.AspNetCore.Components.Web; 6 | using Microsoft.AspNetCore.Identity; 7 | using Microsoft.Extensions.Options; 8 | using System.Diagnostics; 9 | 10 | namespace AppStatServer.Components.Account 11 | { 12 | // This is a server-side AuthenticationStateProvider that uses PersistentComponentState to flow the 13 | // authentication state to the client which is then fixed for the lifetime of the WebAssembly application. 14 | internal sealed class PersistingServerAuthenticationStateProvider : ServerAuthenticationStateProvider, IDisposable 15 | { 16 | private readonly PersistentComponentState state; 17 | private readonly IdentityOptions options; 18 | 19 | private readonly PersistingComponentStateSubscription subscription; 20 | 21 | private Task? authenticationStateTask; 22 | 23 | public PersistingServerAuthenticationStateProvider( 24 | PersistentComponentState persistentComponentState, 25 | IOptions optionsAccessor) 26 | { 27 | state = persistentComponentState; 28 | options = optionsAccessor.Value; 29 | 30 | AuthenticationStateChanged += OnAuthenticationStateChanged; 31 | subscription = state.RegisterOnPersisting(OnPersistingAsync, RenderMode.InteractiveWebAssembly); 32 | } 33 | 34 | private void OnAuthenticationStateChanged(Task task) 35 | { 36 | authenticationStateTask = task; 37 | } 38 | 39 | private async Task OnPersistingAsync() 40 | { 41 | if (authenticationStateTask is null) 42 | { 43 | throw new UnreachableException($"Authentication state not set in {nameof(OnPersistingAsync)}()."); 44 | } 45 | 46 | var authenticationState = await authenticationStateTask; 47 | var principal = authenticationState.User; 48 | 49 | if (principal.Identity?.IsAuthenticated == true) 50 | { 51 | var userId = principal.FindFirst(options.ClaimsIdentity.UserIdClaimType)?.Value; 52 | var email = principal.FindFirst(options.ClaimsIdentity.EmailClaimType)?.Value; 53 | 54 | if (userId != null && email != null) 55 | { 56 | state.PersistAsJson(nameof(UserInfo), new UserInfo 57 | { 58 | UserId = userId, 59 | Email = email, 60 | }); 61 | } 62 | } 63 | } 64 | 65 | public void Dispose() 66 | { 67 | subscription.Dispose(); 68 | AuthenticationStateChanged -= OnAuthenticationStateChanged; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.10.34804.81 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppStatServer", "AppStatServer\AppStatServer\AppStatServer.csproj", "{943F1259-F1F8-49E9-9594-51E00CE2DA9C}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppStatServer.Client", "AppStatServer\AppStatServer.Client\AppStatServer.Client.csproj", "{995E55B4-64D6-472A-9C0D-F2B667EAEE07}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTestClient", "ConsoleTestClient\ConsoleTestClient.csproj", "{50B380B7-E367-41C6-B501-F40DCE4CCDF3}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestClients", "TestClients", "{58232895-04C7-4F0B-BA96-B1C650AB49D5}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppStatServerLite", "AppStatServerLite\AppStatServerLite.csproj", "{9C14F825-65F7-4579-825F-06011C4D921A}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {943F1259-F1F8-49E9-9594-51E00CE2DA9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {943F1259-F1F8-49E9-9594-51E00CE2DA9C}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {943F1259-F1F8-49E9-9594-51E00CE2DA9C}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {943F1259-F1F8-49E9-9594-51E00CE2DA9C}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {995E55B4-64D6-472A-9C0D-F2B667EAEE07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {995E55B4-64D6-472A-9C0D-F2B667EAEE07}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {995E55B4-64D6-472A-9C0D-F2B667EAEE07}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {995E55B4-64D6-472A-9C0D-F2B667EAEE07}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {50B380B7-E367-41C6-B501-F40DCE4CCDF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {50B380B7-E367-41C6-B501-F40DCE4CCDF3}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {50B380B7-E367-41C6-B501-F40DCE4CCDF3}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {50B380B7-E367-41C6-B501-F40DCE4CCDF3}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {9C14F825-65F7-4579-825F-06011C4D921A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {9C14F825-65F7-4579-825F-06011C4D921A}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {9C14F825-65F7-4579-825F-06011C4D921A}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {9C14F825-65F7-4579-825F-06011C4D921A}.Release|Any CPU.Build.0 = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | GlobalSection(NestedProjects) = preSolution 43 | {50B380B7-E367-41C6-B501-F40DCE4CCDF3} = {58232895-04C7-4F0B-BA96-B1C650AB49D5} 44 | EndGlobalSection 45 | GlobalSection(ExtensibilityGlobals) = postSolution 46 | SolutionGuid = {F2D21728-A53B-458F-BD5D-185391D54733} 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IdentityRedirectManager RedirectManager 11 | 12 | Profile 13 | 14 |

Profile

15 | 16 | 17 |
18 |
19 | 20 | 21 | 22 |
23 | 24 | 25 |
26 |
27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 | @code { 37 | private ApplicationUser user = default!; 38 | private string? username; 39 | private string? phoneNumber; 40 | 41 | [CascadingParameter] 42 | private HttpContext HttpContext { get; set; } = default!; 43 | 44 | [SupplyParameterFromForm] 45 | private InputModel Input { get; set; } = new(); 46 | 47 | protected override async Task OnInitializedAsync() 48 | { 49 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 50 | username = await UserManager.GetUserNameAsync(user); 51 | phoneNumber = await UserManager.GetPhoneNumberAsync(user); 52 | 53 | Input.PhoneNumber ??= phoneNumber; 54 | } 55 | 56 | private async Task OnValidSubmitAsync() 57 | { 58 | if (Input.PhoneNumber != phoneNumber) 59 | { 60 | var setPhoneResult = await UserManager.SetPhoneNumberAsync(user, Input.PhoneNumber); 61 | if (!setPhoneResult.Succeeded) 62 | { 63 | RedirectManager.RedirectToCurrentPageWithStatus("Error: Failed to set phone number.", HttpContext); 64 | } 65 | } 66 | 67 | await SignInManager.RefreshSignInAsync(user); 68 | RedirectManager.RedirectToCurrentPageWithStatus("Your profile has been updated", HttpContext); 69 | } 70 | 71 | private sealed class InputModel 72 | { 73 | [Phone] 74 | [Display(Name = "Phone number")] 75 | public string? PhoneNumber { get; set; } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/DeletePersonalData.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/DeletePersonalData" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IdentityRedirectManager RedirectManager 11 | @inject ILogger Logger 12 | 13 | Delete Personal Data 14 | 15 | 16 | 17 |

Delete Personal Data

18 | 19 | 24 | 25 |
26 | 27 | 28 | 29 | @if (requirePassword) 30 | { 31 |
32 | 33 | 34 | 35 |
36 | } 37 | 38 |
39 |
40 | 41 | @code { 42 | private string? message; 43 | private ApplicationUser user = default!; 44 | private bool requirePassword; 45 | 46 | [CascadingParameter] 47 | private HttpContext HttpContext { get; set; } = default!; 48 | 49 | [SupplyParameterFromForm] 50 | private InputModel Input { get; set; } = new(); 51 | 52 | protected override async Task OnInitializedAsync() 53 | { 54 | Input ??= new(); 55 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 56 | requirePassword = await UserManager.HasPasswordAsync(user); 57 | } 58 | 59 | private async Task OnValidSubmitAsync() 60 | { 61 | if (requirePassword && !await UserManager.CheckPasswordAsync(user, Input.Password)) 62 | { 63 | message = "Error: Incorrect password."; 64 | return; 65 | } 66 | 67 | var result = await UserManager.DeleteAsync(user); 68 | if (!result.Succeeded) 69 | { 70 | throw new InvalidOperationException("Unexpected error occurred deleting user."); 71 | } 72 | 73 | await SignInManager.SignOutAsync(); 74 | 75 | var userId = await UserManager.GetUserIdAsync(user); 76 | Logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId); 77 | 78 | RedirectManager.RedirectToCurrentPage(); 79 | } 80 | 81 | private sealed class InputModel 82 | { 83 | [DataType(DataType.Password)] 84 | public string Password { get; set; } = ""; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Program.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Client.Pages; 2 | using AppStatServer.Components; 3 | using AppStatServer.Components.Account; 4 | using AppStatServer.Data; 5 | using AppStatServer.Sentry; 6 | using Microsoft.AspNetCore.Components.Authorization; 7 | using Microsoft.AspNetCore.Identity; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | var builder = WebApplication.CreateBuilder(args); 11 | 12 | // Add services to the container. 13 | builder.Services.AddRazorComponents() 14 | .AddInteractiveWebAssemblyComponents(); 15 | 16 | builder.Services.AddCascadingAuthenticationState(); 17 | builder.Services.AddScoped(); 18 | builder.Services.AddScoped(); 19 | builder.Services.AddScoped(); 20 | 21 | builder.Services.AddAuthorization(); 22 | builder.Services.AddAuthentication(options => 23 | { 24 | options.DefaultScheme = IdentityConstants.ApplicationScheme; 25 | options.DefaultSignInScheme = IdentityConstants.ExternalScheme; 26 | }) 27 | .AddIdentityCookies(); 28 | 29 | var connectionStringName = builder.Configuration["UseConnection"]; 30 | 31 | var connectionString = builder.Configuration.GetConnectionString(connectionStringName) ?? throw new InvalidOperationException($"Connection string '{connectionStringName}' not found."); 32 | 33 | builder.Services.AddDbContext(options => 34 | { 35 | switch (connectionStringName) 36 | { 37 | case "PostgresConnection": 38 | options.UseNpgsql(connectionString); 39 | break; 40 | case "SqliteConnection": 41 | options.UseSqlite(connectionString); 42 | break; 43 | case "MsSqlConnection": 44 | options.UseSqlServer(connectionString); 45 | break; 46 | case "MySqlConnection": 47 | options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); 48 | break; 49 | } 50 | }); 51 | 52 | builder.Services.AddDatabaseDeveloperPageExceptionFilter(); 53 | 54 | builder.Services.AddIdentityCore(options => options.SignIn.RequireConfirmedAccount = true) 55 | .AddEntityFrameworkStores() 56 | .AddSignInManager() 57 | .AddDefaultTokenProviders(); 58 | 59 | builder.Services.AddSingleton, IdentityNoOpEmailSender>(); 60 | 61 | var app = builder.Build(); 62 | 63 | // Configure the HTTP request pipeline. 64 | if (app.Environment.IsDevelopment()) 65 | { 66 | app.UseWebAssemblyDebugging(); 67 | app.UseMigrationsEndPoint(); 68 | } 69 | else 70 | { 71 | app.UseExceptionHandler("/Error", createScopeForErrors: true); 72 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 73 | app.UseHsts(); 74 | } 75 | 76 | var sentryEnvelopeHandler = new EnvelopeHandler(app); 77 | 78 | app.UseHttpsRedirection(); 79 | 80 | app.UseStaticFiles(); 81 | app.UseAntiforgery(); 82 | 83 | app.MapRazorComponents() 84 | .AddInteractiveWebAssemblyRenderMode() 85 | .AddAdditionalAssemblies(typeof(AppStatServer.Client._Imports).Assembly); 86 | 87 | // Add additional endpoints required by the Identity /Account Razor components. 88 | app.MapAdditionalIdentityEndpoints(); 89 | 90 | app.Run(); 91 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/LoginWithRecoveryCode.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/LoginWithRecoveryCode" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject SignInManager SignInManager 8 | @inject UserManager UserManager 9 | @inject IdentityRedirectManager RedirectManager 10 | @inject ILogger Logger 11 | 12 | Recovery code verification 13 | 14 |

Recovery code verification

15 |
16 | 17 |

18 | You have requested to log in with a recovery code. This login will not be remembered until you provide 19 | an authenticator app code at log in or disable 2FA and log in again. 20 |

21 |
22 |
23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 | @code { 37 | private string? message; 38 | private ApplicationUser user = default!; 39 | 40 | [SupplyParameterFromForm] 41 | private InputModel Input { get; set; } = new(); 42 | 43 | [SupplyParameterFromQuery] 44 | private string? ReturnUrl { get; set; } 45 | 46 | protected override async Task OnInitializedAsync() 47 | { 48 | // Ensure the user has gone through the username & password screen first 49 | user = await SignInManager.GetTwoFactorAuthenticationUserAsync() ?? 50 | throw new InvalidOperationException("Unable to load two-factor authentication user."); 51 | } 52 | 53 | private async Task OnValidSubmitAsync() 54 | { 55 | var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty); 56 | 57 | var result = await SignInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode); 58 | 59 | var userId = await UserManager.GetUserIdAsync(user); 60 | 61 | if (result.Succeeded) 62 | { 63 | Logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", userId); 64 | RedirectManager.RedirectTo(ReturnUrl); 65 | } 66 | else if (result.IsLockedOut) 67 | { 68 | Logger.LogWarning("User account locked out."); 69 | RedirectManager.RedirectTo("Account/Lockout"); 70 | } 71 | else 72 | { 73 | Logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", userId); 74 | message = "Error: Invalid recovery code entered."; 75 | } 76 | } 77 | 78 | private sealed class InputModel 79 | { 80 | [Required] 81 | [DataType(DataType.Text)] 82 | [Display(Name = "Recovery Code")] 83 | public string RecoveryCode { get; set; } = ""; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Layout/NavMenu.razor: -------------------------------------------------------------------------------- 1 | @implements IDisposable 2 | 3 | @inject NavigationManager NavigationManager 4 | 5 | 10 | 11 | 12 | 13 | 71 | 72 | @code { 73 | private string? currentUrl; 74 | 75 | protected override void OnInitialized() 76 | { 77 | currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri); 78 | NavigationManager.LocationChanged += OnLocationChanged; 79 | } 80 | 81 | private void OnLocationChanged(object? sender, LocationChangedEventArgs e) 82 | { 83 | currentUrl = NavigationManager.ToBaseRelativePath(e.Location); 84 | StateHasChanged(); 85 | } 86 | 87 | public void Dispose() 88 | { 89 | NavigationManager.LocationChanged -= OnLocationChanged; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/SetPassword.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/SetPassword" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IdentityRedirectManager RedirectManager 11 | 12 | Set password 13 | 14 |

Set your password

15 | 16 |

17 | You do not have a local username/password for this site. Add a local 18 | account so you can log in without an external login. 19 |

20 |
21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 |
30 |
31 | 32 | 33 | 34 |
35 | 36 |
37 |
38 |
39 | 40 | @code { 41 | private string? message; 42 | private ApplicationUser user = default!; 43 | 44 | [CascadingParameter] 45 | private HttpContext HttpContext { get; set; } = default!; 46 | 47 | [SupplyParameterFromForm] 48 | private InputModel Input { get; set; } = new(); 49 | 50 | protected override async Task OnInitializedAsync() 51 | { 52 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 53 | 54 | var hasPassword = await UserManager.HasPasswordAsync(user); 55 | if (hasPassword) 56 | { 57 | RedirectManager.RedirectTo("Account/Manage/ChangePassword"); 58 | } 59 | } 60 | 61 | private async Task OnValidSubmitAsync() 62 | { 63 | var addPasswordResult = await UserManager.AddPasswordAsync(user, Input.NewPassword!); 64 | if (!addPasswordResult.Succeeded) 65 | { 66 | message = $"Error: {string.Join(",", addPasswordResult.Errors.Select(error => error.Description))}"; 67 | return; 68 | } 69 | 70 | await SignInManager.RefreshSignInAsync(user); 71 | RedirectManager.RedirectToCurrentPageWithStatus("Your password has been set.", HttpContext); 72 | } 73 | 74 | private sealed class InputModel 75 | { 76 | [Required] 77 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 78 | [DataType(DataType.Password)] 79 | [Display(Name = "New password")] 80 | public string? NewPassword { get; set; } 81 | 82 | [DataType(DataType.Password)] 83 | [Display(Name = "Confirm new password")] 84 | [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 85 | public string? ConfirmPassword { get; set; } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/TwoFactorAuthentication.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/TwoFactorAuthentication" 2 | 3 | @using Microsoft.AspNetCore.Http.Features 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IdentityRedirectManager RedirectManager 11 | 12 | Two-factor authentication (2FA) 13 | 14 | 15 |

Two-factor authentication (2FA)

16 | @if (canTrack) 17 | { 18 | if (is2faEnabled) 19 | { 20 | if (recoveryCodesLeft == 0) 21 | { 22 |
23 | You have no recovery codes left. 24 |

You must generate a new set of recovery codes before you can log in with a recovery code.

25 |
26 | } 27 | else if (recoveryCodesLeft == 1) 28 | { 29 |
30 | You have 1 recovery code left. 31 |

You can generate a new set of recovery codes.

32 |
33 | } 34 | else if (recoveryCodesLeft <= 3) 35 | { 36 |
37 | You have @recoveryCodesLeft recovery codes left. 38 |

You should generate a new set of recovery codes.

39 |
40 | } 41 | 42 | if (isMachineRemembered) 43 | { 44 |
45 | 46 | 47 | 48 | } 49 | 50 | Disable 2FA 51 | Reset recovery codes 52 | } 53 | 54 |

Authenticator app

55 | @if (!hasAuthenticator) 56 | { 57 | Add authenticator app 58 | } 59 | else 60 | { 61 | Set up authenticator app 62 | Reset authenticator app 63 | } 64 | } 65 | else 66 | { 67 |
68 | Privacy and cookie policy have not been accepted. 69 |

You must accept the policy before you can enable two factor authentication.

70 |
71 | } 72 | 73 | @code { 74 | private bool canTrack; 75 | private bool hasAuthenticator; 76 | private int recoveryCodesLeft; 77 | private bool is2faEnabled; 78 | private bool isMachineRemembered; 79 | 80 | [CascadingParameter] 81 | private HttpContext HttpContext { get; set; } = default!; 82 | 83 | protected override async Task OnInitializedAsync() 84 | { 85 | var user = await UserAccessor.GetRequiredUserAsync(HttpContext); 86 | canTrack = HttpContext.Features.Get()?.CanTrack ?? true; 87 | hasAuthenticator = await UserManager.GetAuthenticatorKeyAsync(user) is not null; 88 | is2faEnabled = await UserManager.GetTwoFactorEnabledAsync(user); 89 | isMachineRemembered = await SignInManager.IsTwoFactorClientRememberedAsync(user); 90 | recoveryCodesLeft = await UserManager.CountRecoveryCodesAsync(user); 91 | } 92 | 93 | private async Task OnSubmitForgetBrowserAsync() 94 | { 95 | await SignInManager.ForgetTwoFactorClientAsync(); 96 | 97 | RedirectManager.RedirectToCurrentPageWithStatus( 98 | "The current browser has been forgotten. When you login again from this browser you will be prompted for your 2fa code.", 99 | HttpContext); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/LoginWith2fa.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/LoginWith2fa" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject SignInManager SignInManager 8 | @inject UserManager UserManager 9 | @inject IdentityRedirectManager RedirectManager 10 | @inject ILogger Logger 11 | 12 | Two-factor authentication 13 | 14 |

Two-factor authentication

15 |
16 | 17 |

Your login is protected with an authenticator app. Enter your authenticator code below.

18 |
19 |
20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 |
30 |
31 | 35 |
36 |
37 | 38 |
39 |
40 |
41 |
42 |

43 | Don't have access to your authenticator device? You can 44 | log in with a recovery code. 45 |

46 | 47 | @code { 48 | private string? message; 49 | private ApplicationUser user = default!; 50 | 51 | [SupplyParameterFromForm] 52 | private InputModel Input { get; set; } = new(); 53 | 54 | [SupplyParameterFromQuery] 55 | private string? ReturnUrl { get; set; } 56 | 57 | [SupplyParameterFromQuery] 58 | private bool RememberMe { get; set; } 59 | 60 | protected override async Task OnInitializedAsync() 61 | { 62 | // Ensure the user has gone through the username & password screen first 63 | user = await SignInManager.GetTwoFactorAuthenticationUserAsync() ?? 64 | throw new InvalidOperationException("Unable to load two-factor authentication user."); 65 | } 66 | 67 | private async Task OnValidSubmitAsync() 68 | { 69 | var authenticatorCode = Input.TwoFactorCode!.Replace(" ", string.Empty).Replace("-", string.Empty); 70 | var result = await SignInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, RememberMe, Input.RememberMachine); 71 | var userId = await UserManager.GetUserIdAsync(user); 72 | 73 | if (result.Succeeded) 74 | { 75 | Logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", userId); 76 | RedirectManager.RedirectTo(ReturnUrl); 77 | } 78 | else if (result.IsLockedOut) 79 | { 80 | Logger.LogWarning("User with ID '{UserId}' account locked out.", userId); 81 | RedirectManager.RedirectTo("Account/Lockout"); 82 | } 83 | else 84 | { 85 | Logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", userId); 86 | message = "Error: Invalid authenticator code."; 87 | } 88 | } 89 | 90 | private sealed class InputModel 91 | { 92 | [Required] 93 | [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 94 | [DataType(DataType.Text)] 95 | [Display(Name = "Authenticator code")] 96 | public string? TwoFactorCode { get; set; } 97 | 98 | [Display(Name = "Remember this machine")] 99 | public bool RememberMachine { get; set; } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/ChangePassword.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/ChangePassword" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IdentityRedirectManager RedirectManager 11 | @inject ILogger Logger 12 | 13 | Change password 14 | 15 |

Change password

16 | 17 |
18 |
19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 |
27 |
28 | 29 | 30 | 31 |
32 |
33 | 34 | 35 | 36 |
37 | 38 |
39 |
40 |
41 | 42 | @code { 43 | private string? message; 44 | private ApplicationUser user = default!; 45 | private bool hasPassword; 46 | 47 | [CascadingParameter] 48 | private HttpContext HttpContext { get; set; } = default!; 49 | 50 | [SupplyParameterFromForm] 51 | private InputModel Input { get; set; } = new(); 52 | 53 | protected override async Task OnInitializedAsync() 54 | { 55 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 56 | hasPassword = await UserManager.HasPasswordAsync(user); 57 | if (!hasPassword) 58 | { 59 | RedirectManager.RedirectTo("Account/Manage/SetPassword"); 60 | } 61 | } 62 | 63 | private async Task OnValidSubmitAsync() 64 | { 65 | var changePasswordResult = await UserManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword); 66 | if (!changePasswordResult.Succeeded) 67 | { 68 | message = $"Error: {string.Join(",", changePasswordResult.Errors.Select(error => error.Description))}"; 69 | return; 70 | } 71 | 72 | await SignInManager.RefreshSignInAsync(user); 73 | Logger.LogInformation("User changed their password successfully."); 74 | 75 | RedirectManager.RedirectToCurrentPageWithStatus("Your password has been changed", HttpContext); 76 | } 77 | 78 | private sealed class InputModel 79 | { 80 | [Required] 81 | [DataType(DataType.Password)] 82 | [Display(Name = "Current password")] 83 | public string OldPassword { get; set; } = ""; 84 | 85 | [Required] 86 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 87 | [DataType(DataType.Password)] 88 | [Display(Name = "New password")] 89 | public string NewPassword { get; set; } = ""; 90 | 91 | [DataType(DataType.Password)] 92 | [Display(Name = "Confirm new password")] 93 | [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")] 94 | public string ConfirmPassword { get; set; } = ""; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ResetPassword.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ResetPassword" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Text 5 | @using Microsoft.AspNetCore.Identity 6 | @using Microsoft.AspNetCore.WebUtilities 7 | @using AppStatServer.Data 8 | 9 | @inject IdentityRedirectManager RedirectManager 10 | @inject UserManager UserManager 11 | 12 | Reset password 13 | 14 |

Reset password

15 |

Reset your password.

16 |
17 |
18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 |
30 |
31 | 32 | 33 | 34 |
35 |
36 | 37 | 38 | 39 |
40 | 41 |
42 |
43 |
44 | 45 | @code { 46 | private IEnumerable? identityErrors; 47 | 48 | [SupplyParameterFromForm] 49 | private InputModel Input { get; set; } = new(); 50 | 51 | [SupplyParameterFromQuery] 52 | private string? Code { get; set; } 53 | 54 | private string? Message => identityErrors is null ? null : $"Error: {string.Join(", ", identityErrors.Select(error => error.Description))}"; 55 | 56 | protected override void OnInitialized() 57 | { 58 | if (Code is null) 59 | { 60 | RedirectManager.RedirectTo("Account/InvalidPasswordReset"); 61 | } 62 | 63 | Input.Code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(Code)); 64 | } 65 | 66 | private async Task OnValidSubmitAsync() 67 | { 68 | var user = await UserManager.FindByEmailAsync(Input.Email); 69 | if (user is null) 70 | { 71 | // Don't reveal that the user does not exist 72 | RedirectManager.RedirectTo("Account/ResetPasswordConfirmation"); 73 | } 74 | 75 | var result = await UserManager.ResetPasswordAsync(user, Input.Code, Input.Password); 76 | if (result.Succeeded) 77 | { 78 | RedirectManager.RedirectTo("Account/ResetPasswordConfirmation"); 79 | } 80 | 81 | identityErrors = result.Errors; 82 | } 83 | 84 | private sealed class InputModel 85 | { 86 | [Required] 87 | [EmailAddress] 88 | public string Email { get; set; } = ""; 89 | 90 | [Required] 91 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 92 | [DataType(DataType.Password)] 93 | public string Password { get; set; } = ""; 94 | 95 | [DataType(DataType.Password)] 96 | [Display(Name = "Confirm password")] 97 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 98 | public string ConfirmPassword { get; set; } = ""; 99 | 100 | [Required] 101 | public string Code { get; set; } = ""; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/EnvelopeHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.IO.Compression; 3 | using System.Text.Json; 4 | using System.Text.RegularExpressions; 5 | using AppStatServerLite.Data; 6 | 7 | namespace AppStatServerLite.Sentry; 8 | 9 | public class EnvelopeHandler 10 | { 11 | private ConcurrentQueue _events = new (); 12 | 13 | public EnvelopeHandler(WebApplication app) 14 | { 15 | app.MapPost("/api/1/envelope", async (HttpRequest request, IEventStorage eventStorage) => 16 | { 17 | var body = request.Body; 18 | var requestBody = await DecompressStream(body); 19 | var entries = requestBody.Split('\n'); 20 | var lastId = "0"; 21 | 22 | if (entries.Length > 0) 23 | foreach (var entry in entries) 24 | lastId = ProcessEntry(entry, _events); 25 | 26 | var events = new List(); 27 | while (_events.Count > 0) 28 | if (_events.TryDequeue(out var ev)) events.Add(ev); 29 | 30 | await eventStorage.SaveEventsAsync(events); 31 | //Console.WriteLine("count: " + _events.Count); 32 | 33 | return new EnvelopeResponse { Id = lastId }; 34 | }); 35 | 36 | } 37 | 38 | static async Task DecompressStream(Stream compressedStream) 39 | { 40 | var gzipStream = new GZipStream(compressedStream, CompressionMode.Decompress); 41 | using StreamReader streamReader = new StreamReader(gzipStream); 42 | return await streamReader.ReadToEndAsync(); 43 | } 44 | 45 | string ProcessEntry(string entry, ConcurrentQueue eventsQueue) 46 | { 47 | if (string.IsNullOrWhiteSpace(entry)) 48 | return "0"; 49 | 50 | if (entry.StartsWith("{\"sdk")) 51 | { 52 | var sdkEntry = JsonSerializer.Deserialize(entry); 53 | } 54 | 55 | if (entry.StartsWith("{\"type")) 56 | { 57 | var sectionEntry = JsonSerializer.Deserialize(entry); 58 | } 59 | 60 | if (entry.StartsWith("{\"sid")) 61 | { 62 | var sessionEntry = JsonSerializer.Deserialize(entry); 63 | } 64 | 65 | if (entry.StartsWith("{\"event_id") || entry.StartsWith("{\"modules")) 66 | { 67 | var eventEntry = JsonSerializer.Deserialize(entry); 68 | 69 | var message = eventEntry?.exception?.values?.FirstOrDefault()?.value 70 | ?? eventEntry?.logentry?.message; 71 | 72 | string pattern = @"(\d+\.\d+\.\d+)(\+\w+)?$"; 73 | 74 | var input = eventEntry.release; 75 | // Match the pattern in the input string 76 | Match match = Regex.Match(input, pattern); 77 | var versionNumber = input; 78 | 79 | if (match.Success) 80 | { 81 | // Extract the version number from the matched group 82 | versionNumber = match.Groups[1].Value; 83 | Console.WriteLine("Version Number: " + versionNumber); 84 | } 85 | else 86 | { 87 | Console.WriteLine("No version number found in the input string."); 88 | } 89 | 90 | var isError = eventEntry?.exception != null; 91 | var isCrash = eventEntry?.threads?.values?.Any(x => x.crashed) ?? false; 92 | var level = eventEntry?.level ?? "-"; 93 | var sessionId = ""; 94 | var spanId = eventEntry.contexts?.trace?.span_id; 95 | var traceId = eventEntry.contexts?.trace?.trace_id; 96 | var os = eventEntry.contexts?.os?.raw_description; 97 | var user = eventEntry.user?.id ?? Guid.Empty.ToString(); 98 | 99 | if (!string.IsNullOrWhiteSpace(message)) 100 | { 101 | eventsQueue.Enqueue(new AppEvent() 102 | { 103 | Id = eventEntry.event_id, 104 | Timestamp = eventEntry.timestamp, 105 | SessionId = sessionId, 106 | Message = message, 107 | EventEntry = "", //entry, 108 | IsCrash = isCrash, 109 | IsError = isError, 110 | Level = level, 111 | Release = versionNumber, 112 | SpanId = spanId, 113 | TraceId = traceId, 114 | Os = os, 115 | UserId = user 116 | }); 117 | 118 | return eventEntry.event_id; 119 | } 120 | } 121 | 122 | return "0"; 123 | } 124 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/wwwroot/app.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 3 | } 4 | 5 | a, .btn-link { 6 | color: #006bb7; 7 | } 8 | 9 | .btn-primary { 10 | color: #fff; 11 | background-color: #1b6ec2; 12 | border-color: #1861ac; 13 | } 14 | 15 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { 16 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; 17 | } 18 | 19 | .content { 20 | padding-top: 1.1rem; 21 | } 22 | 23 | h1:focus { 24 | outline: none; 25 | } 26 | 27 | .valid.modified:not([type=checkbox]) { 28 | outline: 1px solid #26b050; 29 | } 30 | 31 | .invalid { 32 | outline: 1px solid #e50000; 33 | } 34 | 35 | .validation-message { 36 | color: #e50000; 37 | } 38 | 39 | .blazor-error-boundary { 40 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 41 | padding: 1rem 1rem 1rem 3.7rem; 42 | color: white; 43 | } 44 | 45 | .blazor-error-boundary::after { 46 | content: "An error has occurred." 47 | } 48 | 49 | .darker-border-checkbox.form-check-input { 50 | border-color: #929292; 51 | } 52 | 53 | 54 | 55 | blockquote { 56 | font-size: 1.1em; 57 | line-height: 1.6em; 58 | padding: 20px 20px 20px 40px; 59 | border-left: none; 60 | position: relative; 61 | text-indent: -19px 62 | } 63 | 64 | section#block_content { 65 | min-height: 400px; 66 | padding-top: 40px; 67 | text-align: left; 68 | } 69 | 70 | blockquote p { 71 | font-size: 1em 72 | } 73 | 74 | blockquote:before, 75 | blockquote:after { 76 | font-family: Arial, serif; 77 | font-size: 2.5em; 78 | vertical-align: middle; 79 | line-height: 0 80 | } 81 | 82 | blockquote:before { 83 | content: open-quote; 84 | margin-right: 4px 85 | } 86 | 87 | blockquote:after { 88 | content: close-quote; 89 | margin-left: 3px 90 | } 91 | 92 | blockquote.blockstyle, 93 | blockquote.style2 { 94 | background: #fff; 95 | /* font-style: italic 96 | */} 97 | 98 | blockquote.blockstyle p, 99 | blockquote.style2 p { 100 | display: inline 101 | } 102 | 103 | blockquote.blockstyle { 104 | border-left: 3px solid #f0715f; 105 | position: relative; 106 | } 107 | 108 | blockquote.blockstyle > span.triangle:before { 109 | text-indent: 0; 110 | content: "\f0da"; 111 | font-family: FontAwesome; 112 | color: #f0715f; 113 | position: absolute; 114 | left: -1px; 115 | top: 50%; 116 | margin-top: -11px; 117 | font-style: normal 118 | } 119 | 120 | blockquote.blockstyle:before, 121 | blockquote.blockstyle:after { 122 | color: #f0715f; 123 | } 124 | 125 | blockquote.blockstyle.border-color-blue { 126 | border-color: #01b7f2 127 | } 128 | 129 | blockquote.blockstyle.border-color-blue > span.triangle:before { 130 | color: #01b7f2 131 | } 132 | 133 | blockquote.blockstyle.border-color-yellow { 134 | border-color: #fdb714 135 | } 136 | 137 | blockquote.blockstyle.border-color-yellow > span.triangle:before { 138 | color: #fdb714 139 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/EnvelopeHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using AppStatServer.Data; 3 | using System.IO.Compression; 4 | using System.Text.Json; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace AppStatServer.Sentry; 8 | 9 | public class EnvelopeHandler 10 | { 11 | private ConcurrentQueue _events = new (); 12 | 13 | public EnvelopeHandler(WebApplication app) 14 | { 15 | app.MapPost("/api/1/envelope", async (HttpRequest request, ApplicationDbContext dbContext) => 16 | { 17 | var body = request.Body; 18 | var requestBody = await DecompressStream(body); 19 | var entries = requestBody.Split('\n'); 20 | var lastId = "0"; 21 | if (entries.Length > 0) 22 | { 23 | foreach (var entry in entries) 24 | lastId = ProcessEntry(entry, _events); 25 | } 26 | 27 | while (_events.Count > 0) 28 | { 29 | if (_events.TryDequeue(out var ev)) 30 | { 31 | dbContext.Events.Add(ev); 32 | } 33 | } 34 | await dbContext.SaveChangesAsync(); 35 | 36 | //Console.WriteLine("count: " + _events.Count); 37 | 38 | return new EnvelopeResponse { Id = lastId }; 39 | }); 40 | 41 | } 42 | 43 | static async Task DecompressStream(Stream compressedStream) 44 | { 45 | var gzipStream = new GZipStream(compressedStream, CompressionMode.Decompress); 46 | using StreamReader streamReader = new StreamReader(gzipStream); 47 | return await streamReader.ReadToEndAsync(); 48 | } 49 | 50 | string ProcessEntry(string entry, ConcurrentQueue eventsQueue) 51 | { 52 | if (string.IsNullOrWhiteSpace(entry)) 53 | return "0"; 54 | 55 | if (entry.StartsWith("{\"sdk")) 56 | { 57 | var sdkEntry = JsonSerializer.Deserialize(entry); 58 | } 59 | 60 | if (entry.StartsWith("{\"type")) 61 | { 62 | var sectionEntry = JsonSerializer.Deserialize(entry); 63 | } 64 | 65 | if (entry.StartsWith("{\"sid")) 66 | { 67 | var sessionEntry = JsonSerializer.Deserialize(entry); 68 | } 69 | 70 | if (entry.StartsWith("{\"event_id") || entry.StartsWith("{\"modules")) 71 | { 72 | var eventEntry = JsonSerializer.Deserialize(entry); 73 | 74 | var message = eventEntry?.exception?.values?.FirstOrDefault()?.value 75 | ?? eventEntry?.logentry?.message; 76 | 77 | string pattern = @"(\d+\.\d+\.\d+)(\+\w+)?$"; 78 | 79 | var input = eventEntry.release; 80 | // Match the pattern in the input string 81 | Match match = Regex.Match(input, pattern); 82 | var versionNumber = input; 83 | 84 | if (match.Success) 85 | { 86 | // Extract the version number from the matched group 87 | versionNumber = match.Groups[1].Value; 88 | Console.WriteLine("Version Number: " + versionNumber); 89 | } 90 | else 91 | { 92 | Console.WriteLine("No version number found in the input string."); 93 | } 94 | 95 | var isError = eventEntry?.exception != null; 96 | var isCrash = eventEntry?.threads?.values?.Any(x => x.crashed) ?? false; 97 | var level = eventEntry?.level ?? "-"; 98 | var sessionId = ""; 99 | var spanId = eventEntry.contexts?.trace?.span_id; 100 | var traceId = eventEntry.contexts?.trace?.trace_id; 101 | var os = eventEntry.contexts?.os?.raw_description; 102 | var user = eventEntry.user?.id ?? Guid.Empty.ToString(); 103 | 104 | var stackTrace = ""; 105 | if (isError || isCrash) 106 | stackTrace = eventEntry.threads.values.FirstOrDefault().stacktrace.ToString(); 107 | 108 | if (!string.IsNullOrWhiteSpace(message)) 109 | { 110 | eventsQueue.Enqueue(new AppEvent() 111 | { 112 | Id = eventEntry.event_id, 113 | Timestamp = eventEntry.timestamp, 114 | SessionId = sessionId, 115 | Message = message, 116 | EventEntry = "", //entry, 117 | IsCrash = isCrash, 118 | IsError = isError, 119 | Level = level, 120 | Release = versionNumber, 121 | SpanId = spanId, 122 | TraceId = traceId, 123 | Os = os, 124 | UserId = user, 125 | StackTrace = stackTrace 126 | }); 127 | 128 | return eventEntry.event_id; 129 | } 130 | } 131 | 132 | return "0"; 133 | } 134 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Login.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Login" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using Microsoft.AspNetCore.Authentication 5 | @using Microsoft.AspNetCore.Identity 6 | @using AppStatServer.Data 7 | 8 | @inject SignInManager SignInManager 9 | @inject ILogger Logger 10 | @inject NavigationManager NavigationManager 11 | @inject IdentityRedirectManager RedirectManager 12 | 13 | Log in 14 | 15 |

Log in

16 |
17 |
18 |
19 | 20 | 21 | 22 |

Use a local account to log in.

23 |
24 | 25 |
26 | 27 | 28 | 29 |
30 |
31 | 32 | 33 | 34 |
35 |
36 | 40 |
41 |
42 | 43 |
44 | 55 |
56 |
57 |
58 |
59 |
60 |

Use another service to log in.

61 |
62 | 63 |
64 |
65 |
66 | 67 | @code { 68 | private string? errorMessage; 69 | 70 | [CascadingParameter] 71 | private HttpContext HttpContext { get; set; } = default!; 72 | 73 | [SupplyParameterFromForm] 74 | private InputModel Input { get; set; } = new(); 75 | 76 | [SupplyParameterFromQuery] 77 | private string? ReturnUrl { get; set; } 78 | 79 | protected override async Task OnInitializedAsync() 80 | { 81 | if (HttpMethods.IsGet(HttpContext.Request.Method)) 82 | { 83 | // Clear the existing external cookie to ensure a clean login process 84 | await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); 85 | } 86 | } 87 | 88 | public async Task LoginUser() 89 | { 90 | // This doesn't count login failures towards account lockout 91 | // To enable password failures to trigger account lockout, set lockoutOnFailure: true 92 | var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false); 93 | if (result.Succeeded) 94 | { 95 | Logger.LogInformation("User logged in."); 96 | RedirectManager.RedirectTo(ReturnUrl); 97 | } 98 | else if (result.RequiresTwoFactor) 99 | { 100 | RedirectManager.RedirectTo( 101 | "Account/LoginWith2fa", 102 | new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe }); 103 | } 104 | else if (result.IsLockedOut) 105 | { 106 | Logger.LogWarning("User account locked out."); 107 | RedirectManager.RedirectTo("Account/Lockout"); 108 | } 109 | else 110 | { 111 | errorMessage = "Error: Invalid login attempt."; 112 | } 113 | } 114 | 115 | private sealed class InputModel 116 | { 117 | [Required] 118 | [EmailAddress] 119 | public string Email { get; set; } = ""; 120 | 121 | [Required] 122 | [DataType(DataType.Password)] 123 | public string Password { get; set; } = ""; 124 | 125 | [Display(Name = "Remember me?")] 126 | public bool RememberMe { get; set; } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/Email.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/Email" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Text 5 | @using System.Text.Encodings.Web 6 | @using Microsoft.AspNetCore.Identity 7 | @using Microsoft.AspNetCore.WebUtilities 8 | @using AppStatServer.Data 9 | 10 | @inject UserManager UserManager 11 | @inject IEmailSender EmailSender 12 | @inject IdentityUserAccessor UserAccessor 13 | @inject NavigationManager NavigationManager 14 | 15 | Manage email 16 | 17 |

Manage email

18 | 19 | 20 |
21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | @if (isEmailConfirmed) 29 | { 30 |
31 | 32 |
33 | 34 |
35 | 36 |
37 | } 38 | else 39 | { 40 |
41 | 42 | 43 | 44 |
45 | } 46 |
47 | 48 | 49 | 50 |
51 | 52 |
53 |
54 |
55 | 56 | @code { 57 | private string? message; 58 | private ApplicationUser user = default!; 59 | private string? email; 60 | private bool isEmailConfirmed; 61 | 62 | [CascadingParameter] 63 | private HttpContext HttpContext { get; set; } = default!; 64 | 65 | [SupplyParameterFromForm(FormName = "change-email")] 66 | private InputModel Input { get; set; } = new(); 67 | 68 | protected override async Task OnInitializedAsync() 69 | { 70 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 71 | email = await UserManager.GetEmailAsync(user); 72 | isEmailConfirmed = await UserManager.IsEmailConfirmedAsync(user); 73 | 74 | Input.NewEmail ??= email; 75 | } 76 | 77 | private async Task OnValidSubmitAsync() 78 | { 79 | if (Input.NewEmail is null || Input.NewEmail == email) 80 | { 81 | message = "Your email is unchanged."; 82 | return; 83 | } 84 | 85 | var userId = await UserManager.GetUserIdAsync(user); 86 | var code = await UserManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail); 87 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 88 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 89 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmailChange").AbsoluteUri, 90 | new Dictionary { ["userId"] = userId, ["email"] = Input.NewEmail, ["code"] = code }); 91 | 92 | await EmailSender.SendConfirmationLinkAsync(user, Input.NewEmail, HtmlEncoder.Default.Encode(callbackUrl)); 93 | 94 | message = "Confirmation link to change email sent. Please check your email."; 95 | } 96 | 97 | private async Task OnSendEmailVerificationAsync() 98 | { 99 | if (email is null) 100 | { 101 | return; 102 | } 103 | 104 | var userId = await UserManager.GetUserIdAsync(user); 105 | var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); 106 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 107 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 108 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, 109 | new Dictionary { ["userId"] = userId, ["code"] = code }); 110 | 111 | await EmailSender.SendConfirmationLinkAsync(user, email, HtmlEncoder.Default.Encode(callbackUrl)); 112 | 113 | message = "Verification email sent. Please check your email."; 114 | } 115 | 116 | private sealed class InputModel 117 | { 118 | [Required] 119 | [EmailAddress] 120 | [Display(Name = "New email")] 121 | public string? NewEmail { get; set; } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServerLite/Sentry/Event.cs: -------------------------------------------------------------------------------- 1 | namespace AppStatServerLite.Sentry; 2 | 3 | public class ExceptionValue 4 | { 5 | public string type { get; set; } 6 | public string value { get; set; } 7 | public string module { get; set; } 8 | public int thread_id { get; set; } 9 | } 10 | 11 | public class StacktraceFrame 12 | { 13 | public string function { get; set; } 14 | public bool in_app { get; set; } 15 | public string package { get; set; } 16 | public string instruction_addr { get; set; } 17 | public string addr_mode { get; set; } 18 | public string function_id { get; set; } 19 | public string filename { get; set; } 20 | public int? lineno { get; set; } 21 | public int? colno { get; set; } 22 | public string abs_path { get; set; } 23 | } 24 | 25 | public class StacktraceValue 26 | { 27 | public List frames { get; set; } 28 | } 29 | 30 | public class ExceptionInfo 31 | { 32 | public List values { get; set; } 33 | } 34 | 35 | public class ThreadValue 36 | { 37 | public int id { get; set; } 38 | public string name { get; set; } 39 | public bool crashed { get; set; } 40 | public bool current { get; set; } 41 | public StacktraceValue stacktrace { get; set; } 42 | } 43 | 44 | public class Threads 45 | { 46 | public List values { get; set; } 47 | } 48 | 49 | public class CurrentCulture 50 | { 51 | public string name { get; set; } 52 | public string display_name { get; set; } 53 | public string calendar { get; set; } 54 | } 55 | 56 | public class DynamicCode 57 | { 58 | public bool Compiled { get; set; } 59 | public bool Supported { get; set; } 60 | } 61 | 62 | public class MemoryInfo 63 | { 64 | public int allocated_bytes { get; set; } 65 | public long high_memory_load_threshold_bytes { get; set; } 66 | public long total_available_memory_bytes { get; set; } 67 | public int finalization_pending_count { get; set; } 68 | public bool compacted { get; set; } 69 | public bool concurrent { get; set; } 70 | public List pause_durations { get; set; } 71 | } 72 | 73 | public class ThreadPoolInfo 74 | { 75 | public int min_worker_threads { get; set; } 76 | public int min_completion_port_threads { get; set; } 77 | public int max_worker_threads { get; set; } 78 | public int max_completion_port_threads { get; set; } 79 | public int available_worker_threads { get; set; } 80 | public int available_completion_port_threads { get; set; } 81 | } 82 | 83 | public class AppInfo 84 | { 85 | public string type { get; set; } 86 | public DateTime app_start_time { get; set; } 87 | public bool in_foreground { get; set; } 88 | } 89 | 90 | public class Device 91 | { 92 | public string type { get; set; } 93 | public string timezone { get; set; } 94 | public string timezone_display_name { get; set; } 95 | public DateTime boot_time { get; set; } 96 | } 97 | 98 | public class Os 99 | { 100 | public string type { get; set; } 101 | public string raw_description { get; set; } 102 | } 103 | 104 | public class Runtime 105 | { 106 | public string type { get; set; } 107 | public string name { get; set; } 108 | public string version { get; set; } 109 | public string raw_description { get; set; } 110 | public string identifier { get; set; } 111 | } 112 | 113 | public class TraceInfo 114 | { 115 | public string type { get; set; } 116 | public string span_id { get; set; } 117 | public string trace_id { get; set; } 118 | } 119 | 120 | public class Package 121 | { 122 | public string name { get; set; } 123 | public string version { get; set; } 124 | } 125 | 126 | public class SdkInfo 127 | { 128 | public List packages { get; set; } 129 | public string name { get; set; } 130 | public string version { get; set; } 131 | } 132 | 133 | public class Image 134 | { 135 | public string type { get; set; } 136 | public string debug_id { get; set; } 137 | public string debug_checksum { get; set; } 138 | public string debug_file { get; set; } 139 | public string code_id { get; set; } 140 | public string code_file { get; set; } 141 | } 142 | 143 | public class DebugMeta 144 | { 145 | public List images { get; set; } 146 | } 147 | 148 | public class Contexts 149 | { 150 | public CurrentCulture CurrentCulture { get; set; } 151 | public DynamicCode DynamicCode { get; set; } 152 | public MemoryInfo MemoryInfo { get; set; } 153 | public ThreadPoolInfo ThreadPoolInfo { get; set; } 154 | public AppInfo app { get; set; } 155 | public Device device { get; set; } 156 | public Os os { get; set; } 157 | public Runtime runtime { get; set; } 158 | public TraceInfo trace { get; set; } 159 | } 160 | 161 | public class User 162 | { 163 | public string ip_address { get; set; } 164 | public string id { get; set; } 165 | public string username { get; set; } 166 | } 167 | 168 | public class LogEntry 169 | { 170 | public string message { get; set; } 171 | } 172 | 173 | public class EventEntry 174 | { 175 | public string event_id { get; set; } 176 | public DateTime timestamp { get; set; } 177 | public LogEntry logentry { get; set; } 178 | public string platform { get; set; } 179 | public string release { get; set; } 180 | public ExceptionInfo exception { get; set; } 181 | public Threads threads { get; set; } 182 | public string level { get; set; } 183 | public Dictionary request { get; set; } 184 | public Contexts contexts { get; set; } 185 | public User user { get; set; } 186 | public string environment { get; set; } 187 | public SdkInfo sdk { get; set; } 188 | public DebugMeta debug_meta { get; set; } 189 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/IdentityComponentsEndpointRouteBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using AppStatServer.Components.Account.Pages; 2 | using AppStatServer.Components.Account.Pages.Manage; 3 | using AppStatServer.Data; 4 | using Microsoft.AspNetCore.Authentication; 5 | using Microsoft.AspNetCore.Components.Authorization; 6 | using Microsoft.AspNetCore.Http.Extensions; 7 | using Microsoft.AspNetCore.Identity; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Extensions.Primitives; 10 | using System.Security.Claims; 11 | using System.Text.Json; 12 | 13 | namespace Microsoft.AspNetCore.Routing 14 | { 15 | internal static class IdentityComponentsEndpointRouteBuilderExtensions 16 | { 17 | // These endpoints are required by the Identity Razor components defined in the /Components/Account/Pages directory of this project. 18 | public static IEndpointConventionBuilder MapAdditionalIdentityEndpoints(this IEndpointRouteBuilder endpoints) 19 | { 20 | ArgumentNullException.ThrowIfNull(endpoints); 21 | 22 | var accountGroup = endpoints.MapGroup("/Account"); 23 | 24 | accountGroup.MapPost("/PerformExternalLogin", ( 25 | HttpContext context, 26 | [FromServices] SignInManager signInManager, 27 | [FromForm] string provider, 28 | [FromForm] string returnUrl) => 29 | { 30 | IEnumerable> query = [ 31 | new("ReturnUrl", returnUrl), 32 | new("Action", ExternalLogin.LoginCallbackAction)]; 33 | 34 | var redirectUrl = UriHelper.BuildRelative( 35 | context.Request.PathBase, 36 | "/Account/ExternalLogin", 37 | QueryString.Create(query)); 38 | 39 | var properties = signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); 40 | return TypedResults.Challenge(properties, [provider]); 41 | }); 42 | 43 | accountGroup.MapPost("/Logout", async ( 44 | ClaimsPrincipal user, 45 | SignInManager signInManager, 46 | [FromForm] string returnUrl) => 47 | { 48 | await signInManager.SignOutAsync(); 49 | return TypedResults.LocalRedirect($"~/{returnUrl}"); 50 | }); 51 | 52 | var manageGroup = accountGroup.MapGroup("/Manage").RequireAuthorization(); 53 | 54 | manageGroup.MapPost("/LinkExternalLogin", async ( 55 | HttpContext context, 56 | [FromServices] SignInManager signInManager, 57 | [FromForm] string provider) => 58 | { 59 | // Clear the existing external cookie to ensure a clean login process 60 | await context.SignOutAsync(IdentityConstants.ExternalScheme); 61 | 62 | var redirectUrl = UriHelper.BuildRelative( 63 | context.Request.PathBase, 64 | "/Account/Manage/ExternalLogins", 65 | QueryString.Create("Action", ExternalLogins.LinkLoginCallbackAction)); 66 | 67 | var properties = signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, signInManager.UserManager.GetUserId(context.User)); 68 | return TypedResults.Challenge(properties, [provider]); 69 | }); 70 | 71 | var loggerFactory = endpoints.ServiceProvider.GetRequiredService(); 72 | var downloadLogger = loggerFactory.CreateLogger("DownloadPersonalData"); 73 | 74 | manageGroup.MapPost("/DownloadPersonalData", async ( 75 | HttpContext context, 76 | [FromServices] UserManager userManager, 77 | [FromServices] AuthenticationStateProvider authenticationStateProvider) => 78 | { 79 | var user = await userManager.GetUserAsync(context.User); 80 | if (user is null) 81 | { 82 | return Results.NotFound($"Unable to load user with ID '{userManager.GetUserId(context.User)}'."); 83 | } 84 | 85 | var userId = await userManager.GetUserIdAsync(user); 86 | downloadLogger.LogInformation("User with ID '{UserId}' asked for their personal data.", userId); 87 | 88 | // Only include personal data for download 89 | var personalData = new Dictionary(); 90 | var personalDataProps = typeof(ApplicationUser).GetProperties().Where( 91 | prop => Attribute.IsDefined(prop, typeof(PersonalDataAttribute))); 92 | foreach (var p in personalDataProps) 93 | { 94 | personalData.Add(p.Name, p.GetValue(user)?.ToString() ?? "null"); 95 | } 96 | 97 | var logins = await userManager.GetLoginsAsync(user); 98 | foreach (var l in logins) 99 | { 100 | personalData.Add($"{l.LoginProvider} external login provider key", l.ProviderKey); 101 | } 102 | 103 | personalData.Add("Authenticator Key", (await userManager.GetAuthenticatorKeyAsync(user))!); 104 | var fileBytes = JsonSerializer.SerializeToUtf8Bytes(personalData); 105 | 106 | context.Response.Headers.TryAdd("Content-Disposition", "attachment; filename=PersonalData.json"); 107 | return TypedResults.File(fileBytes, contentType: "application/json", fileDownloadName: "PersonalData.json"); 108 | }); 109 | 110 | return accountGroup; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/ExternalLogins.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/ExternalLogins" 2 | 3 | @using Microsoft.AspNetCore.Authentication 4 | @using Microsoft.AspNetCore.Identity 5 | @using AppStatServer.Data 6 | 7 | @inject UserManager UserManager 8 | @inject SignInManager SignInManager 9 | @inject IdentityUserAccessor UserAccessor 10 | @inject IUserStore UserStore 11 | @inject IdentityRedirectManager RedirectManager 12 | 13 | Manage your external logins 14 | 15 | 16 | @if (currentLogins?.Count > 0) 17 | { 18 |

Registered Logins

19 | 20 | 21 | @foreach (var login in currentLogins) 22 | { 23 | 24 | 25 | 42 | 43 | } 44 | 45 |
@login.ProviderDisplayName 26 | @if (showRemoveButton) 27 | { 28 |
29 | 30 |
31 | 32 | 33 | 34 |
35 | 36 | } 37 | else 38 | { 39 | @:   40 | } 41 |
46 | } 47 | @if (otherLogins?.Count > 0) 48 | { 49 |

Add another service to log in.

50 |
51 |
52 | 53 |
54 |

55 | @foreach (var provider in otherLogins) 56 | { 57 | 60 | } 61 |

62 |
63 | 64 | } 65 | 66 | @code { 67 | public const string LinkLoginCallbackAction = "LinkLoginCallback"; 68 | 69 | private ApplicationUser user = default!; 70 | private IList? currentLogins; 71 | private IList? otherLogins; 72 | private bool showRemoveButton; 73 | 74 | [CascadingParameter] 75 | private HttpContext HttpContext { get; set; } = default!; 76 | 77 | [SupplyParameterFromForm] 78 | private string? LoginProvider { get; set; } 79 | 80 | [SupplyParameterFromForm] 81 | private string? ProviderKey { get; set; } 82 | 83 | [SupplyParameterFromQuery] 84 | private string? Action { get; set; } 85 | 86 | protected override async Task OnInitializedAsync() 87 | { 88 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 89 | currentLogins = await UserManager.GetLoginsAsync(user); 90 | otherLogins = (await SignInManager.GetExternalAuthenticationSchemesAsync()) 91 | .Where(auth => currentLogins.All(ul => auth.Name != ul.LoginProvider)) 92 | .ToList(); 93 | 94 | string? passwordHash = null; 95 | if (UserStore is IUserPasswordStore userPasswordStore) 96 | { 97 | passwordHash = await userPasswordStore.GetPasswordHashAsync(user, HttpContext.RequestAborted); 98 | } 99 | 100 | showRemoveButton = passwordHash is not null || currentLogins.Count > 1; 101 | 102 | if (HttpMethods.IsGet(HttpContext.Request.Method) && Action == LinkLoginCallbackAction) 103 | { 104 | await OnGetLinkLoginCallbackAsync(); 105 | } 106 | } 107 | 108 | private async Task OnSubmitAsync() 109 | { 110 | var result = await UserManager.RemoveLoginAsync(user, LoginProvider!, ProviderKey!); 111 | if (!result.Succeeded) 112 | { 113 | RedirectManager.RedirectToCurrentPageWithStatus("Error: The external login was not removed.", HttpContext); 114 | } 115 | 116 | await SignInManager.RefreshSignInAsync(user); 117 | RedirectManager.RedirectToCurrentPageWithStatus("The external login was removed.", HttpContext); 118 | } 119 | 120 | private async Task OnGetLinkLoginCallbackAsync() 121 | { 122 | var userId = await UserManager.GetUserIdAsync(user); 123 | var info = await SignInManager.GetExternalLoginInfoAsync(userId); 124 | if (info is null) 125 | { 126 | RedirectManager.RedirectToCurrentPageWithStatus("Error: Could not load external login info.", HttpContext); 127 | } 128 | 129 | var result = await UserManager.AddLoginAsync(user, info); 130 | if (!result.Succeeded) 131 | { 132 | RedirectManager.RedirectToCurrentPageWithStatus("Error: The external login was not added. External logins can only be associated with one account.", HttpContext); 133 | } 134 | 135 | // Clear the existing external cookie to ensure a clean login process 136 | await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); 137 | 138 | RedirectManager.RedirectToCurrentPageWithStatus("The external login was added.", HttpContext); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Layout/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | appearance: none; 3 | cursor: pointer; 4 | width: 3.5rem; 5 | height: 2.5rem; 6 | color: white; 7 | position: absolute; 8 | top: 0.5rem; 9 | right: 1rem; 10 | border: 1px solid rgba(255, 255, 255, 0.1); 11 | background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1); 12 | } 13 | 14 | .navbar-toggler:checked { 15 | background-color: rgba(255, 255, 255, 0.5); 16 | } 17 | 18 | .top-row { 19 | height: 3.5rem; 20 | background-color: rgba(0,0,0,0.4); 21 | } 22 | 23 | .navbar-brand { 24 | font-size: 1.1rem; 25 | } 26 | 27 | .bi { 28 | display: inline-block; 29 | position: relative; 30 | width: 1.25rem; 31 | height: 1.25rem; 32 | margin-right: 0.75rem; 33 | top: -1px; 34 | background-size: cover; 35 | } 36 | 37 | .bi-house-door-fill-nav-menu { 38 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E"); 39 | } 40 | 41 | .bi-plus-square-fill-nav-menu { 42 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E"); 43 | } 44 | 45 | .bi-list-nested-nav-menu { 46 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E"); 47 | } 48 | 49 | .bi-lock-nav-menu { 50 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z'/%3E%3C/svg%3E"); 51 | } 52 | 53 | .bi-person-nav-menu { 54 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person' viewBox='0 0 16 16'%3E%3Cpath d='M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10Z'/%3E%3C/svg%3E"); 55 | } 56 | 57 | .bi-person-badge-nav-menu { 58 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person-badge' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 2a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1h-3zM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0z'/%3E%3Cpath d='M4.5 0A2.5 2.5 0 0 0 2 2.5V14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V2.5A2.5 2.5 0 0 0 11.5 0h-7zM3 2.5A1.5 1.5 0 0 1 4.5 1h7A1.5 1.5 0 0 1 13 2.5v10.795a4.2 4.2 0 0 0-.776-.492C11.392 12.387 10.063 12 8 12s-3.392.387-4.224.803a4.2 4.2 0 0 0-.776.492V2.5z'/%3E%3C/svg%3E"); 59 | } 60 | 61 | .bi-person-fill-nav-menu { 62 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person-fill' viewBox='0 0 16 16'%3E%3Cpath d='M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z'/%3E%3C/svg%3E"); 63 | } 64 | 65 | .bi-arrow-bar-left-nav-menu { 66 | background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-arrow-bar-left' viewBox='0 0 16 16'%3E%3Cpath d='M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5ZM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5Z'/%3E%3C/svg%3E"); 67 | } 68 | 69 | .nav-item { 70 | font-size: 0.9rem; 71 | padding-bottom: 0.5rem; 72 | } 73 | 74 | .nav-item:first-of-type { 75 | padding-top: 1rem; 76 | } 77 | 78 | .nav-item:last-of-type { 79 | padding-bottom: 1rem; 80 | } 81 | 82 | .nav-item ::deep .nav-link { 83 | color: #d7d7d7; 84 | background: none; 85 | border: none; 86 | border-radius: 4px; 87 | height: 3rem; 88 | display: flex; 89 | align-items: center; 90 | line-height: 3rem; 91 | width: 100%; 92 | } 93 | 94 | .nav-item ::deep a.active { 95 | background-color: rgba(255,255,255,0.37); 96 | color: white; 97 | } 98 | 99 | .nav-item ::deep .nav-link:hover { 100 | background-color: rgba(255,255,255,0.1); 101 | color: white; 102 | } 103 | 104 | .nav-scrollable { 105 | display: none; 106 | } 107 | 108 | .navbar-toggler:checked ~ .nav-scrollable { 109 | display: block; 110 | } 111 | 112 | @media (min-width: 641px) { 113 | .navbar-toggler { 114 | display: none; 115 | } 116 | 117 | .nav-scrollable { 118 | /* Never collapse the sidebar for wide screens */ 119 | display: block; 120 | 121 | /* Allow sidebar to scroll for tall menus */ 122 | height: calc(100vh - 3.5rem); 123 | overflow-y: auto; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Register.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Register" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Text 5 | @using System.Text.Encodings.Web 6 | @using Microsoft.AspNetCore.Identity 7 | @using Microsoft.AspNetCore.WebUtilities 8 | @using AppStatServer.Data 9 | 10 | @inject UserManager UserManager 11 | @inject IUserStore UserStore 12 | @inject SignInManager SignInManager 13 | @inject IEmailSender EmailSender 14 | @inject ILogger Logger 15 | @inject NavigationManager NavigationManager 16 | @inject IdentityRedirectManager RedirectManager 17 | 18 | Register 19 | 20 |

Register

21 | 22 |
23 |
24 | 25 | 26 | 27 |

Create a new account.

28 |
29 | 30 |
31 | 32 | 33 | 34 |
35 |
36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 |
45 | 46 |
47 |
48 |
49 |
50 |

Use another service to register.

51 |
52 | 53 |
54 |
55 |
56 | 57 | @code { 58 | private IEnumerable? identityErrors; 59 | 60 | [SupplyParameterFromForm] 61 | private InputModel Input { get; set; } = new(); 62 | 63 | [SupplyParameterFromQuery] 64 | private string? ReturnUrl { get; set; } 65 | 66 | private string? Message => identityErrors is null ? null : $"Error: {string.Join(", ", identityErrors.Select(error => error.Description))}"; 67 | 68 | public async Task RegisterUser(EditContext editContext) 69 | { 70 | var user = CreateUser(); 71 | 72 | await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); 73 | var emailStore = GetEmailStore(); 74 | await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); 75 | var result = await UserManager.CreateAsync(user, Input.Password); 76 | 77 | if (!result.Succeeded) 78 | { 79 | identityErrors = result.Errors; 80 | return; 81 | } 82 | 83 | Logger.LogInformation("User created a new account with password."); 84 | 85 | var userId = await UserManager.GetUserIdAsync(user); 86 | var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); 87 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 88 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 89 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, 90 | new Dictionary { ["userId"] = userId, ["code"] = code, ["returnUrl"] = ReturnUrl }); 91 | 92 | await EmailSender.SendConfirmationLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl)); 93 | 94 | if (UserManager.Options.SignIn.RequireConfirmedAccount) 95 | { 96 | RedirectManager.RedirectTo( 97 | "Account/RegisterConfirmation", 98 | new() { ["email"] = Input.Email, ["returnUrl"] = ReturnUrl }); 99 | } 100 | 101 | await SignInManager.SignInAsync(user, isPersistent: false); 102 | RedirectManager.RedirectTo(ReturnUrl); 103 | } 104 | 105 | private ApplicationUser CreateUser() 106 | { 107 | try 108 | { 109 | return Activator.CreateInstance(); 110 | } 111 | catch 112 | { 113 | throw new InvalidOperationException($"Can't create an instance of '{nameof(ApplicationUser)}'. " + 114 | $"Ensure that '{nameof(ApplicationUser)}' is not an abstract class and has a parameterless constructor."); 115 | } 116 | } 117 | 118 | private IUserEmailStore GetEmailStore() 119 | { 120 | if (!UserManager.SupportsUserEmail) 121 | { 122 | throw new NotSupportedException("The default UI requires a user store with email support."); 123 | } 124 | return (IUserEmailStore)UserStore; 125 | } 126 | 127 | private sealed class InputModel 128 | { 129 | [Required] 130 | [EmailAddress] 131 | [Display(Name = "Email")] 132 | public string Email { get; set; } = ""; 133 | 134 | [Required] 135 | [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 136 | [DataType(DataType.Password)] 137 | [Display(Name = "Password")] 138 | public string Password { get; set; } = ""; 139 | 140 | [DataType(DataType.Password)] 141 | [Display(Name = "Confirm password")] 142 | [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 143 | public string ConfirmPassword { get; set; } = ""; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Sentry/Event.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace AppStatServer.Sentry; 4 | 5 | public class ExceptionValue 6 | { 7 | public string type { get; set; } 8 | public string value { get; set; } 9 | public string module { get; set; } 10 | public int thread_id { get; set; } 11 | } 12 | 13 | public class StacktraceFrame 14 | { 15 | public string function { get; set; } 16 | public bool in_app { get; set; } 17 | public string package { get; set; } 18 | public string instruction_addr { get; set; } 19 | public string addr_mode { get; set; } 20 | public string function_id { get; set; } 21 | public string filename { get; set; } 22 | public int? lineno { get; set; } 23 | public int? colno { get; set; } 24 | public string abs_path { get; set; } 25 | } 26 | 27 | public class StacktraceValue 28 | { 29 | public List? frames { get; set; } 30 | 31 | public override string ToString() 32 | { 33 | if (frames == null) 34 | return ""; 35 | return FormatStackTrace(frames); 36 | } 37 | 38 | public static string FormatStackTrace(List stackTraceFrames) 39 | { 40 | StringBuilder formattedStackTrace = new StringBuilder(); 41 | int frameIndex = 1; 42 | foreach (var frame in stackTraceFrames) 43 | { 44 | if (frameIndex == 1) 45 | { 46 | formattedStackTrace.AppendLine($"Exception in thread \"{frame.package}\" {frame.function}"); 47 | } 48 | else 49 | { 50 | formattedStackTrace.AppendLine($"\tat {frame.package}.{frame.function}({frame.filename}:{frame.lineno})"); 51 | } 52 | frameIndex++; 53 | } 54 | return formattedStackTrace.ToString(); 55 | } 56 | } 57 | 58 | public class ExceptionInfo 59 | { 60 | public List values { get; set; } 61 | } 62 | 63 | public class ThreadValue 64 | { 65 | public int id { get; set; } 66 | public string name { get; set; } 67 | public bool crashed { get; set; } 68 | public bool current { get; set; } 69 | public StacktraceValue stacktrace { get; set; } 70 | } 71 | 72 | public class Threads 73 | { 74 | public List values { get; set; } 75 | } 76 | 77 | public class CurrentCulture 78 | { 79 | public string name { get; set; } 80 | public string display_name { get; set; } 81 | public string calendar { get; set; } 82 | } 83 | 84 | public class DynamicCode 85 | { 86 | public bool Compiled { get; set; } 87 | public bool Supported { get; set; } 88 | } 89 | 90 | public class MemoryInfo 91 | { 92 | public int allocated_bytes { get; set; } 93 | public long high_memory_load_threshold_bytes { get; set; } 94 | public long total_available_memory_bytes { get; set; } 95 | public int finalization_pending_count { get; set; } 96 | public bool compacted { get; set; } 97 | public bool concurrent { get; set; } 98 | public List pause_durations { get; set; } 99 | } 100 | 101 | public class ThreadPoolInfo 102 | { 103 | public int min_worker_threads { get; set; } 104 | public int min_completion_port_threads { get; set; } 105 | public int max_worker_threads { get; set; } 106 | public int max_completion_port_threads { get; set; } 107 | public int available_worker_threads { get; set; } 108 | public int available_completion_port_threads { get; set; } 109 | } 110 | 111 | public class AppInfo 112 | { 113 | public string type { get; set; } 114 | public DateTime app_start_time { get; set; } 115 | public bool in_foreground { get; set; } 116 | } 117 | 118 | public class Device 119 | { 120 | public string type { get; set; } 121 | public string timezone { get; set; } 122 | public string timezone_display_name { get; set; } 123 | public DateTime boot_time { get; set; } 124 | } 125 | 126 | public class Os 127 | { 128 | public string type { get; set; } 129 | public string raw_description { get; set; } 130 | } 131 | 132 | public class Runtime 133 | { 134 | public string type { get; set; } 135 | public string name { get; set; } 136 | public string version { get; set; } 137 | public string raw_description { get; set; } 138 | public string identifier { get; set; } 139 | } 140 | 141 | public class TraceInfo 142 | { 143 | public string type { get; set; } 144 | public string span_id { get; set; } 145 | public string trace_id { get; set; } 146 | } 147 | 148 | public class Package 149 | { 150 | public string name { get; set; } 151 | public string version { get; set; } 152 | } 153 | 154 | public class SdkInfo 155 | { 156 | public List packages { get; set; } 157 | public string name { get; set; } 158 | public string version { get; set; } 159 | } 160 | 161 | public class Image 162 | { 163 | public string type { get; set; } 164 | public string debug_id { get; set; } 165 | public string debug_checksum { get; set; } 166 | public string debug_file { get; set; } 167 | public string code_id { get; set; } 168 | public string code_file { get; set; } 169 | } 170 | 171 | public class DebugMeta 172 | { 173 | public List images { get; set; } 174 | } 175 | 176 | public class Contexts 177 | { 178 | public CurrentCulture CurrentCulture { get; set; } 179 | public DynamicCode DynamicCode { get; set; } 180 | public MemoryInfo MemoryInfo { get; set; } 181 | public ThreadPoolInfo ThreadPoolInfo { get; set; } 182 | public AppInfo app { get; set; } 183 | public Device device { get; set; } 184 | public Os os { get; set; } 185 | public Runtime runtime { get; set; } 186 | public TraceInfo trace { get; set; } 187 | } 188 | 189 | public class User 190 | { 191 | public string ip_address { get; set; } 192 | public string id { get; set; } 193 | public string username { get; set; } 194 | } 195 | 196 | public class LogEntry 197 | { 198 | public string message { get; set; } 199 | } 200 | 201 | public class EventEntry 202 | { 203 | public string event_id { get; set; } 204 | public DateTime timestamp { get; set; } 205 | public LogEntry logentry { get; set; } 206 | public string platform { get; set; } 207 | public string release { get; set; } 208 | public ExceptionInfo exception { get; set; } 209 | public Threads threads { get; set; } 210 | public string level { get; set; } 211 | public Dictionary request { get; set; } 212 | public Contexts contexts { get; set; } 213 | public User user { get; set; } 214 | public string environment { get; set; } 215 | public SdkInfo sdk { get; set; } 216 | public DebugMeta debug_meta { get; set; } 217 | } -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/Manage/EnableAuthenticator.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/Manage/EnableAuthenticator" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Globalization 5 | @using System.Text 6 | @using System.Text.Encodings.Web 7 | @using Microsoft.AspNetCore.Identity 8 | @using AppStatServer.Data 9 | 10 | @inject UserManager UserManager 11 | @inject IdentityUserAccessor UserAccessor 12 | @inject UrlEncoder UrlEncoder 13 | @inject IdentityRedirectManager RedirectManager 14 | @inject ILogger Logger 15 | 16 | Configure authenticator app 17 | 18 | @if (recoveryCodes is not null) 19 | { 20 | 21 | } 22 | else 23 | { 24 | 25 |

Configure authenticator app

26 |
27 |

To use an authenticator app go through the following steps:

28 |
    29 |
  1. 30 |

    31 | Download a two-factor authenticator app like Microsoft Authenticator for 32 | Android and 33 | iOS or 34 | Google Authenticator for 35 | Android and 36 | iOS. 37 |

    38 |
  2. 39 |
  3. 40 |

    Scan the QR Code or enter this key @sharedKey into your two factor authenticator app. Spaces and casing do not matter.

    41 | 42 |
    43 |
    44 |
  4. 45 |
  5. 46 |

    47 | Once you have scanned the QR code or input the key above, your two factor authentication app will provide you 48 | with a unique code. Enter the code in the confirmation box below. 49 |

    50 |
    51 |
    52 | 53 | 54 |
    55 | 56 | 57 | 58 |
    59 | 60 | 61 |
    62 |
    63 |
    64 |
  6. 65 |
66 |
67 | } 68 | 69 | @code { 70 | private const string AuthenticatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6"; 71 | 72 | private string? message; 73 | private ApplicationUser user = default!; 74 | private string? sharedKey; 75 | private string? authenticatorUri; 76 | private IEnumerable? recoveryCodes; 77 | 78 | [CascadingParameter] 79 | private HttpContext HttpContext { get; set; } = default!; 80 | 81 | [SupplyParameterFromForm] 82 | private InputModel Input { get; set; } = new(); 83 | 84 | protected override async Task OnInitializedAsync() 85 | { 86 | user = await UserAccessor.GetRequiredUserAsync(HttpContext); 87 | 88 | await LoadSharedKeyAndQrCodeUriAsync(user); 89 | } 90 | 91 | private async Task OnValidSubmitAsync() 92 | { 93 | // Strip spaces and hyphens 94 | var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty); 95 | 96 | var is2faTokenValid = await UserManager.VerifyTwoFactorTokenAsync( 97 | user, UserManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode); 98 | 99 | if (!is2faTokenValid) 100 | { 101 | message = "Error: Verification code is invalid."; 102 | return; 103 | } 104 | 105 | await UserManager.SetTwoFactorEnabledAsync(user, true); 106 | var userId = await UserManager.GetUserIdAsync(user); 107 | Logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId); 108 | 109 | message = "Your authenticator app has been verified."; 110 | 111 | if (await UserManager.CountRecoveryCodesAsync(user) == 0) 112 | { 113 | recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10); 114 | } 115 | else 116 | { 117 | RedirectManager.RedirectToWithStatus("Account/Manage/TwoFactorAuthentication", message, HttpContext); 118 | } 119 | } 120 | 121 | private async ValueTask LoadSharedKeyAndQrCodeUriAsync(ApplicationUser user) 122 | { 123 | // Load the authenticator key & QR code URI to display on the form 124 | var unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user); 125 | if (string.IsNullOrEmpty(unformattedKey)) 126 | { 127 | await UserManager.ResetAuthenticatorKeyAsync(user); 128 | unformattedKey = await UserManager.GetAuthenticatorKeyAsync(user); 129 | } 130 | 131 | sharedKey = FormatKey(unformattedKey!); 132 | 133 | var email = await UserManager.GetEmailAsync(user); 134 | authenticatorUri = GenerateQrCodeUri(email!, unformattedKey!); 135 | } 136 | 137 | private string FormatKey(string unformattedKey) 138 | { 139 | var result = new StringBuilder(); 140 | int currentPosition = 0; 141 | while (currentPosition + 4 < unformattedKey.Length) 142 | { 143 | result.Append(unformattedKey.AsSpan(currentPosition, 4)).Append(' '); 144 | currentPosition += 4; 145 | } 146 | if (currentPosition < unformattedKey.Length) 147 | { 148 | result.Append(unformattedKey.AsSpan(currentPosition)); 149 | } 150 | 151 | return result.ToString().ToLowerInvariant(); 152 | } 153 | 154 | private string GenerateQrCodeUri(string email, string unformattedKey) 155 | { 156 | return string.Format( 157 | CultureInfo.InvariantCulture, 158 | AuthenticatorUriFormat, 159 | UrlEncoder.Encode("Microsoft.AspNetCore.Identity.UI"), 160 | UrlEncoder.Encode(email), 161 | unformattedKey); 162 | } 163 | 164 | private sealed class InputModel 165 | { 166 | [Required] 167 | [StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)] 168 | [DataType(DataType.Text)] 169 | [Display(Name = "Verification Code")] 170 | public string Code { get; set; } = ""; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /Source/AppStatServer/AppStatServer/AppStatServer/Components/Account/Pages/ExternalLogin.razor: -------------------------------------------------------------------------------- 1 | @page "/Account/ExternalLogin" 2 | 3 | @using System.ComponentModel.DataAnnotations 4 | @using System.Security.Claims 5 | @using System.Text 6 | @using System.Text.Encodings.Web 7 | @using Microsoft.AspNetCore.Identity 8 | @using Microsoft.AspNetCore.WebUtilities 9 | @using AppStatServer.Data 10 | 11 | @inject SignInManager SignInManager 12 | @inject UserManager UserManager 13 | @inject IUserStore UserStore 14 | @inject IEmailSender EmailSender 15 | @inject NavigationManager NavigationManager 16 | @inject IdentityRedirectManager RedirectManager 17 | @inject ILogger Logger 18 | 19 | Register 20 | 21 | 22 |

Register

23 |

Associate your @ProviderDisplayName account.

24 |
25 | 26 |
27 | You've successfully authenticated with @ProviderDisplayName. 28 | Please enter an email address for this site below and click the Register button to finish 29 | logging in. 30 |
31 | 32 |
33 |
34 | 35 | 36 | 37 |
38 | 39 | 40 | 41 |
42 | 43 |
44 |
45 |
46 | 47 | @code { 48 | public const string LoginCallbackAction = "LoginCallback"; 49 | 50 | private string? message; 51 | private ExternalLoginInfo externalLoginInfo = default!; 52 | 53 | [CascadingParameter] 54 | private HttpContext HttpContext { get; set; } = default!; 55 | 56 | [SupplyParameterFromForm] 57 | private InputModel Input { get; set; } = new(); 58 | 59 | [SupplyParameterFromQuery] 60 | private string? RemoteError { get; set; } 61 | 62 | [SupplyParameterFromQuery] 63 | private string? ReturnUrl { get; set; } 64 | 65 | [SupplyParameterFromQuery] 66 | private string? Action { get; set; } 67 | 68 | private string? ProviderDisplayName => externalLoginInfo.ProviderDisplayName; 69 | 70 | protected override async Task OnInitializedAsync() 71 | { 72 | if (RemoteError is not null) 73 | { 74 | RedirectManager.RedirectToWithStatus("Account/Login", $"Error from external provider: {RemoteError}", HttpContext); 75 | } 76 | 77 | var info = await SignInManager.GetExternalLoginInfoAsync(); 78 | if (info is null) 79 | { 80 | RedirectManager.RedirectToWithStatus("Account/Login", "Error loading external login information.", HttpContext); 81 | } 82 | 83 | externalLoginInfo = info; 84 | 85 | if (HttpMethods.IsGet(HttpContext.Request.Method)) 86 | { 87 | if (Action == LoginCallbackAction) 88 | { 89 | await OnLoginCallbackAsync(); 90 | return; 91 | } 92 | 93 | // We should only reach this page via the login callback, so redirect back to 94 | // the login page if we get here some other way. 95 | RedirectManager.RedirectTo("Account/Login"); 96 | } 97 | } 98 | 99 | private async Task OnLoginCallbackAsync() 100 | { 101 | // Sign in the user with this external login provider if the user already has a login. 102 | var result = await SignInManager.ExternalLoginSignInAsync( 103 | externalLoginInfo.LoginProvider, 104 | externalLoginInfo.ProviderKey, 105 | isPersistent: false, 106 | bypassTwoFactor: true); 107 | 108 | if (result.Succeeded) 109 | { 110 | Logger.LogInformation( 111 | "{Name} logged in with {LoginProvider} provider.", 112 | externalLoginInfo.Principal.Identity?.Name, 113 | externalLoginInfo.LoginProvider); 114 | RedirectManager.RedirectTo(ReturnUrl); 115 | } 116 | else if (result.IsLockedOut) 117 | { 118 | RedirectManager.RedirectTo("Account/Lockout"); 119 | } 120 | 121 | // If the user does not have an account, then ask the user to create an account. 122 | if (externalLoginInfo.Principal.HasClaim(c => c.Type == ClaimTypes.Email)) 123 | { 124 | Input.Email = externalLoginInfo.Principal.FindFirstValue(ClaimTypes.Email) ?? ""; 125 | } 126 | } 127 | 128 | private async Task OnValidSubmitAsync() 129 | { 130 | var emailStore = GetEmailStore(); 131 | var user = CreateUser(); 132 | 133 | await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None); 134 | await emailStore.SetEmailAsync(user, Input.Email, CancellationToken.None); 135 | 136 | var result = await UserManager.CreateAsync(user); 137 | if (result.Succeeded) 138 | { 139 | result = await UserManager.AddLoginAsync(user, externalLoginInfo); 140 | if (result.Succeeded) 141 | { 142 | Logger.LogInformation("User created an account using {Name} provider.", externalLoginInfo.LoginProvider); 143 | 144 | var userId = await UserManager.GetUserIdAsync(user); 145 | var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); 146 | code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); 147 | 148 | var callbackUrl = NavigationManager.GetUriWithQueryParameters( 149 | NavigationManager.ToAbsoluteUri("Account/ConfirmEmail").AbsoluteUri, 150 | new Dictionary { ["userId"] = userId, ["code"] = code }); 151 | await EmailSender.SendConfirmationLinkAsync(user, Input.Email, HtmlEncoder.Default.Encode(callbackUrl)); 152 | 153 | // If account confirmation is required, we need to show the link if we don't have a real email sender 154 | if (UserManager.Options.SignIn.RequireConfirmedAccount) 155 | { 156 | RedirectManager.RedirectTo("Account/RegisterConfirmation", new() { ["email"] = Input.Email }); 157 | } 158 | 159 | await SignInManager.SignInAsync(user, isPersistent: false, externalLoginInfo.LoginProvider); 160 | RedirectManager.RedirectTo(ReturnUrl); 161 | } 162 | } 163 | 164 | message = $"Error: {string.Join(",", result.Errors.Select(error => error.Description))}"; 165 | } 166 | 167 | private ApplicationUser CreateUser() 168 | { 169 | try 170 | { 171 | return Activator.CreateInstance(); 172 | } 173 | catch 174 | { 175 | throw new InvalidOperationException($"Can't create an instance of '{nameof(ApplicationUser)}'. " + 176 | $"Ensure that '{nameof(ApplicationUser)}' is not an abstract class and has a parameterless constructor"); 177 | } 178 | } 179 | 180 | private IUserEmailStore GetEmailStore() 181 | { 182 | if (!UserManager.SupportsUserEmail) 183 | { 184 | throw new NotSupportedException("The default UI requires a user store with email support."); 185 | } 186 | return (IUserEmailStore)UserStore; 187 | } 188 | 189 | private sealed class InputModel 190 | { 191 | [Required] 192 | [EmailAddress] 193 | public string Email { get; set; } = ""; 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | /Source/AppStatServer/AppStatServer/AppStatServer/appstat.db 400 | /Source/AppStatServer/AppStatServer/AppStatServer/appsettings.json 401 | --------------------------------------------------------------------------------