Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<ShellContent
Title="Welcome"
ContentTemplate="{DataTemplate views:WelcomePage}"/>
<ShellContent
Title="User Management"
ContentTemplate="{DataTemplate views:UsersPage}"
Icon="{OnPlatform 'icon_about.png', iOS='icon_about_ios.png', MacCatalyst='icon_about_ios.png'}" />


<ShellContent
Title="Volunteer Requests"
Expand Down
1 change: 1 addition & 0 deletions MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<Database>();
builder.Services.AddSingleton<IUsersService, UsersService>();
builder.Services.AddSingleton<ISecurityAlertService, SecurityAlertService>();
builder.Services.AddSingleton<IContinentService, ContinentService>();
builder.Services.AddSingleton<ISkillService, SkillService>();
Expand Down
58 changes: 58 additions & 0 deletions Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using SQLite;
using System.ComponentModel;

namespace UndacApp.Models
{
public class User : AModel
{
private string _name;
public string Name
{
get => _name;
set => SetField(ref _name, value);
}

private string _email;
public string Email
{
get => _email;
set => SetField(ref _email, value);
}

private string _accessLevel;
public string AccessLevel
{
get => _accessLevel;
set => SetField(ref _accessLevel, value);
}

private bool _employed = true;
public bool Employed
{
get => _employed;
set => SetField(ref _employed, value);
}

private string _role;
public string Role
{
get => _role;
set => SetField(ref _role, value);
}

private string _team;
public string Team
{
get => _team;
set => SetField(ref _team, value);
}

private string _password;
public string Password
{
get => _password;
set => SetField(ref _password, value);
}
}
}

11 changes: 11 additions & 0 deletions Services/IUsersService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using UndacApp.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace UndacApp.Services
{
public interface IUsersService : IService<User>
{
// Define additional methods specific to user management if needed
}
}
16 changes: 16 additions & 0 deletions Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using UndacApp.Models;
using System.Threading.Tasks;

namespace UndacApp.Services
{
public class UsersService : AService<User>, IUsersService
{
public UsersService() : base()
{
// Additional initialization if required
}

// Implement any additional methods specific to the User entity
// For now, all basic CRUD operations are inherited from AService<User>
}
}
21 changes: 21 additions & 0 deletions Utils/PasswordHasher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Security.Cryptography;
using System.Text;

public static class PasswordHasher
{
public static string HashPassword(string password)
{
using (var sha256 = SHA256.Create())
{
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job on password hashing!

return Convert.ToBase64String(hashedBytes);
}
}

public static bool VerifyPassword(string enteredPassword, string storedHash)
{
string enteredHash = HashPassword(enteredPassword);
return enteredHash == storedHash;
}
}
45 changes: 45 additions & 0 deletions Views/UsersPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="UndacApp.Views.UsersPage"
Title="User Management">

<ScrollView>
<VerticalStackLayout Spacing="10" Margin="5">
<!-- Login Section -->
<VerticalStackLayout Spacing="10">
<Entry x:Name="txtLoginEmail" Placeholder="Email"/>
<Entry x:Name="txtLoginPassword" Placeholder="Password" IsPassword="True"/>
<Button Text="Login" Clicked="LoginButton_Clicked"/>
</VerticalStackLayout>

<!-- User Management Section (Initially Hidden) -->
<StackLayout x:Name="userManagementSection" IsVisible="False">
<!-- User Addition Form -->
<VerticalStackLayout Spacing="10">
<Entry x:Name="txtName" Placeholder="Name"/>
<Entry x:Name="txtEmail" Placeholder="Email"/>
<Entry x:Name="txtPassword" Placeholder="Password" IsPassword="True"/>
<Entry x:Name="txtTeam" Placeholder="Team"/>
<Picker x:Name="pickerRole" Title="Role"/>
<Picker x:Name="pickerAccessLevel" Title="Access Level"/>
<Button x:Name="AddUserButton" Text="Add User" Clicked="AddUserButton_Clicked"/>
</VerticalStackLayout>

<!-- User List and Selection -->
<ListView x:Name="listViewUsers" ItemSelected="OnUserSelected">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" Detail="{Binding Email}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

<!-- Edit and Delete Buttons -->
<StackLayout Orientation="Horizontal">
<Button x:Name="btnEdit" Text="Edit" Clicked="EditUserButton_Clicked" IsEnabled="False"/>
<Button x:Name="btnDelete" Text="Delete" Clicked="DeleteUserButton_Clicked" IsEnabled="False"/>
</StackLayout>
</StackLayout>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
Loading