Login-update

main
unknown 6 months ago
parent a8c14f471d
commit d1f9f85a9e
  1. 8
      AppShell.xaml
  2. 31
      AppShell.xaml.cs
  3. 6
      Views/DashboardPage.xaml
  4. 15
      Views/DashboardPage.xaml.cs
  5. 17
      Views/LoginPage.xaml
  6. 48
      Views/LoginPage.xaml.cs
  7. 5
      Views/ViewReportsPage.xaml
  8. 10
      Views/ViewReportsPage.xaml.cs
  9. BIN
      bin/Debug/net9.0-android/Justice.dll
  10. BIN
      bin/Debug/net9.0-android/Justice.pdb
  11. BIN
      bin/Debug/net9.0-android/com.companyname.justice-Signed.apk
  12. BIN
      bin/Debug/net9.0-android/com.companyname.justice-Signed.apk.idsig
  13. BIN
      bin/Debug/net9.0-android/com.companyname.justice.apk
  14. BIN
      bin/Debug/net9.0-ios/iossimulator-x64/Justice.dll
  15. BIN
      bin/Debug/net9.0-ios/iossimulator-x64/Justice.pdb
  16. BIN
      bin/Debug/net9.0-maccatalyst/maccatalyst-x64/Justice.dll
  17. BIN
      bin/Debug/net9.0-maccatalyst/maccatalyst-x64/Justice.pdb
  18. BIN
      bin/Debug/net9.0-windows10.0.19041.0/win10-x64/Justice.dll
  19. BIN
      bin/Debug/net9.0-windows10.0.19041.0/win10-x64/Justice.exe
  20. BIN
      bin/Debug/net9.0-windows10.0.19041.0/win10-x64/Justice.pdb

@ -7,7 +7,9 @@
Shell.FlyoutBehavior="Flyout" Shell.FlyoutBehavior="Flyout"
Title="Justice"> Title="Justice">
<ShellContent Title="Login" ContentTemplate="{DataTemplate views:LoginPage}" /> <ShellContent Title="Login" ContentTemplate="{DataTemplate views:LoginPage}" Route="LoginPage" />
<ShellContent Title="Register" ContentTemplate="{DataTemplate views:RegistrationPage}" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate views:DashboardPage}" Route="DashboardPage" />
<ShellContent Title="Home" ContentTemplate="{DataTemplate views:DashboardPage}" Route="DashboardPage" /> <ShellContent Title="View Reports" ContentTemplate="{DataTemplate views:ViewReportsPage}" Route="ViewReportsPage" />
<MenuItem Text="Logout" Command="{Binding LogoutCommand}" />
</Shell> </Shell>

@ -1,10 +1,39 @@
namespace Justice using Justice.Helpers;
namespace Justice
{ {
public partial class AppShell : Shell public partial class AppShell : Shell
{ {
public Command LogoutCommand { get; }
public AppShell() public AppShell()
{ {
InitializeComponent(); InitializeComponent();
Routing.RegisterRoute("LoginPage", typeof(Views.LoginPage));
Routing.RegisterRoute("DashboardPage", typeof(Views.DashboardPage));
Routing.RegisterRoute("ViewReportsPage", typeof(Views.ViewReportsPage));
LogoutCommand = new Command(async () =>
{
AuthHelper.Logout();
await Shell.Current.GoToAsync("//LoginPage");
});
BindingContext = this;
}
protected override async void OnNavigating(ShellNavigatingEventArgs args)
{
base.OnNavigating(args);
// Check if user is authenticated
if (!AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("ViewReportsPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("DashboardPage"))
{
args.Cancel(); // Prevent navigation
await Shell.Current.GoToAsync("//LoginPage");
}
} }
} }
} }

@ -3,8 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Justice.Views.DashboardPage" x:Class="Justice.Views.DashboardPage"
Title="DashboardPage" BackgroundColor="WhiteSmoke"> Title="DashboardPage" BackgroundColor="WhiteSmoke">
<ScrollView> <ScrollView>
<VerticalStackLayout> <VerticalStackLayout>
<Label Text="Welcome to the End User Dashboard!" FontSize="Large" HorizontalOptions="Center" />
<!-- Logout Button -->
<Button Text="Logout" Clicked="OnLogoutClicked" HorizontalOptions="Center" VerticalOptions="EndAndExpand" />
<Button Text="Get Current Location" <Button Text="Get Current Location"
HorizontalOptions="Fill" HorizontalOptions="Fill"
BackgroundColor="White" BackgroundColor="White"

@ -1,5 +1,6 @@
using Justice.Helpers; using Justice.Helpers;
using Microsoft; using Microsoft;
using Justice.Views;
namespace Justice.Views; namespace Justice.Views;
@ -11,33 +12,39 @@ public partial class DashboardPage : ContentPage
InitializeComponent(); InitializeComponent();
} }
private async void OnInformationCenterClicked(object sender, EventArgs e) private async void OnInformationCenterClicked(object sender, EventArgs e)
{ {
await Navigation.PushAsync(new InformationCenterPage()); await Navigation.PushAsync(new InformationCenterPage());
} }
private void OnHelpLineNumberClicked(object sender, EventArgs e) private void OnHelpLineNumberClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new HelplinePage()); Navigation.PushAsync(new HelplinePage());
} }
private void OnViewReportClicked(object sender, EventArgs e) private void OnViewReportClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new ViewReportsPage()); Navigation.PushAsync(new ViewReportsPage());
} }
private void OnIncidentReportClicked(object sender, EventArgs e) private void OnIncidentReportClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new IncidentReportPage()); Navigation.PushAsync(new IncidentReportPage());
} }
private void OnSOSButtonClicked(object sender, EventArgs e) private void OnSOSButtonClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new SosPage()); Navigation.PushAsync(new SosPage());
} }
private void OnAddContactClicked(object sender, EventArgs e) private void OnAddContactClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new AddContactPage()); Navigation.PushAsync(new AddContactPage());
} }
private async void OnLogoutClicked(object sender, EventArgs e)
{
bool confirm = await DisplayAlert("Logout", "Are you sure you want to log out?", "Yes", "No");
if (confirm)
{
// Redirect to Login Page
await Shell.Current.GoToAsync("//LoginPage");
}
}
} }

@ -6,9 +6,22 @@
<StackLayout Padding="20"> <StackLayout Padding="20">
<Label Text="Login" FontSize="Large" HorizontalOptions="Center" /> <Label Text="Login" FontSize="Large" HorizontalOptions="Center" />
<!-- Role Picker -->
<Entry x:Name="UsernameEntry" Placeholder="Username"/> <Entry x:Name="UsernameEntry" Placeholder="Username"/>
<Entry x:Name="PasswordEntry" Placeholder="Password" IsPassword="True" /> <Entry x:Name="PasswordEntry" Placeholder="Password"/>
<Button Text="Login" Clicked="OnLoginClicked" />
<Label Text="Select Role:" FontSize="Medium" />
<Picker x:Name="RolePicker" Title="Choose a role">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>End User</x:String>
<x:String>Authority User</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<!-- Login Button -->
<Button Text="Login" Clicked="OnLoginButtonClicked" />
</StackLayout> </StackLayout>
</ContentPage> </ContentPage>

@ -1,54 +1,50 @@
using Justice.Helpers; using Justice.Helpers;
using Justice.Models;
using Org.BouncyCastle.Crypto.Generators;
using System;
using BCrypt.Net;
namespace Justice.Views namespace Justice.Views
{ {
public partial class LoginPage : ContentPage public partial class LoginPage : ContentPage
{ {
private readonly DatabaseHelper _dbHelper;
public LoginPage() public LoginPage()
{ {
InitializeComponent(); InitializeComponent();
_dbHelper = new DatabaseHelper();
} }
private async void OnLoginClicked(object sender, EventArgs e) private async void OnLoginButtonClicked(object sender, EventArgs e)
{ {
if (string.IsNullOrWhiteSpace(UsernameEntry.Text) || string.IsNullOrWhiteSpace(PasswordEntry.Text)) var endvalidUsername = "test";
var endvalidPassword = "test123";
var authvalidUsername = "auth";
var authvalidPassword = "auth123";
var enteredUsername = UsernameEntry?.Text?.Trim();
var enteredPassword = PasswordEntry?.Text?.Trim();
var selectedRole = RolePicker?.SelectedItem?.ToString();
if (string.IsNullOrEmpty(selectedRole))
{ {
await DisplayAlert("Error", "Username and password are required.", "OK"); await DisplayAlert("Error", "Please select a role to proceed.", "OK");
return; return;
} }
try if (string.IsNullOrWhiteSpace(enteredUsername) || string.IsNullOrWhiteSpace(enteredPassword))
{ {
var user = await _dbHelper.FindAsync<User>("SELECT * FROM User WHERE Username = ?", UsernameEntry.Text.Trim()); await DisplayAlert("Error", "Please enter both username and password.", "OK");
if (user == null || !BCrypt.Net.BCrypt.Verify(PasswordEntry.Text.Trim(), user.Password))
{
await DisplayAlert("Error", "Invalid username or password.", "OK");
return; return;
} }
await DisplayAlert("Success", $"Welcome {user.Username}!", "OK"); if (enteredUsername == endvalidUsername && enteredPassword == endvalidPassword && selectedRole == "End User")
// Navigate based on role
if (user.Role == "EndUser")
{ {
await Navigation.PushAsync(new DashboardPage()); AuthHelper.Login("EndUser");
await Shell.Current.GoToAsync("//DashboardPage");
} }
else if (user.Role == "AuthorityUser") else if (enteredUsername == authvalidUsername && enteredPassword == authvalidPassword && selectedRole == "Authority User")
{ {
await Navigation.PushAsync(new AuthorityDashboardPage()); AuthHelper.Login("AuthorityUser");
} await Shell.Current.GoToAsync("//ViewReportsPage");
} }
catch (Exception ex) else
{ {
await DisplayAlert("Error", $"Failed to login: {ex.Message}", "OK"); await DisplayAlert("Error", "Invalid credentials. Please try again.", "OK");
} }
} }
} }

@ -5,7 +5,6 @@
<StackLayout Padding="20"> <StackLayout Padding="20">
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" /> <Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" />
<!-- List of Reports --> <!-- List of Reports -->
<ListView x:Name="ReportsListView" <ListView x:Name="ReportsListView"
HasUnevenRows="True" HasUnevenRows="True"
@ -21,9 +20,9 @@
FontSize="Small" /> FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" /> <Label Text="{Binding Description}" FontSize="Small" />
</StackLayout> </StackLayout>
<Button Text="Delete" <Button x:Name="DeleteName" Text="Delete"
Clicked="OnDeleteReportClicked" Clicked="OnDeleteReportClicked"
CommandParameter="{Binding .}" HeightRequest="10" /> CommandParameter="{Binding .}" HeightRequest="10" IsVisible="True"/>
</StackLayout> </StackLayout>
</ViewCell> </ViewCell>
</DataTemplate> </DataTemplate>

@ -85,7 +85,15 @@ namespace Justice.Views
} }
} }
} }
private async void OnLogoutClicked(object sender, EventArgs e)
{
bool confirm = await DisplayAlert("Logout", "Are you sure you want to log out?", "Yes", "No");
if (confirm)
{
// Redirect to Login Page
await Shell.Current.GoToAsync("//LoginPage");
}
}
private void MenuItem_Clicked(object sender, EventArgs e) private void MenuItem_Clicked(object sender, EventArgs e)
{ {

Loading…
Cancel
Save