Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Various hotfixes and improvements #119

Merged
merged 12 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/FocusApp.Client/AppShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using FocusApp.Client.Views.Social;
using SimpleToolkit.SimpleShell.Extensions;
using Microsoft.Maui;
using FocusApp.Client.Views.Settings;

namespace FocusApp.Client;

Expand Down
9 changes: 2 additions & 7 deletions src/FocusApp.Client/FocusApp.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<MauiIcon Include="Resources\AppIcon\appicon.svg" Color="#BB8EFF" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#BB8EFF" BaseSize="128,128" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#BB8EFF" BaseSize="456, 456" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
Expand Down Expand Up @@ -105,11 +105,6 @@
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidSigningKeyStore>ff.keystore</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>MyAppkey</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>2x4WFl6FUbU3</AndroidSigningKeyPass>
<AndroidSigningStorePass>2x4WFl6FUbU3</AndroidSigningStorePass>
</PropertyGroup>

</Project>
66 changes: 64 additions & 2 deletions src/FocusApp.Client/Helpers/AuthenticationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Auth0.OidcClient;
using FocusApp.Client.Views;
using FocusApp.Shared.Models;

namespace FocusApp.Client.Helpers;
Expand All @@ -8,22 +10,25 @@ internal interface IAuthenticationService
{
string? Auth0Id { get; set; }
string? Email { get; set; }
string? AuthToken { get; set; }
User? CurrentUser { get; set; }
Island? SelectedIsland { get; set; }
Pet? SelectedPet { get; set; }
Badge? SelectedBadge { get; set; }
Decor? SelectedDecor { get; set; }
int Balance { get; set; }

event PropertyChangedEventHandler? PropertyChanged;

void ClearUser();
Task Logout(IAuth0Client auth0Client);
void PopulateWithUserData(User user);
}

public class AuthenticationService : INotifyPropertyChanged, IAuthenticationService
{
public event PropertyChangedEventHandler? PropertyChanged;
public string? Auth0Id { get; set; } = "";
public string? Email { get; set; } = "";
public string? AuthToken { get; set; } = "";

private User? _currentUser;
public User? CurrentUser
Expand All @@ -32,6 +37,13 @@ public User? CurrentUser
set => SetProperty(ref _currentUser, value);
}

private int? _balance;
public int Balance
{
get => _balance ?? 0;
set => SetProperty(ref _balance, value);
}

private Island? _selectedIsland;
public Island? SelectedIsland
{
Expand Down Expand Up @@ -60,6 +72,56 @@ public Decor? SelectedDecor
set => SetProperty(ref _selectedDecor, value);
}

/// <summary>
/// Remove user data from auth service and secure storage,
/// navigate to the login page,and
/// log the user out using the auth0 client.
/// </summary>
/// <remarks>
/// Note that the auth0Client.LogoutAsync needs to happen after the navigation
/// to LoginPage due to an issue with Maui navigation handlers.
/// Details here: https://github.com/dotnet/maui/issues/11259
/// </remarks>
public async Task Logout(IAuth0Client auth0Client)
{
ClearUser();

SecureStorage.Default.Remove("id_token");
SecureStorage.Default.Remove("access_token");

await Shell.Current.GoToAsync("///" + nameof(LoginPage));

await auth0Client.LogoutAsync();
}

/// <summary>
/// Remove all data for the "logged in" user.
/// </summary>
public void ClearUser()
{
Auth0Id = string.Empty;
Email = string.Empty;
Balance = 0;
CurrentUser = null;
SelectedIsland = null;
SelectedPet = null;
SelectedBadge = null;
SelectedDecor = null;
}

public void PopulateWithUserData(User user)
{
CurrentUser = user;

Auth0Id = user.Auth0Id;
Email = user.Email;
Balance = user.Balance;
SelectedBadge = user.SelectedBadge;
SelectedDecor = user.SelectedDecor;
SelectedIsland = user.SelectedIsland;
SelectedPet = user.SelectedPet;
}

#region Property Changed Notification Logic

private void SetProperty<T>(ref T backingStore, in T value, [CallerMemberName] in string propertyname = "")
Expand Down
7 changes: 7 additions & 0 deletions src/FocusApp.Client/Helpers/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public UserManager(string domain, string clientId)
_clientId = clientId;
}

public async Task<string?> GetIdToken()
{
return await SecureStorage.Default.GetAsync("id_token");
}



public async Task<ClaimsPrincipal> GetAuthenticatedUser()
{
ClaimsPrincipal user = null;
Expand Down
2 changes: 1 addition & 1 deletion src/FocusApp.Client/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static IServiceCollection RegisterRefitClient(this IServiceCollection se
{
services
.AddRefitClient<IAPIClient>()
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://10.0.2.2:5223"));
.ConfigureHttpClient(c => c.BaseAddress = new Uri("http://test.zenpxl.com:25565"));

return services;
}
Expand Down
12 changes: 6 additions & 6 deletions src/FocusApp.Client/Methods/Shop/PurchaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<Unit> Handle(Command command, CancellationToken cancellationTo
});

// Update the user's balance on the local database
user.Balance = _authenticationService.CurrentUser.Balance;
user.Balance = _authenticationService.Balance;
}
catch (Exception ex)
{
Expand All @@ -61,7 +61,7 @@ await _client.AddUserPet(new AddUserPetCommand
{
UserId = _authenticationService.CurrentUser.Id,
PetId = command.Item.Id,
UpdatedBalance = _authenticationService.CurrentUser.Balance,
UpdatedBalance = _authenticationService.Balance,
});
}
catch (Exception ex)
Expand All @@ -82,7 +82,7 @@ await _client.AddUserPet(new AddUserPetCommand
});

// Update the user's balance on the local database
user.Balance = _authenticationService.CurrentUser.Balance;
user.Balance = _authenticationService.Balance;
}
catch (Exception ex)
{
Expand All @@ -97,7 +97,7 @@ await _client.AddUserDecor(new AddUserDecorCommand
{
UserId = _authenticationService.CurrentUser.Id,
DecorId = command.Item.Id,
UpdatedBalance = _authenticationService.CurrentUser.Balance,
UpdatedBalance = _authenticationService.Balance,
});
}
catch (Exception ex)
Expand All @@ -117,7 +117,7 @@ await _client.AddUserDecor(new AddUserDecorCommand
});

// Update the user's balance on the local database
user.Balance = _authenticationService.CurrentUser.Balance;
user.Balance = _authenticationService.Balance;
}
catch (Exception ex)
{
Expand All @@ -131,7 +131,7 @@ await _client.AddUserIsland(new AddUserIslandCommand
{
UserId = _authenticationService.CurrentUser.Id,
IslandId = command.Item.Id,
UpdatedBalance = _authenticationService.CurrentUser.Balance,
UpdatedBalance = _authenticationService.Balance,
});
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion src/FocusApp.Client/Methods/User/AddSessionToUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task Handle(

UserSession session = CreateSession(query, user);

_authService.CurrentUser.Balance += session.CurrencyEarned;
_authService.Balance += session.CurrencyEarned;

// If a user isn't found, don't track the session
if (user is null) return;
Expand Down
8 changes: 1 addition & 7 deletions src/FocusApp.Client/Methods/User/GetPersistentUserLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ public async Task<Result> Handle(Query query, CancellationToken cancellationToke
throw new InvalidOperationException("User not found in the local database.");

// Set session variables
_authenticationService.Auth0Id = user.Auth0Id;
_authenticationService.CurrentUser = user;

_authenticationService.SelectedBadge = user.SelectedBadge;
_authenticationService.SelectedDecor = user.SelectedDecor;
_authenticationService.SelectedIsland = user.SelectedIsland;
_authenticationService.SelectedPet = user.SelectedPet;
_authenticationService.PopulateWithUserData(user);

return new Result
{
Expand Down
10 changes: 2 additions & 8 deletions src/FocusApp.Client/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ZenPxl.FocusFriends" android:versionCode="1" android:versionName="Development Test">
<application android:allowBackup="true"
android:icon="@mipmap/appicon"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:enableOnBackInvokedCallback="true"
android:label="FocusApp"></application>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ZenPxl.FocusFriends" android:versionCode="1" android:versionName="1.0">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:usesCleartextTraffic="true" android:enableOnBackInvokedCallback="true" android:label="Focus Friends"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<queries>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
Expand Down
51 changes: 49 additions & 2 deletions src/FocusApp.Client/Resources/AppIcon/appicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading