Started working on data collection service

This commit is contained in:
BOT Alex 2023-05-28 02:51:04 +02:00
parent f6956dfaa0
commit 6cb976fc11
10 changed files with 206 additions and 31 deletions

View File

@ -5,10 +5,11 @@
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@inject NavigationManager NavManager
@inject ISnackbar Snackbar
@inject DataCollectorService DCollector
<MudLayout Class="overflow-hidden">
<MudAppBar Elevation="1">
<MudButton Variant="Variant.Filled" Color="Color.Primary" Disabled=true>Debug button</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" Disabled=false OnClick="DebugButton">Debug button</MudButton>
<MudSpacer />
@if (!isLoggedIn)
{
@ -120,6 +121,14 @@
User tempUser = new User();
private string ipAddress;
protected async Task DebugButton()
{
ipAddress = (await DCollector.GetBrowserInfo()).ToString();
Console.WriteLine(ipAddress);
}
#region Drawers and overlays
void ToggleDrawer()
{

View File

@ -18,43 +18,49 @@
<MudContainer Class="justify-center">
<MudContainer Style="max-width: 400px; width: 100vw; min-width: 250px;">
<MudPaper Style="height: 80vh; flex-direction: column-reverse;" Class="mt-7 bottom-start">
@if (messages != null)
@if (!isFakeLoading)
{
@for (int i = 0; i < messages.Length; i++)
@if (messages != null)
{
Message message = messages[i];
@for (int i = 0; i < messages.Length; i++)
{
Message message = messages[i];
if (Program.LoggedInName != null && Program.LoggedInName == message.Name)
{
<MudStack Class="px-4 py-2 d-flex" Justify="Justify.FlexEnd" Row="true" AlignItems="AlignItems.End">
<MudStack>
<MudPaper Style="max-width: 320px ;overflow-wrap: break-word;" Class="mud-theme-primary" Elevation="4">
<MudText Typo="Typo.body1" Class="px-2 pt-2" Style="max-width: 320px;">@message.Content</MudText>
<MudText Class="pa-1 pr-2" Align="Align.End" Style="font-size: 10px;">@("@" + message.Name)</MudText>
</MudPaper>
<MudText Class="mt-n3" Align="Align.End" Style="font-size: 10px;">@(DateTimeOffset.FromUnixTimeSeconds(message.DatePosted).ToString("dd/MM HH:mm", danishCulture))</MudText>
</MudStack>
</MudStack>
}
else
{
<MudStack Class="px-4 py-2" Row="true">
<MudStack>
<MudPaper Style="max-width: 320px; overflow-wrap: break-word;" Elevation="4">
<MudText Typo="Typo.body1" Class="px-2 pt-2" Style="max-width: 320px;">@message.Content</MudText>
<MudText Class="pa-1" Style="font-size: 10px;">@("@" + message.Name)</MudText>
</MudPaper>
<MudText Class="mt-n3 pl-1" Style="font-size: 10px;">@(DateTimeOffset.FromUnixTimeSeconds(message.DatePosted).ToString("dd/MM HH:mm", danishCulture))</MudText>
</MudStack>
</MudStack>
if (Program.LoggedInName != null && Program.LoggedInName == message.Name)
{
<MudStack Class="px-4 py-2 d-flex" Justify="Justify.FlexEnd" Row="true" AlignItems="AlignItems.End">
<MudStack>
<MudPaper Style="max-width: 320px ;overflow-wrap: break-word;" Class="mud-theme-primary" Elevation="4">
<MudText Typo="Typo.body1" Class="px-2 pt-2" Style="max-width: 320px;">@message.Content</MudText>
<MudText Class="pa-1 pr-2" Align="Align.End" Style="font-size: 10px;">@("@" + message.Name)</MudText>
</MudPaper>
<MudText Class="mt-n3" Align="Align.End" Style="font-size: 10px;">@(DateTimeOffset.FromUnixTimeSeconds(message.DatePosted).ToString("dd/MM HH:mm", danishCulture))</MudText>
</MudStack>
</MudStack>
}
else
{
<MudStack Class="px-4 py-2" Row="true">
<MudStack>
<MudPaper Style="max-width: 320px; overflow-wrap: break-word;" Elevation="4">
<MudText Typo="Typo.body1" Class="px-2 pt-2" Style="max-width: 320px;">@message.Content</MudText>
<MudText Class="pa-1" Style="font-size: 10px;">@("@" + message.Name)</MudText>
</MudPaper>
<MudText Class="mt-n3 pl-1" Style="font-size: 10px;">@(DateTimeOffset.FromUnixTimeSeconds(message.DatePosted).ToString("dd/MM HH:mm", danishCulture))</MudText>
</MudStack>
</MudStack>
}
}
}
}
else
{
<MudProgressCircular Class="align-self-center ma-auto" Size="Size.Large" Indeterminate="true" />
}
</MudPaper>
<MudContainer Class="d-flex pa-0 mb-n1">
<MudTextField Class="my-1" HelperText="Messages cannot be deleted!" HelperTextOnFocus=true Counter="25" @bind-Value="TextValue" MaxLength="32" Immediate="true" Validation="@(new Func<string, IEnumerable<string>>(MaxCharacters))" Disabled="@(Program.LoggedInName == null)" Label="@((Program.LoggedInName == null) ? "Sign-in to send messages" : "Message")" Variant="Variant.Filled" AdornmentColor="@Color.Primary" Margin="Margin.Dense"></MudTextField>
<MudTextField Class="my-1" HelperText="Messages cannot be deleted!" HelperTextOnFocus=true Counter="32" @bind-Value="TextValue" MaxLength="32" Immediate="true" Validation="@(new Func<string, IEnumerable<string>>(MaxCharacters))" Disabled="@(Program.LoggedInName == null)" Label="@((Program.LoggedInName == null) ? "Sign-in to send messages" : "Message")" Variant="Variant.Filled" AdornmentColor="@Color.Primary" Margin="Margin.Dense"></MudTextField>
<MudButton Class="mt-1 mb-7" Variant="Variant.Filled" Color="Color.Primary" Disabled="@(Program.LoggedInName == null || isSending)" OnClick="SendMessage">
@if (isSending)
{
@ -74,6 +80,7 @@
string TextValue = "";
bool isSending = false;
CultureInfo danishCulture = new CultureInfo("da-DK");
bool isFakeLoading = true;
async void SendMessage()
{
@ -115,6 +122,9 @@
messages = await messageService.GetMessages();
StartLoop();
await Task.Delay(2000);
isFakeLoading = false;
}
bool isLooping = false;

View File

@ -0,0 +1,73 @@
@page "/Privacy"
<style>
.unreadable {
font-family: 'Comic Sans MS'
}
</style>
<div class="unreadable">
Privacy Policy for Otakians Social Media Platform
<br /><br />
Effective Date: May 28, 2023
<br /><br />
This Privacy Policy explains how Otakians ("we," "us," or "our") collects, uses, and protects the personal information of users ("you" or "users") on the Otakians social media platform (the "Platform"). We are committed to protecting your privacy and ensuring the security of your personal information. By using the Platform, you consent to the data practices described in this Privacy Policy.
<br /><br />
<strong>1. Information We Collect</strong>
<br /><br />
1.1 Personal Information: When you create an account on the Platform, we may collect personal information, such as your name, email address, username, profile picture, and any other information you choose to provide.
<br /><br />
1.2 Usage Information: We may collect information about your use of the Platform, including your IP address, device information, browser type, operating system, and the pages you visit on the Platform.
<br /><br />
1.3 Cookies and Similar Technologies: We may use cookies and similar technologies to collect information about your interactions with the Platform. This information may include your preferences, browsing history, and other usage data.
<br /><br />
<strong>2. Use of Collected Information</strong>
<br /><br />
2.1 Providing and Improving the Platform: We use the collected information to operate, maintain, and improve the Platform, including providing personalized content, analyzing user trends, and enhancing user experience.
<br /><br />
2.2 Communication: We may use your email address or other contact information to send you important notifications, updates, or promotional materials related to the Platform. You can opt-out of receiving promotional emails by following the unsubscribe instructions provided in the email.
<br /><br />
2.3 Aggregated Data: We may aggregate and anonymize the collected information for statistical or analytical purposes. This aggregated data does not personally identify you and may be shared with third parties for various purposes, including research and marketing.
<br /><br />
<strong>3. Data Retention</strong>
<br /><br />
We will retain your personal information for as long as necessary to fulfill the purposes outlined in this Privacy Policy, unless a longer retention period is required or permitted by law. We will also retain and use your information as necessary to comply with our legal obligations, resolve disputes, and enforce our agreements.
<br /><br />
4. Data Sharing and Disclosure
<br /><br />
4.1 Service Providers: We may engage third-party service providers to perform certain functions on our behalf, such as hosting, data analysis, and customer support. These service providers may have access to your personal information only to the extent necessary to perform their functions and are obligated to maintain the confidentiality and security of your information.
<br /><br />
4.2 Legal Requirements: We may disclose your personal information if required by law, regulation, or legal process, or if we believe it is necessary to protect the rights, property, or safety of Otakians, its users, or others.
<br /><br />
4.3 Business Transfers: In the event of a merger, acquisition, or sale of all or a portion of our assets, your personal information may be transferred as part of the transaction. We will notify you via email or prominent notice on the Platform of any such change in ownership or control of your personal information.
<br /><br />
<strong>5. Data Security</strong>
<br /><br />
We implement reasonable security measures to protect your personal information from unauthorized access, disclosure, alteration, or destruction. However, please note that no method of transmission over the internet or electronic storage is 100% secure, and we cannot guarantee absolute security.
<br /><br />
6. International Data Transfers
<br /><br />
As an international platform, your information may be transferred to and stored on servers located in countries outside of your country of residence. By using the Platform, you consent to the transfer of your information to these countries, which may have different data protection laws than your country.
<br /><br />
<strong>7. Children's Privacy</strong>
<br /><br />
The Platform is not intended for children under the age of 13. We do not knowingly collect personal information from children under
<br /><br />
13. If you believe that we have inadvertently collected personal information from a child under 13, please contact us, and we will promptly delete such information.
<br /><br />
<strong>8. Your Rights</strong>
<br /><br />
You have certain rights regarding your personal information, including the right to access, correct, update, or delete your information. You may also have the right to restrict or object to certain processing activities. To exercise these rights, please contact us using the information provided below.
<br /><br />
<strong>9. Contact Us</strong>
<br /><br />
If you have any questions, concerns, or requests regarding this Privacy Policy or the handling of your personal information, please contact us at:
<br /><br />
Email: [Insert contact email]
<br />
Address: [Insert address]
<br /><br />
We may update this Privacy Policy from time to time, and any changes will be posted on the Platform. Please review this Privacy Policy periodically for any updates or modifications.
<br /><br />
By using the Otakians Platform, you acknowledge that you have read, understood, and agreed to this Privacy Policy.
</div>

View File

@ -7,6 +7,7 @@ using System;
using System.Security.Cryptography;
using System.Text;
using MudBlazor;
using Otakians.Services;
internal class Program
{
@ -25,6 +26,7 @@ internal class Program
config.JsonSerializerOptions.WriteIndented = true); // local storage
builder.Services.AddScoped<MessageService>();
builder.Services.AddScoped<DataCollectorService>();
await builder.Build().RunAsync();
}

View File

@ -2,7 +2,6 @@
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},

View File

@ -0,0 +1,59 @@
using DataStructs;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Threading.Tasks;
using System;
namespace Otakians.Services
{
public class DataCollectorService
{
private readonly IJSRuntime jsRuntime;
private readonly NavigationManager navigationManager;
public DataCollectorService(IJSRuntime jsRuntime, NavigationManager navigation)
{
this.jsRuntime = jsRuntime;
this.navigationManager = navigation;
}
public async Task<string> GetIPAddress()
{
return await jsRuntime.InvokeAsync<string>("getIPAddress");
}
public async Task<BrowserInfo> GetBrowserInfo()
{
var browserInfo = await jsRuntime.InvokeAsync<BrowserInfo>("getBrowserInfo");
return browserInfo;
}
}
}
namespace DataStructs
{
public class BrowserInfo
{
public string? BrowserType { get; set; }
public string? BrowserVersion { get; set; }
public string? OperatingSystem { get; set; }
public string? DeviceType { get; set; }
public string? ScreenResolution { get; set; }
public string? LanguageSettings { get; set; }
public string? Timezone { get; set; }
public string? UserAgent { get; set; }
public override string ToString()
{
return $"Browser Type: {BrowserType}\n" +
$"Browser Version: {BrowserVersion}\n" +
$"Operating System: {OperatingSystem}\n" +
$"Device Type: {DeviceType}\n" +
$"Screen Resolution: {ScreenResolution}\n" +
$"Language Settings: {LanguageSettings}\n" +
$"Timezone: {Timezone}\n" +
$"User Agent: {UserAgent}";
}
}
}

View File

@ -7,7 +7,7 @@ using static Otakians.Pages.Chatting;
public class MessageService
{
private readonly HttpClient _httpClient;
private const string ApiUrl = "https://globalchat-4a89f-default-rtdb.europe-west1.firebasedatabase.app/Database.json";
private const string ApiUrl = "https://globalchat-4a89f-default-rtdb.europe-west1.firebasedatabase.app/Database/Messages.json";
public MessageService(HttpClient httpClient)
{

View File

@ -6,5 +6,6 @@
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using Otakians
@using Otakians.Services
@using MudBlazor
@using System.Text.Json;

View File

@ -29,6 +29,7 @@
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="/jsFunctions.js"></script>
</body>
</html>

View File

@ -0,0 +1,21 @@
function getIPAddress() {
return new Promise((resolve, reject) => {
fetch('https://api.ipify.org/?format=json')
.then(response => response.json())
.then(data => resolve(data.ip))
.catch(error => reject(error));
});
}
function getBrowserInfo() {
return {
browserType: navigator.userAgent,
browserVersion: navigator.appVersion,
operatingSystem: navigator.platform,
deviceType: /Mobile/.test(navigator.userAgent) ? "Mobile" : "Desktop",
screenResolution: window.screen.width + "x" + window.screen.height,
languageSettings: navigator.language,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
userAgent: navigator.userAgent
};
}