parent
f1c836480e
commit
a8c14f471d
@ -0,0 +1,43 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.AuthorityDashboardPage" |
||||
Title="Authority Dashboard"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<!-- Dashboard Header --> |
||||
<Label Text="Authority Dashboard" |
||||
FontSize="Large" |
||||
HorizontalOptions="Center" |
||||
FontAttributes="Bold" /> |
||||
|
||||
<!-- Section: Reports List --> |
||||
<Label Text="Reports Submitted by Users" |
||||
FontSize="Medium" |
||||
FontAttributes="Bold" |
||||
Margin="0,20,0,10" /> |
||||
<ListView x:Name="ReportsListView" |
||||
HasUnevenRows="True"> |
||||
<ListView.ItemTemplate> |
||||
<DataTemplate> |
||||
<ViewCell> |
||||
<StackLayout Padding="10"> |
||||
<Label Text="{Binding IncidentType}" |
||||
FontSize="Medium" |
||||
FontAttributes="Bold" /> |
||||
<Label Text="{Binding Address}" |
||||
FontSize="Small" |
||||
TextColor="Gray" /> |
||||
<Label Text="{Binding DateTime, StringFormat='Reported on: {0:MMM dd, yyyy HH:mm}'}" |
||||
FontSize="Small" /> |
||||
<Label Text="{Binding Description}" |
||||
FontSize="Small" /> |
||||
<Button Text="Mark as Solved" |
||||
|
||||
CommandParameter="{Binding .}" /> |
||||
</StackLayout> |
||||
</ViewCell> |
||||
</DataTemplate> |
||||
</ListView.ItemTemplate> |
||||
</ListView> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,9 @@ |
||||
namespace Justice.Views; |
||||
|
||||
public partial class AuthorityDashboardPage : ContentPage |
||||
{ |
||||
public AuthorityDashboardPage() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.LoginPage" |
||||
Title="Login"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="Login" FontSize="Large" HorizontalOptions="Center" /> |
||||
|
||||
<Entry x:Name="UsernameEntry" Placeholder="Username" /> |
||||
<Entry x:Name="PasswordEntry" Placeholder="Password" IsPassword="True" /> |
||||
|
||||
<Button Text="Login" Clicked="OnLoginClicked" /> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,55 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using Org.BouncyCastle.Crypto.Generators; |
||||
using System; |
||||
using BCrypt.Net; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class LoginPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _dbHelper; |
||||
|
||||
public LoginPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_dbHelper = new DatabaseHelper(); |
||||
} |
||||
|
||||
private async void OnLoginClicked(object sender, EventArgs e) |
||||
{ |
||||
if (string.IsNullOrWhiteSpace(UsernameEntry.Text) || string.IsNullOrWhiteSpace(PasswordEntry.Text)) |
||||
{ |
||||
await DisplayAlert("Error", "Username and password are required.", "OK"); |
||||
return; |
||||
} |
||||
|
||||
try |
||||
{ |
||||
var user = await _dbHelper.FindAsync<User>("SELECT * FROM User WHERE Username = ?", UsernameEntry.Text.Trim()); |
||||
|
||||
if (user == null || !BCrypt.Net.BCrypt.Verify(PasswordEntry.Text.Trim(), user.Password)) |
||||
{ |
||||
await DisplayAlert("Error", "Invalid username or password.", "OK"); |
||||
return; |
||||
} |
||||
|
||||
await DisplayAlert("Success", $"Welcome {user.Username}!", "OK"); |
||||
|
||||
// Navigate based on role |
||||
if (user.Role == "EndUser") |
||||
{ |
||||
await Navigation.PushAsync(new DashboardPage()); |
||||
} |
||||
else if (user.Role == "AuthorityUser") |
||||
{ |
||||
await Navigation.PushAsync(new AuthorityDashboardPage()); |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to login: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
||||
x:Class="Justice.Views.RegistrationPage" |
||||
Title="Register"> |
||||
|
||||
<StackLayout Padding="20"> |
||||
<Label Text="Register" FontSize="Large" HorizontalOptions="Center" /> |
||||
|
||||
<Entry x:Name="UsernameEntry" Placeholder="Username" /> |
||||
<Entry x:Name="PasswordEntry" Placeholder="Password" IsPassword="True" /> |
||||
|
||||
<Picker x:Name="RolePicker" Title="Select Role"> |
||||
<Picker.ItemsSource> |
||||
<x:Array Type="{x:Type x:String}"> |
||||
<x:String>EndUser</x:String> |
||||
<x:String>AuthorityUser</x:String> |
||||
</x:Array> |
||||
</Picker.ItemsSource> |
||||
</Picker> |
||||
|
||||
<Entry x:Name="AuthorityTypeEntry" Placeholder="Authority Type (Optional)" IsVisible="False" /> |
||||
<Button Text="Register" Clicked="OnRegisterClicked" /> |
||||
</StackLayout> |
||||
</ContentPage> |
@ -0,0 +1,53 @@ |
||||
using Justice.Helpers; |
||||
using Justice.Models; |
||||
using Org.BouncyCastle.Crypto.Generators; |
||||
using System; |
||||
|
||||
namespace Justice.Views |
||||
{ |
||||
public partial class RegistrationPage : ContentPage |
||||
{ |
||||
private readonly DatabaseHelper _dbHelper; |
||||
|
||||
public RegistrationPage() |
||||
{ |
||||
InitializeComponent(); |
||||
_dbHelper = new DatabaseHelper(); |
||||
RolePicker.SelectedIndexChanged += (s, e) => |
||||
{ |
||||
AuthorityTypeEntry.IsVisible = RolePicker.SelectedItem?.ToString() == "AuthorityUser"; |
||||
}; |
||||
} |
||||
|
||||
private async void OnRegisterClicked(object sender, EventArgs e) |
||||
{ |
||||
if (string.IsNullOrWhiteSpace(UsernameEntry.Text) || string.IsNullOrWhiteSpace(PasswordEntry.Text) || RolePicker.SelectedItem == null) |
||||
{ |
||||
await DisplayAlert("Error", "All fields are required.", "OK"); |
||||
return; |
||||
} |
||||
|
||||
var hashedPassword = BCrypt.Net.BCrypt.HashPassword(PasswordEntry.Text.Trim()); |
||||
var user = new User |
||||
{ |
||||
Username = UsernameEntry.Text.Trim(), |
||||
Password = hashedPassword, |
||||
Role = RolePicker.SelectedItem.ToString(), |
||||
AuthorityType = AuthorityTypeEntry.IsVisible ? AuthorityTypeEntry.Text.Trim() : null |
||||
}; |
||||
|
||||
try |
||||
{ |
||||
await _dbHelper.InitializeAsync<User>(); |
||||
await _dbHelper.InsertAsync(user); |
||||
|
||||
await DisplayAlert("Success", "User registered successfully.", "OK"); |
||||
await Navigation.PopAsync(); |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
await DisplayAlert("Error", $"Failed to register: {ex.Message}", "OK"); |
||||
} |
||||
} |
||||
} |
||||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue