Implement stub endpoints and stub login logic
continuous-integration/drone/push Build is passing Details

pull/40/head
Maxime BATISTA 2 years ago
parent 6ac6c731d0
commit fe44bf737d

@ -1,17 +1,28 @@
namespace ShoopNCook; namespace ShoopNCook;
using ShoopNCook.Pages; using ShoopNCook.Pages;
using Models; using Models;
using Models.Endpoint;
using LocalEndpoint;
public partial class App : Application public partial class App : Application, ConnectionObserver
{ {
private IEndpoint endpoint = new LocalEndpoint();
public App() public App()
{ {
InitializeComponent(); InitializeComponent();
Shell main = new ConnectAppShell();
main.GoToAsync("//Splash"); Shell shell = new ConnectAppShell(this, endpoint.AccountManager);
MainPage = main; shell.GoToAsync("//Splash");
MainPage = shell;
} }
public void OnAccountConnected(Account account)
{
Shell shell = new MainAppShell(account);
shell.GoToAsync("//MainPage");
MainPage = shell;
}
} }

@ -19,13 +19,11 @@
<ShellContent <ShellContent
x:Name="LoginPage" x:Name="LoginPage"
Title="Login" Title="Login"
ContentTemplate="{DataTemplate pages:LoginPage}" Route="Login"/>
Route="LoginPage"/>
<ShellContent <ShellContent
x:Name="RegisterPage" x:Name="RegisterPage"
Title="Register" Title="Register"
ContentTemplate="{DataTemplate pages:RegisterPage}" Route="Register"/>
Route="RegisterPage"/>
</Shell> </Shell>

@ -1,11 +1,17 @@
namespace ShoopNCook; namespace ShoopNCook;
using Microsoft.Maui.Controls; using Microsoft.Maui.Controls;
using Models; using Models;
using Models.Endpoint;
using ShoopNCook.Controllers;
using ShoopNCook.Pages;
public partial class ConnectAppShell : Shell public partial class ConnectAppShell : Shell
{ {
public ConnectAppShell() public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts)
{ {
ConnectionController controller = new ConnectionController(observer, accounts);
InitializeComponent(); InitializeComponent();
LoginPage.ContentTemplate = new DataTemplate(() => new LoginPage(controller));
RegisterPage.ContentTemplate = new DataTemplate(() => new RegisterPage(controller));
} }
} }

@ -0,0 +1,14 @@
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook
{
public interface ConnectionObserver
{
public void OnAccountConnected(Account account);
}
}

@ -0,0 +1,26 @@
using Models.Endpoint;
using Models;
namespace ShoopNCook.Controllers
{
public class ConnectionController : LoginController, RegisterController
{
private readonly ConnectionObserver observer;
private readonly IAccountManager accounts;
public ConnectionController(ConnectionObserver observer, IAccountManager accounts) {
this.observer = observer;
this.accounts = accounts;
}
public void Login(string email, string password)
{
Account acc = accounts.Login(email, password);
observer.OnAccountConnected(acc);
}
public void Register(string username, string email, string password)
{
Account acc = accounts.Register(username, email, password);
observer.OnAccountConnected(acc);
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook.Controllers
{
public interface LoginController
{
public void Login(string email, string password);
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShoopNCook.Controllers
{
public interface RegisterController
{
public void Register(string username, string email, string password);
}
}

@ -0,0 +1,34 @@
using Models;
using Models.Endpoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LocalEndpoint
{
internal class AccountManager : IAccountManager
{
private static readonly Uri DEFAULT_ACCOUNT_IMAGE = new Uri("https://www.pngkey.com/png/full/115-1150152_default-profile-picture-avatar-png-green.png");
private Account userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, "Stub Account"), "test@example.com");
private string userPassword = "123456";
public Account? Login(string email, string password)
{
if (userAccount.Email == email && userPassword == password)
{
return userAccount;
}
return null;
}
public Account? Register(string email, string username, string password)
{
userAccount = new Account(new User(DEFAULT_ACCOUNT_IMAGE, username), email);
userPassword = password;
return userAccount;
}
}
}

@ -1,7 +0,0 @@
namespace LocalEndpoint
{
public class Class1
{
}
}

@ -0,0 +1,11 @@
using Models.Endpoint;
namespace LocalEndpoint
{
public class LocalEndpoint : IEndpoint
{
public IAccountManager AccountManager => new AccountManager();
public ISearchEngine SearchEngine => throw new NotImplementedException();
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>

@ -10,24 +10,6 @@
Shell.TabBarTitleColor="{StaticResource Selected}" Shell.TabBarTitleColor="{StaticResource Selected}"
Shell.TabBarUnselectedColor="{StaticResource TextColorSecondary}"> Shell.TabBarUnselectedColor="{StaticResource TextColorSecondary}">
<ShellContent
x:Name="Splash"
Title="More"
ContentTemplate="{DataTemplate pages:Splash}"
Route="Splash"/>
<ShellContent
x:Name="LoginPage"
Title="Login"
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="LoginPage"/>
<ShellContent
x:Name="RegisterPage"
Title="Register"
ContentTemplate="{DataTemplate pages:RegisterPage}"
Route="RegisterPage"/>
<TabBar> <TabBar>
<ShellContent <ShellContent
x:Name="HomeTab" x:Name="HomeTab"

@ -4,7 +4,7 @@ using Models;
public partial class MainAppShell : Shell public partial class MainAppShell : Shell
{ {
public MainAppShell() public MainAppShell(Account account)
{ {
InitializeComponent(); InitializeComponent();
} }

@ -8,8 +8,8 @@ namespace Models.Endpoint
{ {
public interface IAccountManager public interface IAccountManager
{ {
public Account login(string email, string password); public Account? Login(string email, string password);
public Account? Register(string email, string username, string password);
} }
} }

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application> <application android:allowBackup="true" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
</manifest> </manifest>

@ -48,27 +48,22 @@
<ItemGroup> <ItemGroup>
<AndroidResource Remove="ShopNCookTests\**" /> <AndroidResource Remove="ShopNCookTests\**" />
<AndroidResource Remove="Tests\**" /> <AndroidResource Remove="Tests\**" />
<Compile Remove="Endpoint\**" />
<Compile Remove="LocalEndpoint\**" /> <Compile Remove="LocalEndpoint\**" />
<Compile Remove="Models\**" /> <Compile Remove="Models\**" />
<Compile Remove="ShopNCookTests\**" /> <Compile Remove="ShopNCookTests\**" />
<Compile Remove="Tests\**" /> <Compile Remove="Tests\**" />
<EmbeddedResource Remove="Endpoint\**" />
<EmbeddedResource Remove="LocalEndpoint\**" /> <EmbeddedResource Remove="LocalEndpoint\**" />
<EmbeddedResource Remove="Models\**" /> <EmbeddedResource Remove="Models\**" />
<EmbeddedResource Remove="ShopNCookTests\**" /> <EmbeddedResource Remove="ShopNCookTests\**" />
<EmbeddedResource Remove="Tests\**" /> <EmbeddedResource Remove="Tests\**" />
<MauiCss Remove="Endpoint\**" />
<MauiCss Remove="LocalEndpoint\**" /> <MauiCss Remove="LocalEndpoint\**" />
<MauiCss Remove="Models\**" /> <MauiCss Remove="Models\**" />
<MauiCss Remove="ShopNCookTests\**" /> <MauiCss Remove="ShopNCookTests\**" />
<MauiCss Remove="Tests\**" /> <MauiCss Remove="Tests\**" />
<MauiXaml Remove="Endpoint\**" />
<MauiXaml Remove="LocalEndpoint\**" /> <MauiXaml Remove="LocalEndpoint\**" />
<MauiXaml Remove="Models\**" /> <MauiXaml Remove="Models\**" />
<MauiXaml Remove="ShopNCookTests\**" /> <MauiXaml Remove="ShopNCookTests\**" />
<MauiXaml Remove="Tests\**" /> <MauiXaml Remove="Tests\**" />
<None Remove="Endpoint\**" />
<None Remove="LocalEndpoint\**" /> <None Remove="LocalEndpoint\**" />
<None Remove="Models\**" /> <None Remove="Models\**" />
<None Remove="ShopNCookTests\**" /> <None Remove="ShopNCookTests\**" />
@ -118,7 +113,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="Endpoint\Models.csproj" /> <ProjectReference Include="LocalEndpoint\LocalEndpoint.csproj" />
<ProjectReference Include="Models\Models.csproj" /> <ProjectReference Include="Models\Models.csproj" />
</ItemGroup> </ItemGroup>

@ -1,44 +1,44 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283 VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShoopNCook", "ShoopNCook.csproj", "{8ED2FB1D-C04D-478D-9271-CC91FE110396}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShoopNCook", "ShoopNCook.csproj", "{8ED2FB1D-C04D-478D-9271-CC91FE110396}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{E50D92DC-0BB1-4998-B085-EF47C55675AC}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LocalEndpoint", "LocalEndpoint\LocalEndpoint.csproj", "{57732316-93B9-4DA0-A212-F8892D3D968B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Build.0 = Debug|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.ActiveCfg = Release|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Build.0 = Release|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Build.0 = Release|Any CPU
{8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Deploy.0 = Release|Any CPU {8ED2FB1D-C04D-478D-9271-CC91FE110396}.Release|Any CPU.Deploy.0 = Release|Any CPU
{E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.ActiveCfg = Release|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.Build.0 = Release|Any CPU {E50D92DC-0BB1-4998-B085-EF47C55675AC}.Release|Any CPU.Build.0 = Release|Any CPU
{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.Build.0 = Release|Any CPU {A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}.Release|Any CPU.Build.0 = Release|Any CPU
{57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.Build.0 = Debug|Any CPU {57732316-93B9-4DA0-A212-F8892D3D968B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.ActiveCfg = Release|Any CPU {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.Build.0 = Release|Any CPU {57732316-93B9-4DA0-A212-F8892D3D968B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

@ -23,7 +23,7 @@
StrokeShape="RoundRectangle 20" StrokeShape="RoundRectangle 20"
BackgroundColor="{StaticResource ImageBackground}"> BackgroundColor="{StaticResource ImageBackground}">
<Grid> <Grid>
<Image /> <Image x:Name="RecipeImage" />
<HorizontalStackLayout <HorizontalStackLayout
x:Name="Stars" x:Name="Stars"
VerticalOptions="End" VerticalOptions="End"

@ -38,7 +38,8 @@
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Grid.Column="2" Grid.Column="2"
Placeholder="Mail address"/> Placeholder="Mail address"
x:Name="EmailEntry"/>
</Grid> </Grid>
</Border> </Border>
@ -57,7 +58,8 @@
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Grid.Column="2" Grid.Column="2"
Placeholder="Password"/> Placeholder="Password"
x:Name="PasswordEntry"/>
<ImageButton <ImageButton
Grid.Column="3" Grid.Column="3"
Source="visibility_off.svg" Source="visibility_off.svg"

@ -1,20 +1,21 @@
using Models.Endpoint;
using ShoopNCook.Controllers;
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
public partial class LoginPage : ContentPage public partial class LoginPage : ContentPage
{ {
public LoginPage() private readonly LoginController controller;
public LoginPage(LoginController controller)
{ {
InitializeComponent(); InitializeComponent();
this.controller = controller;
} }
private async void OnLoginButtonClicked(object sender, EventArgs e) private async void OnLoginButtonClicked(object sender, EventArgs e)
{ {
// Vérifiez les informations d'identification de l'utilisateur ici string email = EmailEntry.Text;
bool isValidUser = true; string password = PasswordEntry.Text;
controller.Login(email, password);
if (isValidUser)
{
await Shell.Current.GoToAsync("//HomePage");
}
} }
private async void ForgotPasswordTapped(object sender, EventArgs e) private async void ForgotPasswordTapped(object sender, EventArgs e)
{ {
@ -22,6 +23,6 @@ public partial class LoginPage : ContentPage
} }
private async void RegisterLabbelTapped(object sender, EventArgs e) private async void RegisterLabbelTapped(object sender, EventArgs e)
{ {
await Shell.Current.Navigation.PushAsync(new RegisterPage()); await Shell.Current.GoToAsync("//Register");
} }
} }

@ -24,7 +24,7 @@ public partial class MorePage : ContentPage
private async void OnLogoutButtonTapped(object sender, EventArgs e) private async void OnLogoutButtonTapped(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//LoginPage"); await Shell.Current.GoToAsync("//Login");
} }
private async void OnShareButtonClicked(object sender, EventArgs e) private async void OnShareButtonClicked(object sender, EventArgs e)
{ {

@ -40,7 +40,8 @@
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Grid.Column="2" Grid.Column="2"
Placeholder="User Name"/> Placeholder="User Name"
x:Name="UserNameEntry"/>
</Grid> </Grid>
</Border> </Border>
@ -59,7 +60,8 @@
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Grid.Column="2" Grid.Column="2"
Placeholder="Mail address"/> Placeholder="Mail address"
x:Name="EmailEntry"/>
</Grid> </Grid>
</Border> </Border>
@ -76,7 +78,8 @@
<Entry <Entry
Style="{StaticResource UserInput}" Style="{StaticResource UserInput}"
Grid.Column="2" Grid.Column="2"
Placeholder="Password"/> Placeholder="Password"
x:Name="PasswordEntry"/>
<ImageButton <ImageButton
Grid.Column="3" Grid.Column="3"
Source="visibility_off.svg" Source="visibility_off.svg"

@ -1,17 +1,24 @@
using ShoopNCook.Controllers;
namespace ShoopNCook.Pages; namespace ShoopNCook.Pages;
public partial class RegisterPage : ContentPage public partial class RegisterPage : ContentPage
{ {
public RegisterPage() private readonly RegisterController controller;
public RegisterPage(RegisterController controller)
{ {
InitializeComponent(); InitializeComponent();
this.controller = controller;
} }
private async void LoginTapped(object sender, EventArgs e) private async void LoginTapped(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//LoginPage"); await Shell.Current.GoToAsync("//Login");
} }
private async void RegisterTapped(object sender, EventArgs e) private void RegisterTapped(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//LoginPage"); string email = EmailEntry.Text;
string password = PasswordEntry.Text;
string username = UserNameEntry.Text;
controller.Register(username, email, password);
} }
} }

@ -8,7 +8,7 @@ public partial class Splash : ContentPage
} }
private async void OnGetStartedButtonClicked(object sender, EventArgs e) private async void OnGetStartedButtonClicked(object sender, EventArgs e)
{ {
await Shell.Current.GoToAsync("//LoginPage"); await Shell.Current.GoToAsync("//Login");
} }
} }

Loading…
Cancel
Save