mirror of
https://github.com/NecroticBamboo/QRBee.git
synced 2025-12-21 12:11:53 +00:00
Client connected to the Registration page. LocalSettings are now saved and can be used.
This commit is contained in:
parent
978cb50603
commit
de51e8a59d
@ -78,6 +78,7 @@
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\LocalSettings.cs" />
|
||||
<Compile Include="Services\QRScannerService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
31
QRBee/QRBee.Android/Services/LocalSettings.cs
Normal file
31
QRBee/QRBee.Android/Services/LocalSettings.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using QRBee.Services;
|
||||
using Xamarin.Forms;
|
||||
|
||||
[assembly: Dependency(typeof(QRBee.Droid.Services.LocalSettings))]
|
||||
|
||||
namespace QRBee.Droid.Services
|
||||
{
|
||||
internal class LocalSettings : ILocalSettings
|
||||
{
|
||||
public string QRBeeApiUrl => "https://localhost:5000";
|
||||
|
||||
public async Task SaveSettings(Settings settings)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(settings, Formatting.Indented);
|
||||
Application.Current.Properties["Settings"] = json;
|
||||
await Application.Current.SavePropertiesAsync();
|
||||
}
|
||||
|
||||
public Task<Settings> LoadSettings()
|
||||
{
|
||||
if (!Application.Current.Properties.ContainsKey("Settings"))
|
||||
return Task.FromResult(new Settings());
|
||||
|
||||
var json = Application.Current.Properties["Settings"].ToString();
|
||||
var settings = JsonConvert.DeserializeObject<Settings>(json);
|
||||
return Task.FromResult(settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,14 @@
|
||||
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Plugin.Fingerprint" Version="2.1.4" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2244" />
|
||||
|
||||
33
QRBee/QRBee/Services/ILocalSettings.cs
Normal file
33
QRBee/QRBee/Services/ILocalSettings.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QRBee.Services
|
||||
{
|
||||
public class Settings
|
||||
{
|
||||
public string PIN { get; set; }
|
||||
public bool IsRegistered { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string DateOfBirth { get; set; }
|
||||
public string CardNumber { get; set; }
|
||||
public string ValidFrom { get; set; }
|
||||
public string ExpirationDate { get; set; }
|
||||
public string CardHolderName { get; set; }
|
||||
public string CVC { get; set; }
|
||||
public string IssueNo { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
public interface ILocalSettings
|
||||
{
|
||||
string QRBeeApiUrl { get; }
|
||||
Task SaveSettings(Settings settings);
|
||||
Task<Settings> LoadSettings();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,15 @@
|
||||
using QRBee.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using QRBee.Views;
|
||||
using Plugin.Fingerprint;
|
||||
using Plugin.Fingerprint.Abstractions;
|
||||
using QRBee.Services;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace QRBee.ViewModels
|
||||
{
|
||||
public class LoginViewModel : BaseViewModel
|
||||
{
|
||||
private bool _isPinVisible;
|
||||
public Command LoginCommand
|
||||
{
|
||||
get;
|
||||
@ -22,7 +22,9 @@ namespace QRBee.ViewModels
|
||||
{
|
||||
LoginCommand = new Command(OnLoginClicked);
|
||||
RegisterCommand = new Command(OnRegisterClicked);
|
||||
|
||||
}
|
||||
public string PinCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Reaction on Login button
|
||||
@ -30,11 +32,23 @@ namespace QRBee.ViewModels
|
||||
/// <param name="obj"></param>
|
||||
private async void OnLoginClicked(object obj)
|
||||
{
|
||||
bool isFingerprintAvailable = await CrossFingerprint.Current.IsAvailableAsync(false);
|
||||
var isFingerprintAvailable = await CrossFingerprint.Current.IsAvailableAsync(false);
|
||||
if (!isFingerprintAvailable)
|
||||
{
|
||||
//Insert PIN
|
||||
return;
|
||||
IsPinVisible = true;
|
||||
var localSettings = DependencyService.Resolve<ILocalSettings>();
|
||||
var pin = (await localSettings.LoadSettings()).PIN;
|
||||
|
||||
if (!string.IsNullOrEmpty(pin) && pin.Equals(PinCode))
|
||||
{
|
||||
await Shell.Current.GoToAsync($"//{nameof(MainPage)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
await Shell.Current.GoToAsync($"{nameof(RegisterPage)}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var conf = new AuthenticationRequestConfiguration("Authentication", "Authenticate access to your personal data");
|
||||
@ -53,6 +67,20 @@ namespace QRBee.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPinVisible
|
||||
{
|
||||
get => _isPinVisible;
|
||||
set
|
||||
{
|
||||
if (value == _isPinVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_isPinVisible = value;
|
||||
OnPropertyChanged(nameof(IsPinVisible));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reaction on Register button
|
||||
/// </summary>
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using QRBee.Core;
|
||||
using QRBee.Services;
|
||||
using QRBee.Views;
|
||||
using Xamarin.Forms;
|
||||
|
||||
@ -62,12 +64,49 @@ namespace QRBee.ViewModels
|
||||
OnPropertyChanged(nameof(Password2Color));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Pin { get; set; }
|
||||
|
||||
private async void OnRegisterClicked(object obj)
|
||||
{
|
||||
await Shell.Current.GoToAsync($"//{nameof(MainPage)}");
|
||||
using var client = new HttpClient();
|
||||
var localSettings = DependencyService.Resolve<ILocalSettings>();
|
||||
|
||||
var service = new Core.Client.Client(localSettings.QRBeeApiUrl,client);
|
||||
|
||||
try
|
||||
{
|
||||
await service.RegisterAsync(new RegistrationRequest
|
||||
{
|
||||
DateOfBirth = DateOfBirth,
|
||||
Email = Email,
|
||||
Name = Name,
|
||||
RegisterAsMerchant = false
|
||||
});
|
||||
|
||||
//save local settings
|
||||
var settings = new Settings
|
||||
{
|
||||
CardHolderName = CardHolderName,
|
||||
CardNumber = CardNumber,
|
||||
CVC = CVC,
|
||||
DateOfBirth = DateOfBirth,
|
||||
Email = Email,
|
||||
ExpirationDate = ExpirationDate,
|
||||
IsRegistered = true,
|
||||
IssueNo = IssueNo,
|
||||
ValidFrom = ValidFrom,
|
||||
Name = Name,
|
||||
PIN = Pin
|
||||
};
|
||||
await localSettings.SaveSettings(settings);
|
||||
|
||||
await Shell.Current.GoToAsync($"//{nameof(MainPage)}");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
var page = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
|
||||
await page.DisplayAlert("Error", "The Backend isn't working", "Ok");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,13 +10,10 @@
|
||||
<ContentPage.Content>
|
||||
|
||||
<StackLayout Padding="10,0,10,0" VerticalOptions="Center">
|
||||
<!-- <StackLayout Orientation="Vertical"> -->
|
||||
<!-- <Label Text="Login: " Padding="5,10,0,0"/> -->
|
||||
<!-- <Entry HorizontalOptions="FillAndExpand" Keyboard="Text"/> -->
|
||||
<!-- -->
|
||||
<!-- <Label Text="Password: " Padding="5,0,0,0" /> -->
|
||||
<!-- <Entry HorizontalOptions="FillAndExpand" IsPassword="True"/> -->
|
||||
<!-- </StackLayout> -->
|
||||
<StackLayout Orientation="Vertical" IsVisible="{Binding IsPinVisible}">
|
||||
<Label Text="PIN code: " Padding="5,0,0,0" />
|
||||
<Entry HorizontalOptions="FillAndExpand" IsPassword="True" Text="{Binding PinCode}" Keyboard="Numeric" MaxLength="4"/>
|
||||
</StackLayout>
|
||||
|
||||
<Button VerticalOptions="Center" Text="Login" Command="{Binding LoginCommand}"/>
|
||||
<Button VerticalOptions="Center" Text="Register new user" Command="{Binding RegisterCommand}"/>
|
||||
|
||||
@ -23,6 +23,9 @@
|
||||
|
||||
<Label Text="Confirm password: " Padding="5,5,0,0" />
|
||||
<Entry HorizontalOptions="FillAndExpand" IsPassword="True" Text="{Binding Password2}" TextColor="{Binding Password2Color}"/>
|
||||
|
||||
<Label Text="Login PIN: " Padding="5,5,0,0" />
|
||||
<Entry HorizontalOptions="FillAndExpand" IsPassword="True" Text="{Binding Pin}" Keyboard="Numeric" MaxLength="4"/>
|
||||
</StackLayout>
|
||||
|
||||
<StackLayout Orientation="Vertical">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user