Skip to content

Commit

Permalink
- merge #3
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoFoxCZ committed May 15, 2024
1 parent ab19815 commit 9557ecc
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 2 deletions.
26 changes: 26 additions & 0 deletions HackatonApp/Components/Pages/Dashboard/Dashboard.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page "/dashboard"
@using HackatonApp.Services.Core
@inject NavigationManager NavigationManager
@inject AuthChecker AuthChecker
@rendermode InteractiveServer

@code {
protected override async Task OnAfterRenderAsync( bool firstRender )
{
if( !firstRender )
{
return;
}

var isAuthenticated = await AuthChecker.IsAuthenticatedAsync();

if (!isAuthenticated)
{
NavigationManager.NavigateTo("/login");
}

}

}

JSI NA ADMINU a jsi přihlášen!! :))
102 changes: 102 additions & 0 deletions HackatonApp/Components/Pages/Register.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@page "/register"
@using HackatonApp.Selectors.User
@inject HttpClient Http
@rendermode InteractiveServer
@inject Blazored.LocalStorage.ILocalStorageService localStorage
@inject NavigationManager NavigationManager

@code {
private string? _email;
private string? _password;
private string? _passwordAgain;


private void UpdateHeading()
{
Console.WriteLine("Update heading");
}

private class LoginResponse()
{
public string Token { get; set; }
}

/// <summary>
/// Do log in method
/// </summary>
private async void DoRegister()
{
if (_password != _passwordAgain)
{
Console.WriteLine("Passwords do not match");
return;
}

var payload = new UserLoginSelector()
{
Email = _email,
Password = _password
};
var user = await Http.PostAsJsonAsync("api/user/register", payload);

if (!user.IsSuccessStatusCode)
{
Console.WriteLine("Error" + user.StatusCode);
return;
}

var response = await user.Content.ReadFromJsonAsync<LoginResponse>();
Console.WriteLine(response.Token);

await localStorage.SetItemAsStringAsync("token", response.Token);
var name = await localStorage.GetItemAsStringAsync("token");
Console.WriteLine("test:" + name);

if (user != null)
{
NavigationManager.NavigateTo("/dashboard");
}
}
}

<section class="md:h-screen py-36 flex items-center relative overflow-hidden zoom-image">
<div class="absolute inset-0 image-wrap z-1 bg-[url('../../assets/images/bg/01.jpg')] bg-no-repeat bg-center bg-cover"></div>
<div class="absolute inset-0 bg-gradient-to-b from-transparent to-black z-2" id="particles-snow"></div>
<div class="container relative z-3">
<div class="flex justify-center">
<div class="max-w-[400px] w-full m-auto p-6 bg-white dark:bg-slate-900 shadow-md dark:shadow-gray-700 rounded-md">
<h5 class="my-6 text-xl font-semibold">Register</h5>

<div class="grid grid-cols-1">
<div class="mb-4">
<label class="font-medium" for="LoginEmail">Email Address:</label>
<input id="LoginEmail" @bind="_email" type="email" class="form-input mt-3" placeholder="[email protected]">
</div>

<div class="mb-4">
<label class="font-medium" for="LoginPassword">Password:</label>
<input id="LoginPassword" @bind="_password" type="password" class="form-input mt-3" placeholder="Password:">
</div>

<div class="mb-4">
<label class="font-medium" for="LoginPasswordAgain">Password Again:</label>
<input id="LoginPasswordAgain" @bind="_passwordAgain" type="password" class="form-input mt-3" placeholder="Password:">
</div>

<div class="mb-4">
<button @onclick="DoRegister" class="btn bg-green-600 hover:bg-green-700 text-white rounded-md w-full">Register</button>
</div>

<div class="text-center">
<span class="text-slate-400 me-2">Do you have an account ?</span> <a href="/login" class="text-black dark:text-white font-bold">Login</a>
</div>
</div>
</div>
</div>
</div>
</section>
<!--
<div class="fixed bottom-3 end-3 z-10">
<a href="" class="back-button btn btn-icon bg-green-600 hover:bg-green-700 text-white rounded-full"><i data-feather="arrow-left" class="h-4 w-4"></i></a>
</div> -->

88 changes: 88 additions & 0 deletions HackatonApp/Components/Pages/Search.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
@page "/search"

<!-- Start Hero -->
<section class="relative table w-full py-32 lg:py-36 bg-[url('../../assets/images/bg/01.jpg')] bg-no-repeat bg-center bg-cover">
<div class="absolute inset-0 bg-black opacity-80"></div>
<div class="container relative">
<div class="grid grid-cols-1 text-center mt-10">
<h3 class="md:text-4xl text-3xl md:leading-normal leading-normal font-medium text-white">Grid View Layout</h3>
</div><!--end grid-->
</div><!--end container-->
</section><!--end section-->
<div class="relative">
<div class="shape overflow-hidden z-1 text-white dark:text-slate-900">
<svg viewBox="0 0 2880 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 48H1437.5H2880V0H2160C1442.5 52 720 0 720 0H0V48Z" fill="currentColor"></path>
</svg>
</div>
</div>
<div class="container relative -mt-16 z-1">
<div class="grid grid-cols-1">
<form class="p-6 bg-white dark:bg-slate-900 rounded-xl shadow-md dark:shadow-gray-700">
<div class="registration-form text-dark text-start">
<div class="grid lg:grid-cols-4 md:grid-cols-2 grid-cols-1 lg:gap-0 gap-6">
<div>
<label class="form-label font-medium text-slate-900 dark:text-white">Search : <span class="text-red-600">*</span></label>
<div class="filter-search-form relative filter-border mt-2">
<i class="uil uil-search icons"></i>
<input name="name" type="text" id="job-keyword" class="form-input filter-input-box bg-gray-50 dark:bg-slate-800 border-0" placeholder="Search your keaywords">
</div>
</div>


<div>
<label for="buy-properties" class="form-label font-medium text-slate-900 dark:text-white">Select Categories:</label>
<div class="filter-search-form relative filter-border mt-2">
<i class="uil uil-estate icons"></i>
<select class="form-select z-2" data-trigger name="choices-catagory" id="choices-catagory-buy" aria-label="Default select example">
<option>Houses</option>
<option>Apartment</option>
<option>Offices</option>
<option>Townhome</option>
</select>
</div>
</div>

<div>
<label for="buy-min-price" class="form-label font-medium text-slate-900 dark:text-white">Min Price :</label>
<div class="filter-search-form relative filter-border mt-2">
<i class="uil uil-usd-circle icons"></i>
<select class="form-select" data-trigger name="choices-min-price" id="choices-min-price-buy" aria-label="Default select example">
<option>Min Price</option>
<option>500</option>
<option>1000</option>
<option>2000</option>
<option>3000</option>
<option>4000</option>
<option>5000</option>
<option>6000</option>
</select>
</div>
</div>

<div>
<label for="buy-max-price" class="form-label font-medium text-slate-900 dark:text-white">Max Price :</label>
<div class="filter-search-form relative mt-2">
<i class="uil uil-usd-circle icons"></i>
<select class="form-select" data-trigger name="choices-max-price" id="choices-max-price-buy" aria-label="Default select example">
<option>Max Price</option>
<option>500</option>
<option>1000</option>
<option>2000</option>
<option>3000</option>
<option>4000</option>
<option>5000</option>
<option>6000</option>
</select>
</div>
</div>

<div class="lg:mt-6">
<input type="submit" id="search-buy" name="search" class="btn bg-green-600 hover:bg-green-700 border-green-600 hover:border-green-700 text-white searchbtn submit-btn w-full !h-12 rounded" value="Search">
</div>
</div><!--end grid-->
</div><!--end container-->
</form><!--end form-->
</div><!--end grid-->
</div><!--end container-->
<!-- End Hero -->
3 changes: 2 additions & 1 deletion HackatonApp/Controllers/User/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public async Task<IActionResult> Login([FromBody]UserLoginSelector login)
[Route("register")]
public async Task<IActionResult> Register([FromBody]UserRegisterSelector register)
{
if (await authService.RegisterUser(register))
var registerValid = await authService.RegisterUser(register);
if (registerValid)
return Ok();

return BadRequest();
Expand Down
9 changes: 9 additions & 0 deletions HackatonApp/Selectors/User/UserRegisterSelector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace HackatonApp.Selectors.User;

/// <summary>
/// User register selector
/// </summary>
public class UserRegisterSelector
{
/// <summary>
/// User email
/// </summary>
public string Email { get; set; }
/// <summary>
/// User password - to be hashed
/// </summary>
public string Password { get; set; }
}
7 changes: 6 additions & 1 deletion HackatonApp/Services/User/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class AuthService(MyContext context, ILogger<AuthService> logger) : IAuth
return hashedPassword.SequenceEqual(user.Password) ? GenerateJSONWebToken(user) : null;
}

/// <summary>
/// Will register a user in the database with standard info
/// </summary>
/// <param name="register"></param>
/// <returns></returns>
public async Task<bool> RegisterUser(UserRegisterSelector register)
{
try
Expand All @@ -44,7 +49,7 @@ public async Task<bool> RegisterUser(UserRegisterSelector register)
Password = System.Security.Cryptography.SHA512.HashData(Encoding.UTF8.GetBytes(register.Password)),
Role = UserRoles.User
};
context.Users.Add(user);
await context.Users.AddAsync(user);
await context.SaveChangesAsync();
return true;
}
Expand Down

0 comments on commit 9557ecc

Please sign in to comment.