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;
using ShoopNCook.Pages;
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()
{
InitializeComponent();
Shell main = new ConnectAppShell();
main.GoToAsync("//Splash");
MainPage = main;
Shell shell = new ConnectAppShell(this, endpoint.AccountManager);
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
x:Name="LoginPage"
Title="Login"
ContentTemplate="{DataTemplate pages:LoginPage}"
Route="LoginPage"/>
Route="Login"/>
<ShellContent
x:Name="RegisterPage"
Title="Register"
ContentTemplate="{DataTemplate pages:RegisterPage}"
Route="RegisterPage"/>
Route="Register"/>
</Shell>

@ -1,11 +1,17 @@
namespace ShoopNCook;
using Microsoft.Maui.Controls;
using Models;
using Models.Endpoint;
using ShoopNCook.Controllers;
using ShoopNCook.Pages;
public partial class ConnectAppShell : Shell
{
public ConnectAppShell()
public ConnectAppShell(ConnectionObserver observer, IAccountManager accounts)
{
ConnectionController controller = new ConnectionController(observer, accounts);
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>
<TargetFramework>net7.0</TargetFramework>

@ -10,24 +10,6 @@
Shell.TabBarTitleColor="{StaticResource Selected}"
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>
<ShellContent
x:Name="HomeTab"

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

@ -8,8 +8,8 @@ namespace Models.Endpoint
{
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"?>
<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.INTERNET" />
</manifest>

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

@ -8,7 +8,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "Models\Models.csproj", "{A9D43E07-345D-4DD4-B4F9-CE69ED569B5F}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

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

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

@ -1,20 +1,21 @@
using Models.Endpoint;
using ShoopNCook.Controllers;
namespace ShoopNCook.Pages;
public partial class LoginPage : ContentPage
{
public LoginPage()
private readonly LoginController controller;
public LoginPage(LoginController controller)
{
InitializeComponent();
this.controller = controller;
}
private async void OnLoginButtonClicked(object sender, EventArgs e)
{
// Vérifiez les informations d'identification de l'utilisateur ici
bool isValidUser = true;
if (isValidUser)
{
await Shell.Current.GoToAsync("//HomePage");
}
string email = EmailEntry.Text;
string password = PasswordEntry.Text;
controller.Login(email, password);
}
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)
{
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)
{
await Shell.Current.GoToAsync("//LoginPage");
await Shell.Current.GoToAsync("//Login");
}
private async void OnShareButtonClicked(object sender, EventArgs e)
{

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

@ -1,17 +1,24 @@
using ShoopNCook.Controllers;
namespace ShoopNCook.Pages;
public partial class RegisterPage : ContentPage
{
public RegisterPage()
private readonly RegisterController controller;
public RegisterPage(RegisterController controller)
{
InitializeComponent();
this.controller = controller;
}
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)
{
await Shell.Current.GoToAsync("//LoginPage");
await Shell.Current.GoToAsync("//Login");
}
}

Loading…
Cancel
Save