mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
Compare commits
26 Commits
5da58ee030
...
DtoBuilder
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a4c24660 | |||
| 271bf84467 | |||
|
|
fd97b2c2d9 | ||
| 42fd94e5ac | |||
| 07128948b0 | |||
| efb71b24d3 | |||
|
|
aa5caf4375 | ||
|
|
26635b4e88 | ||
|
|
7e3759927f | ||
|
|
b440a0334c | ||
|
|
69895f4f35 | ||
|
|
5d362e2a39 | ||
|
|
a81a57654c | ||
| 426288d728 | |||
| 72fbfe982f | |||
| 4be57c27d9 | |||
| b9a7ca08f5 | |||
| a83d8e963a | |||
|
|
9306c90ad6 | ||
| 239b588175 | |||
| 32027f7384 | |||
|
|
e47fd77333 | ||
|
|
2a8fff39c9 | ||
|
|
b194819b6e | ||
|
|
48184cd8b6 | ||
|
|
f2ccde2ea6 |
5
.editorconfig
Normal file
5
.editorconfig
Normal file
@@ -0,0 +1,5 @@
|
||||
[*]
|
||||
end_of_line = crlf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
@@ -1,18 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
|
||||
// Output values in JSON file
|
||||
public record class EventDetailsDto
|
||||
(
|
||||
int EventId,
|
||||
[Required] int? OrganisationId,
|
||||
[Required] string? OrganisationName,
|
||||
[Required][StringLength(50)] string Title,
|
||||
[StringLength(500)] string Description,
|
||||
[Required][StringLength(100)] string Location,
|
||||
[Required] DateTime? EventDate,
|
||||
ICollection<EventSkill> EventSkills,
|
||||
ICollection<EventRegistration> EventRegistrations
|
||||
);
|
||||
{
|
||||
public int EventId { get; set; }
|
||||
[Required] public int? OrganisationId { get; set; }
|
||||
[Required] public string? OrganisationName { get; set; }
|
||||
[Required][StringLength(50)] public string Title { get; set; }
|
||||
[StringLength(500)] public string Description { get; set; }
|
||||
[Required][StringLength(100)] public string Location { get; set; }
|
||||
[Required] public DateTime? EventDate { get; set; }
|
||||
//ICollection<EventSkill> EventSkills,
|
||||
public ICollection<SkillSummaryDto> EventSkills { get; set; }
|
||||
public ICollection<EventRegistrationDto> EventRegistrations { get; set; }
|
||||
|
||||
public EventDetailsDto() { }
|
||||
};
|
||||
|
||||
15
WebApp/DTOs/EventRegistrationDto.cs
Normal file
15
WebApp/DTOs/EventRegistrationDto.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
|
||||
public record class EventRegistrationDto
|
||||
{
|
||||
public int EventId { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public DateTime RegisteredAt { get; set; }
|
||||
|
||||
public EventRegistrationDto() { }
|
||||
|
||||
};
|
||||
@@ -9,7 +9,9 @@ public record class EventSearchDto
|
||||
int? OrganisationId,
|
||||
string? TitleOrDescription,
|
||||
string? Location,
|
||||
DateTime? EventDate,
|
||||
DateTime? EventDateFrom, // zakres daty od
|
||||
DateTime? EventDateTo, // zakres daty do
|
||||
ICollection<EventSkill>? EventSkills, // obecnie nie dotyczy
|
||||
ICollection<EventRegistration>? EventRegistrations // obecnie nie dotyczy
|
||||
|
||||
);
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
|
||||
// Output values in JSON file
|
||||
public record class EventSummaryDto(
|
||||
int EventId,
|
||||
[Required] string Organisation,
|
||||
[Required] int OrganisationId,
|
||||
[Required] [StringLength(50)] string Title,
|
||||
[StringLength(500)] string Description,
|
||||
[Required] [StringLength(100)] string Location,
|
||||
[Required] DateTime? EventDate,
|
||||
ICollection<EventSkill> EventSkills,
|
||||
ICollection<EventRegistration> EventRegistrations
|
||||
);
|
||||
public record class EventSummaryDto {
|
||||
public int EventId { get; set; }
|
||||
[Required] public string Organisation { get; set; }
|
||||
[Required] public int OrganisationId { get; set; }
|
||||
[Required] [StringLength(50)] public string Title { get; set; }
|
||||
[StringLength(500)] public string Description { get; set; }
|
||||
[Required] [StringLength(100)] public string Location { get; set; }
|
||||
[Required] public DateTime? EventDate { get; set; }
|
||||
public ICollection<SkillSummaryDto> EventSkills { get; set; }
|
||||
public ICollection<EventRegistrationDto> EventRegistrations { get; set; }
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
@@ -13,4 +13,5 @@ public record class EventSummaryNoErDto(
|
||||
[Required][StringLength(100)] string Location,
|
||||
[Required] DateTime? EventDate,
|
||||
ICollection<EventSkill> EventSkills
|
||||
// ICollection<SkillSummaryDto> EventSkills
|
||||
);
|
||||
|
||||
8
WebApp/DTOs/SingleSkillDto.cs
Normal file
8
WebApp/DTOs/SingleSkillDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
|
||||
public record class SingleSkillDto
|
||||
(
|
||||
[Required] int Skill
|
||||
);
|
||||
13
WebApp/DTOs/SkillSummaryDto.cs
Normal file
13
WebApp/DTOs/SkillSummaryDto.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.DTOs;
|
||||
|
||||
public record class SkillSummaryDto
|
||||
{
|
||||
public int? SkillId { get; set; }
|
||||
public string? SkillName { get; set; }
|
||||
|
||||
public SkillSummaryDto() { }
|
||||
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
@@ -19,6 +18,7 @@ namespace WebApp.Endpoints
|
||||
var group = app.MapGroup("api/auth")
|
||||
.WithParameterValidation();
|
||||
|
||||
// POST /api/auth/login
|
||||
group.MapPost("/login", async (LoginDto dto, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||
{
|
||||
var user = await context.WebUsers.FirstOrDefaultAsync(u => u.Email == dto.Email);
|
||||
@@ -39,6 +39,7 @@ namespace WebApp.Endpoints
|
||||
});
|
||||
});
|
||||
|
||||
// POST /api/auth/logout
|
||||
group.MapPost("/logout", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
||||
{
|
||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
@@ -55,6 +56,7 @@ namespace WebApp.Endpoints
|
||||
return Results.Ok(new { success = true });
|
||||
});
|
||||
|
||||
// GET /api/auth/my_account
|
||||
group.MapGet("/my_account", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
||||
{
|
||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
@@ -78,6 +80,7 @@ namespace WebApp.Endpoints
|
||||
})
|
||||
.WithName(GetUserEndpointName);
|
||||
|
||||
// GET /api/auth/my_events
|
||||
group.MapGet("/my_events", async (HttpContext httpContext, GeneralUseHelpers guh, ApplicationDbContext context) =>
|
||||
{
|
||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
@@ -96,9 +99,16 @@ namespace WebApp.Endpoints
|
||||
|
||||
if(!user.IsOrganisation)
|
||||
{
|
||||
var events = await context.EventRegistrations
|
||||
|
||||
var eventIds = await context.EventRegistrations
|
||||
.Where(er => er.UserId == user.UserId)
|
||||
.Select(er => er.Event.ToEventSummaryNoErDto())
|
||||
.Select(er => er.EventId)
|
||||
.ToListAsync();
|
||||
|
||||
var events = await context.Events
|
||||
.Where(e => eventIds.Contains(e.EventId))
|
||||
.Include(e => e.Organisation)
|
||||
.Select(e => e.ToEventSummaryDto())
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Ok(events);
|
||||
@@ -123,6 +133,110 @@ namespace WebApp.Endpoints
|
||||
|
||||
});
|
||||
|
||||
// POST /api/auth/add_skill
|
||||
group.MapPost("/add_skill", async (SingleSkillDto dto, HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||
{
|
||||
// Uzyskaj użytkownika z tokenu
|
||||
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guh.GetUserFromToken(token);
|
||||
|
||||
// Tylko wolontariusze powinni móc dodawać swoje skille
|
||||
if (user == null || user.IsOrganisation) {
|
||||
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||
}
|
||||
|
||||
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||
Skill? skill = await context.Skills.FindAsync(dto.Skill);
|
||||
if (skill is null)
|
||||
{
|
||||
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||
}
|
||||
|
||||
// Sprawdzamy, czy ten użytkownik nie ma już takiego skilla. Jeżeli ma, nie ma sensu dodawać go kilkukrotnie.
|
||||
VolunteerSkill? vs = await context.VolunteerSkills.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SkillId == dto.Skill);
|
||||
if (vs is null)
|
||||
{
|
||||
// Nie ma - zatem musimy dodać nowy VolunteerSkill do bazy
|
||||
VolunteerSkill newVs = dto.ToVolunteerSkillEntity(user.UserId);
|
||||
context.VolunteerSkills.Add(newVs);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
} else
|
||||
{
|
||||
// Ma - (ta para UserId <-> SkillId już istnieje w bazie) użytkownik już ma ten skill
|
||||
return Results.Json(new { message = "You already have this skill!" }, statusCode: 400);
|
||||
}
|
||||
|
||||
return Results.Json(new { message = "Skill added successfully!" }, statusCode: 201);
|
||||
});
|
||||
|
||||
// POST /api/auth/remove_skill
|
||||
group.MapPost("/remove_skill", async (SingleSkillDto dto, HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||
{
|
||||
// Uzyskaj użytkownika z tokenu
|
||||
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guh.GetUserFromToken(token);
|
||||
|
||||
// Tylko wolontariusze powinni móc usuwać swoje skille
|
||||
if (user == null || user.IsOrganisation)
|
||||
{
|
||||
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||
}
|
||||
|
||||
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||
Skill? skill = await context.Skills.FindAsync(dto.Skill);
|
||||
if (skill is null)
|
||||
{
|
||||
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||
}
|
||||
|
||||
// Sprawdzamy, czy ten użytkownik ma już taki skill. Jeżeli nie ma, to nie ma sensu usuwać czegoś, czego nie ma.
|
||||
VolunteerSkill? vs = await context.VolunteerSkills.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SkillId == dto.Skill);
|
||||
if (vs is not null)
|
||||
{
|
||||
// Ma - zatem musimy usunąć otrzymany VolunteerSkill z bazy
|
||||
VolunteerSkill newVs = dto.ToVolunteerSkillEntity(user.UserId);
|
||||
|
||||
await context.VolunteerSkills.Where(v => v.SkillId == dto.Skill)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nie ma - (ta para UserId <-> SkillId nie istnieje w bazie). Zwracamy błąd.
|
||||
return Results.Json(new { message = "You don't have this skill" }, statusCode: 400);
|
||||
}
|
||||
|
||||
return Results.Json(new { message = "Skill deleted successfully!" }, statusCode: 201);
|
||||
});
|
||||
|
||||
// GET /api/auth/skills
|
||||
group.MapGet("/skills", async (HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||
{
|
||||
// Uzyskaj użytkownika z tokenu
|
||||
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guh.GetUserFromToken(token);
|
||||
|
||||
// Sprawdź, czy użytkownik istnieje i nie jest organizacją
|
||||
if (user == null || user.IsOrganisation)
|
||||
{
|
||||
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||
}
|
||||
|
||||
// Pobierz skille wolontariusza
|
||||
var skills = await context.VolunteerSkills
|
||||
.Where(vs => vs.UserId == user.UserId)
|
||||
.Include(vs => vs.Skill)
|
||||
.Select(vs => new
|
||||
{
|
||||
skillId = vs.Skill!.SkillId,
|
||||
skillName = vs.Skill.Name
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(skills);
|
||||
});
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
135
WebApp/Endpoints/EventRegistrationEndpoints.cs
Normal file
135
WebApp/Endpoints/EventRegistrationEndpoints.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Cryptography;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
using WebApp.Mapping;
|
||||
|
||||
namespace WebApp.Endpoints
|
||||
{
|
||||
public static class EventsRegistrationEndpoints
|
||||
{
|
||||
const string GetEventEndpointRegistrationName = "GetEventRegistration";
|
||||
|
||||
public static RouteGroupBuilder MapEventsRegistrationEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("api/events")
|
||||
.WithParameterValidation();
|
||||
|
||||
// POST /api/events/join/{id}
|
||||
group.MapPost("/join/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
if (Eve is null)
|
||||
return Results.Json(new { success = false, error_msg = "Event not found." });
|
||||
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guhf.GetUserFromToken(token);
|
||||
|
||||
if (user is null || user.IsOrganisation)
|
||||
return Results.Json(new { success = false, error_msg = "Unauthorized or organisations cannot register for events." });
|
||||
|
||||
if (await dbContext.EventRegistrations.AnyAsync(er => er.UserId == user.UserId && er.EventId == id))
|
||||
return Results.Json(new { success = false, error_msg = "You are already registered for this event." });
|
||||
|
||||
if (Eve.EventDate < DateTime.UtcNow)
|
||||
return Results.Json(new { success = false, error_msg = "This event has already ended." });
|
||||
|
||||
EventRegistration registration = new EventRegistration
|
||||
{
|
||||
UserId = user.UserId,
|
||||
EventId = id,
|
||||
RegisteredAt = DateTime.UtcNow
|
||||
};
|
||||
dbContext.EventRegistrations.Add(registration);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
return Results.Json(new { success = true });
|
||||
});
|
||||
|
||||
// POST /api/events/leave/{id}
|
||||
group.MapPost("/leave/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
if (Eve is null)
|
||||
return Results.Json(new { success = false, error_msg = "Event not found." });
|
||||
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
User? user = await guhf.GetUserFromToken(token);
|
||||
|
||||
if (user is null)
|
||||
return Results.Json(new { success = false, error_msg = "Unauthorized." });
|
||||
|
||||
if (!await dbContext.EventRegistrations.AnyAsync(er => er.UserId == user.UserId && er.EventId == id))
|
||||
return Results.Json(new { success = false, error_msg = "You are not registered for this event." });
|
||||
|
||||
if (Eve.EventDate < DateTime.UtcNow)
|
||||
return Results.Json(new { success = false, error_msg = "This event has already ended." });
|
||||
|
||||
EventRegistration? registration = await dbContext.EventRegistrations
|
||||
.FirstOrDefaultAsync(er => er.UserId == user.UserId && er.EventId == id);
|
||||
|
||||
dbContext.EventRegistrations.Remove(registration);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
return Results.Json(new { success = true });
|
||||
});
|
||||
|
||||
// GET /api/events/registrations/{id}
|
||||
group.MapGet("/registrations/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
if (Eve is null)
|
||||
return Results.Json(new { success = false, error_msg = "Event not found." });
|
||||
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId)
|
||||
return Results.Json(new { success = false, error_msg = "Unauthorized." });
|
||||
|
||||
var registrations = await dbContext.EventRegistrations
|
||||
.Where(er => er.EventId == id)
|
||||
.Select(er => er.ToEventRegistrationDto())
|
||||
.ToListAsync();
|
||||
|
||||
return Results.Json(new
|
||||
{
|
||||
success = true,
|
||||
registrations
|
||||
});
|
||||
});
|
||||
|
||||
// POST /api/events/remove/{id}/{userId}
|
||||
group.MapPost("/remove/{id}/{userId}",
|
||||
async (int id, int userId, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
if (Eve is null)
|
||||
return Results.Json(new { success = false, error_msg = "Event not found." });
|
||||
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId)
|
||||
return Results.Json(new { success = false, error_msg = "Unauthorized." });
|
||||
|
||||
EventRegistration? registration = await dbContext.EventRegistrations
|
||||
.FirstOrDefaultAsync(er => er.UserId == userId && er.EventId == id);
|
||||
|
||||
if (registration is null)
|
||||
return Results.Json(new { success = false, error_msg = "Registration not found." });
|
||||
|
||||
dbContext.EventRegistrations.Remove(registration);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
return Results.Json(new { success = true });
|
||||
});
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
@@ -18,27 +20,24 @@ namespace WebApp.Endpoints
|
||||
|
||||
// GET /events
|
||||
group.MapGet("/",
|
||||
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
|
||||
async (ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
|
||||
var sort = httpContext.Request.Query["sort"].ToString();
|
||||
IOrderedQueryable<Event> res;
|
||||
var r = dbContext.Events
|
||||
.Include(Eve => Eve.Organisation);
|
||||
// Sprawdź, czy lista powinna by posortowana rosnąco. Domyślnie: malejąco.
|
||||
var sort = httpContext.Request.Query["sort"].ToString().ToUpper();
|
||||
|
||||
if (sort is not null && sort.ToUpper() == "ASC")
|
||||
{
|
||||
res = r.OrderBy(Eve => Eve.EventId);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = r.OrderByDescending(Eve => Eve.EventId);
|
||||
}
|
||||
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
|
||||
List<EventSummaryDto> result = await guhf.BuildSummaryEventsDto(
|
||||
dbContext,
|
||||
org,
|
||||
(sort == "ASC")
|
||||
);
|
||||
|
||||
return Results.Ok(result);
|
||||
|
||||
return await res
|
||||
.Select(Eve => Eve.ToEventSummaryDto()) //EventSummaryDto
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
});
|
||||
|
||||
|
||||
@@ -46,8 +45,11 @@ namespace WebApp.Endpoints
|
||||
group.MapGet("/{id}",
|
||||
async (int id, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
|
||||
Event? Eve = await dbContext
|
||||
.Events
|
||||
.Include(e => e.Organisation)
|
||||
.FirstOrDefaultAsync(e => e.EventId == id);
|
||||
if (Eve is null) return Results.NotFound();
|
||||
|
||||
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||
@@ -55,16 +57,14 @@ namespace WebApp.Endpoints
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||
// przed jego wysłaniem!
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId) Eve.EventRegistrations = [];
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie niech będzie to
|
||||
// puste pole.
|
||||
List<EventDetailsDto> result = await guhf.BuildDetailedEventsDto(
|
||||
dbContext,
|
||||
org
|
||||
);
|
||||
|
||||
// DLACZEGO?
|
||||
Eve.Organisation = await guhf.GetOrganisationFromId(Eve.OrganisationId);
|
||||
|
||||
EventDetailsDto EveDto = Eve.ToEventDetailsDto();
|
||||
|
||||
return Results.Ok(EveDto); //EventDetailsDto
|
||||
return Results.Ok(result.FirstOrDefault(e => e.EventId == id));
|
||||
})
|
||||
.WithName(GetEventEndpointName);
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace WebApp.Endpoints
|
||||
// Uzyskaj organizację z tokenu
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
if (org is null) return Results.StatusCode(403);
|
||||
if (org is null) return Results.Unauthorized();
|
||||
|
||||
// Sprawdź, czy organizacja ma prawo
|
||||
// do usunięcia tego (EventId = id) eventu.
|
||||
@@ -155,15 +155,14 @@ namespace WebApp.Endpoints
|
||||
{
|
||||
|
||||
// Uzyskaj organizację z tokenu
|
||||
var sort = httpContext.Request.Query["sort"].ToString().ToUpper();
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
List<EventSummaryDto> SearchCandidates = await guhf.BuildSummaryEventsDto(dbContext, org, sort == "ASC");
|
||||
List<EventSummaryDto> SearchResults = [];
|
||||
|
||||
List<Event> AllEvents = await dbContext.Events.ToListAsync();
|
||||
AllEvents.Reverse(); // aby wyświetlało od najnowszych wydarzeń
|
||||
|
||||
|
||||
foreach(Event e in AllEvents)
|
||||
foreach(EventSummaryDto e in SearchCandidates)
|
||||
{
|
||||
bool matchFound = true;
|
||||
// Logika wyszukiwania
|
||||
@@ -181,6 +180,19 @@ namespace WebApp.Endpoints
|
||||
if (!TitleMatch && !DescMatch) matchFound = false;
|
||||
}
|
||||
|
||||
|
||||
// Zakres dat do wyszukiwania
|
||||
if (query.EventDateFrom is not null)
|
||||
{
|
||||
if (e.EventDate < query.EventDateFrom) matchFound = false;
|
||||
|
||||
}
|
||||
if (query.EventDateTo is not null)
|
||||
{
|
||||
if (e.EventDate > query.EventDateTo) matchFound = false;
|
||||
}
|
||||
|
||||
|
||||
// ...
|
||||
|
||||
// Jeśli Event jest tym, czego szuka użytkownik,
|
||||
@@ -189,21 +201,102 @@ namespace WebApp.Endpoints
|
||||
// Uwaga! Zanim to zrobisz, sprawdź, czy użytkownik
|
||||
// jest twórcą danego wydarzenia! Jeżeli nim nie jest,
|
||||
// wyzeruj EventRegistrations!
|
||||
if (org is null || e.Organisation != org)
|
||||
if (org is null || e.OrganisationId != org.OrganisationId)
|
||||
{
|
||||
e.EventRegistrations.Clear();
|
||||
}
|
||||
|
||||
// UWAGA! TO NIE POWINNO TAK DZIAŁAĆ!
|
||||
// KTOKOLWIEK WIDZIAŁ, KTOKOLWIEK WIE CZEMU Organisation JEST null?
|
||||
e.Organisation = await guhf.GetOrganisationFromId(e.OrganisationId);
|
||||
|
||||
if (matchFound) SearchResults.Add(e.ToEventSummaryDto());
|
||||
if (matchFound) SearchResults.Add(e);
|
||||
}
|
||||
|
||||
return Results.Ok(SearchResults);
|
||||
});
|
||||
|
||||
// POST /events/1/add_skill
|
||||
group.MapPost("/{id}/add_skill/",
|
||||
async (int id, SingleSkillDto dto, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
|
||||
if (Eve is null) return Results.Json(new { message = "Event not found" }, statusCode: 404);
|
||||
|
||||
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||
// przed jego wysłaniem!
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId) return Results.Unauthorized();
|
||||
|
||||
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||
Skill? skill = await dbContext.Skills.FindAsync(dto.Skill);
|
||||
if (skill is null)
|
||||
{
|
||||
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||
}
|
||||
|
||||
// Sprawdzamy, czy to wydarzenie nie ma już takiego skilla. Jeżeli ma, nie ma sensu dodawać go kilkukrotnie.
|
||||
EventSkill? es = await dbContext.EventSkills.FirstOrDefaultAsync(e => e.EventId == id && e.SkillId == dto.Skill);
|
||||
if (es is null)
|
||||
{
|
||||
// Nie ma - zatem musimy dodać nowy EventSkill do bazy
|
||||
EventSkill newEs = dto.ToEventSkillEntity(Eve.EventId);
|
||||
dbContext.EventSkills.Add(newEs);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ma - (ta para EventId <-> SkillId już istnieje w bazie); ten Event posiada już ten skill
|
||||
return Results.Json(new { message = "Skill already assinged to this event!" }, statusCode: 400);
|
||||
}
|
||||
|
||||
return Results.Json(new { message = "Skill added to event successfully!" }, statusCode: 201);
|
||||
|
||||
});
|
||||
|
||||
// POST /events/1/renive_skill
|
||||
group.MapPost("/{id}/remove_skill/",
|
||||
async (int id, SingleSkillDto dto, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||
{
|
||||
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||
|
||||
if (Eve is null) return Results.Json(new { message = "Event not found" }, statusCode: 404);
|
||||
|
||||
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||
// przed jego wysłaniem!
|
||||
if (org is null || org.OrganisationId != Eve.OrganisationId) return Results.Unauthorized();
|
||||
|
||||
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||
Skill? skill = await dbContext.Skills.FindAsync(dto.Skill);
|
||||
if (skill is null)
|
||||
{
|
||||
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||
}
|
||||
|
||||
// Sprawdzamy, czy to wydarzenie nie ma już takiego skilla. Jeżeli nie ma, to nie ma sensu kasować czegoś, czego nie ma.
|
||||
EventSkill? es = await dbContext.EventSkills.FirstOrDefaultAsync(e => e.EventId == id && e.SkillId == dto.Skill);
|
||||
if (es is not null)
|
||||
{
|
||||
// Ma - zatem musimy usunąć ten EventSkill z bazy
|
||||
await dbContext.EventSkills.Where(e => e.SkillId == dto.Skill)
|
||||
.ExecuteDeleteAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nie ma - (ta para EventId <-> SkillId nie istnieje w bazie); ten Event nie posiada tego skill'a
|
||||
return Results.Json(new { message = "This skill isn't assinged to this event!" }, statusCode: 400);
|
||||
}
|
||||
|
||||
return Results.Json(new { message = "Skill removed from event successfully!" }, statusCode: 201);
|
||||
});
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.Data;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.Endpoints;
|
||||
@@ -35,12 +36,7 @@ public class GeneralUseHelpers
|
||||
User? user = await GetUserFromToken(t);
|
||||
if (user is not null && user.IsOrganisation)
|
||||
{
|
||||
Organisation? org = await _context.Organisations.FirstOrDefaultAsync(o => o.UserId == t.UserId);
|
||||
|
||||
if (org is null)
|
||||
{
|
||||
Console.WriteLine("!!!");
|
||||
}
|
||||
Organisation? org = await _context.Organisations.FirstOrDefaultAsync(o => o.UserId == t!.UserId);
|
||||
|
||||
return org;
|
||||
}
|
||||
@@ -112,4 +108,97 @@ public class GeneralUseHelpers
|
||||
// Sprawdza, czy któreś ze słów pasuje (nawet częściowo) do searchTerm
|
||||
return words.Any(word => word.Contains(searchTerm, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public async Task<List<EventDetailsDto>> BuildDetailedEventsDto(
|
||||
ApplicationDbContext context,
|
||||
Organisation? org,
|
||||
bool sortAscending = false)
|
||||
{
|
||||
// https://khalidabuhakmeh.com/ef-core-and-aspnet-core-cycle-issue-and-solution
|
||||
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie niech będzie to
|
||||
// puste pole.
|
||||
|
||||
IQueryable<EventDetailsDto> result_iq = context
|
||||
.Events
|
||||
.Select(e => new EventDetailsDto
|
||||
{
|
||||
EventId = e.EventId,
|
||||
OrganisationId = e.OrganisationId,
|
||||
OrganisationName = e.Organisation!.Name,
|
||||
Title = e.Title,
|
||||
Description = e.Description ?? "",
|
||||
Location = e.Location,
|
||||
EventDate = e.EventDate,
|
||||
EventSkills = e
|
||||
.EventSkills
|
||||
.Select(es => new SkillSummaryDto
|
||||
{
|
||||
SkillId = es.SkillId,
|
||||
SkillName = es.Skill!.Name
|
||||
}).ToList(),
|
||||
EventRegistrations = e.Organisation == org ?
|
||||
e.EventRegistrations
|
||||
.Select(er => new EventRegistrationDto
|
||||
{
|
||||
EventId = er.EventId,
|
||||
UserId = er.UserId,
|
||||
UserName = er.User!.FirstName + " " + er.User.LastName,
|
||||
RegisteredAt = er.RegisteredAt
|
||||
}).ToList() : null!
|
||||
});
|
||||
|
||||
if (sortAscending) result_iq = result_iq.OrderBy(e => e.EventId);
|
||||
else result_iq = result_iq.OrderByDescending(e => e.EventId);
|
||||
|
||||
|
||||
return await result_iq.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<EventSummaryDto>> BuildSummaryEventsDto(
|
||||
ApplicationDbContext context,
|
||||
Organisation? org,
|
||||
bool sortAscending = false)
|
||||
{
|
||||
// https://khalidabuhakmeh.com/ef-core-and-aspnet-core-cycle-issue-and-solution
|
||||
|
||||
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||
// to zwróć także EventRegistrations. W przeciwnym razie niech będzie to
|
||||
// puste pole.
|
||||
IQueryable<EventSummaryDto> result_iq = context
|
||||
.Events
|
||||
.Select(e => new EventSummaryDto
|
||||
{
|
||||
EventId = e.EventId,
|
||||
OrganisationId = e.OrganisationId,
|
||||
Organisation = e.Organisation!.Name,
|
||||
Title = e.Title,
|
||||
Description = e.Description ?? "",
|
||||
Location = e.Location,
|
||||
EventDate = e.EventDate,
|
||||
EventSkills = e
|
||||
.EventSkills
|
||||
.Select(es => new SkillSummaryDto
|
||||
{
|
||||
SkillId = es.SkillId,
|
||||
SkillName = es.Skill!.Name
|
||||
}).ToList(),
|
||||
EventRegistrations = e.Organisation == org ?
|
||||
e.EventRegistrations
|
||||
.Select(er => new EventRegistrationDto
|
||||
{
|
||||
EventId = er.EventId,
|
||||
UserId = er.UserId,
|
||||
UserName = er.User!.FirstName + " " + er.User.LastName,
|
||||
RegisteredAt = er.RegisteredAt
|
||||
}).ToList() : null!
|
||||
});
|
||||
|
||||
if (sortAscending) result_iq = result_iq.OrderBy(e => e.EventId);
|
||||
else result_iq = result_iq.OrderByDescending(e => e.EventId);
|
||||
|
||||
return await result_iq.ToListAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
26
WebApp/Endpoints/SkillsEndpoints.cs
Normal file
26
WebApp/Endpoints/SkillsEndpoints.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.Data;
|
||||
using WebApp.Mapping;
|
||||
|
||||
namespace WebApp.Endpoints;
|
||||
|
||||
public static class SkillsEndpoints
|
||||
{
|
||||
const string GetSkillEndpointName = "GetSkill";
|
||||
|
||||
public static RouteGroupBuilder MapSkillsEndpoints(this WebApplication app)
|
||||
{
|
||||
var group = app.MapGroup("api/skills").WithParameterValidation();
|
||||
|
||||
// GET /skills
|
||||
group.MapGet("/",
|
||||
async (ApplicationDbContext dbContext) =>
|
||||
await dbContext.Skills
|
||||
.OrderBy(Sk => Sk.SkillId)
|
||||
.Select(Sk => Sk.ToSkillSummaryDto()) // SkillSummaryDto
|
||||
.AsNoTracking()
|
||||
.ToListAsync());
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
|
||||
@@ -34,44 +34,83 @@ public static class EventMapping
|
||||
|
||||
public static EventSummaryDto ToEventSummaryDto(this Event myEvent)
|
||||
{
|
||||
return new EventSummaryDto(
|
||||
myEvent.EventId,
|
||||
myEvent.Organisation!.Name,
|
||||
myEvent.OrganisationId,
|
||||
myEvent.Title,
|
||||
myEvent.Description,
|
||||
myEvent.Location,
|
||||
myEvent.EventDate,
|
||||
myEvent.EventSkills,
|
||||
myEvent.EventRegistrations
|
||||
);
|
||||
|
||||
List<SkillSummaryDto> ssdto = new List<SkillSummaryDto>();
|
||||
List<EventRegistrationDto> erdto = new List<EventRegistrationDto>();
|
||||
|
||||
foreach (EventSkill es in myEvent.EventSkills)
|
||||
{
|
||||
ssdto.Add(es.ToSkillSummaryDto());
|
||||
}
|
||||
|
||||
foreach (EventRegistration er in myEvent.EventRegistrations)
|
||||
{
|
||||
erdto.Add(er.ToEventRegistrationDto());
|
||||
}
|
||||
|
||||
return new EventSummaryDto {
|
||||
EventId = myEvent.EventId,
|
||||
Organisation = myEvent.Organisation!.Name,
|
||||
OrganisationId = myEvent.OrganisationId,
|
||||
Title = myEvent.Title,
|
||||
Description = myEvent.Description ?? "",
|
||||
Location = myEvent.Location,
|
||||
EventDate = myEvent.EventDate,
|
||||
EventSkills = ssdto,
|
||||
EventRegistrations = erdto
|
||||
};
|
||||
}
|
||||
public static EventSummaryNoErDto ToEventSummaryNoErDto(this Event myEvent)
|
||||
{
|
||||
|
||||
return new EventSummaryNoErDto(
|
||||
myEvent.EventId,
|
||||
myEvent.Organisation!.Name,
|
||||
myEvent.OrganisationId,
|
||||
myEvent.Title,
|
||||
myEvent.Description,
|
||||
myEvent.Description ?? "",
|
||||
myEvent.Location,
|
||||
myEvent.EventDate,
|
||||
myEvent.EventSkills
|
||||
);
|
||||
}
|
||||
|
||||
public static EventRegistrationDto ToEventRegistrationDto(this EventRegistration myER)
|
||||
{
|
||||
|
||||
return new EventRegistrationDto {
|
||||
EventId = myER.EventId,
|
||||
UserId = myER.UserId,
|
||||
UserName = myER.User!.FirstName + " " + myER.User!.LastName,
|
||||
RegisteredAt = myER.RegisteredAt
|
||||
};
|
||||
}
|
||||
|
||||
public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
|
||||
{
|
||||
return new EventDetailsDto(
|
||||
myEvent.EventId,
|
||||
myEvent.OrganisationId,
|
||||
myEvent.Organisation.Name,
|
||||
myEvent.Title,
|
||||
myEvent.Description,
|
||||
myEvent.Location,
|
||||
myEvent.EventDate,
|
||||
myEvent.EventSkills,
|
||||
myEvent.EventRegistrations
|
||||
);
|
||||
List<SkillSummaryDto> ssdto = new List<SkillSummaryDto>();
|
||||
List<EventRegistrationDto> erdto = new List<EventRegistrationDto>();
|
||||
|
||||
foreach (EventSkill es in myEvent.EventSkills)
|
||||
{
|
||||
ssdto.Add(es.ToSkillSummaryDto());
|
||||
}
|
||||
|
||||
foreach (EventRegistration er in myEvent.EventRegistrations)
|
||||
{
|
||||
erdto.Add(er.ToEventRegistrationDto());
|
||||
}
|
||||
|
||||
return new EventDetailsDto {
|
||||
EventId = myEvent.EventId,
|
||||
OrganisationId = myEvent.OrganisationId,
|
||||
OrganisationName = myEvent.Organisation!.Name,
|
||||
Title = myEvent.Title,
|
||||
Description = myEvent.Description ?? "",
|
||||
Location = myEvent.Location,
|
||||
EventDate = myEvent.EventDate,
|
||||
EventSkills = ssdto,
|
||||
EventRegistrations = erdto
|
||||
};
|
||||
}
|
||||
}
|
||||
24
WebApp/Mapping/EventSkillMapping.cs
Normal file
24
WebApp/Mapping/EventSkillMapping.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.Mapping;
|
||||
|
||||
public static class EventSkillMapping
|
||||
{
|
||||
public static EventSkill ToEventSkillEntity(this SingleSkillDto SSDto, int eid)
|
||||
{
|
||||
return new EventSkill()
|
||||
{
|
||||
EventId = eid,
|
||||
SkillId = SSDto.Skill,
|
||||
};
|
||||
}
|
||||
|
||||
public static SkillSummaryDto ToSkillSummaryDto(this EventSkill es)
|
||||
{
|
||||
return new SkillSummaryDto{
|
||||
SkillId = es.SkillId,
|
||||
SkillName = es.Skill.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
25
WebApp/Mapping/SkillMapping.cs
Normal file
25
WebApp/Mapping/SkillMapping.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.Mapping
|
||||
{
|
||||
public static class SkillMapping
|
||||
{
|
||||
public static Skill ToSkillEntity(this SingleSkillDto SSDto, string name)
|
||||
{
|
||||
return new Skill()
|
||||
{
|
||||
SkillId = SSDto.Skill,
|
||||
Name = name
|
||||
};
|
||||
}
|
||||
|
||||
public static SkillSummaryDto ToSkillSummaryDto(this Skill s)
|
||||
{
|
||||
return new SkillSummaryDto {
|
||||
SkillId = s.SkillId,
|
||||
SkillName = s.Name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
16
WebApp/Mapping/VolunteerSkillMapping.cs
Normal file
16
WebApp/Mapping/VolunteerSkillMapping.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using WebApp.DTOs;
|
||||
using WebApp.Entities;
|
||||
|
||||
namespace WebApp.Mapping;
|
||||
|
||||
public static class VolunteerSkillMapping
|
||||
{
|
||||
public static VolunteerSkill ToVolunteerSkillEntity(this SingleSkillDto SSDto, int uid)
|
||||
{
|
||||
return new VolunteerSkill()
|
||||
{
|
||||
UserId = uid,
|
||||
SkillId = SSDto.Skill,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -53,5 +53,7 @@ app.UseRouting(); // Enables routing to match incoming request to endpoints
|
||||
app.MapEventsEndpoints();
|
||||
app.MapOrganizationsEndpoints();
|
||||
app.MapAuthEndpoints();
|
||||
app.MapSkillsEndpoints();
|
||||
app.MapEventsRegistrationEndpoints();
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -4,18 +4,17 @@ function deleteCookie(name: string): void {
|
||||
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
}
|
||||
|
||||
function logoutUser(): void {
|
||||
// Inform backend to remove cookie if necessary
|
||||
fetch('/api/logout', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}).catch((err) => console.warn('Logout request failed:', err));
|
||||
async function logoutUser(): Promise<void> {
|
||||
await fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
// Clear the auth cookie
|
||||
deleteCookie('token');
|
||||
|
||||
// Redirect to login page
|
||||
window.location.href = 'index.html';
|
||||
window.location.href = "/index.html";
|
||||
}
|
||||
|
||||
function redirectToLogin(): void {
|
||||
@@ -46,7 +45,10 @@ function setupAuthUI(): void {
|
||||
|
||||
if (logoutBtn) {
|
||||
logoutBtn.classList.toggle('d-none', !isAuthenticated);
|
||||
logoutBtn.addEventListener('click', logoutUser);
|
||||
logoutBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
logoutUser();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
|
||||
var isAscending: boolean = false;
|
||||
|
||||
@@ -57,10 +57,17 @@ async function loadEvents(org_id: number, evs?: Promise<any>) {
|
||||
//card.innerHTML = `
|
||||
// <span>${ev.title}</span>`
|
||||
// Do odkomentowania kiedy widok podglądu wydarzeń będzie gotowy
|
||||
let formattedDate: string = new Intl.DateTimeFormat('en-US', {
|
||||
weekday: 'long', // "Monday"
|
||||
year: 'numeric', // "2023"
|
||||
month: 'long', // "December"
|
||||
day: 'numeric' // "1"
|
||||
}).format(ev.eventDate);
|
||||
console.log(formattedDate);
|
||||
card.innerHTML = `
|
||||
<span>
|
||||
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
|
||||
<p style="margin: 0">${ev.organisation}</p>
|
||||
<p style="margin: 0">${ev.organisation} | ${ev.location} | ${formattedDate}</p>
|
||||
</span>`
|
||||
if (org_id == ev.organisationId) {
|
||||
card.innerHTML += `
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
import { getEvent, getMyAccount, unhideElementById, getMyRegisteredEventIds } from './generalUseHelpers.js';
|
||||
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
@@ -9,6 +9,8 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
var container = document.getElementById("mainContainer");
|
||||
const modifyBtn = document.getElementById("editBtn");
|
||||
const removeBtn = document.getElementById("removeBtn");
|
||||
const applyBtn = document.getElementById("applyBtn");
|
||||
const leaveBtn = document.getElementById("leaveBtn");
|
||||
var org_id: number = -1;
|
||||
|
||||
try {
|
||||
@@ -28,11 +30,11 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
try {
|
||||
if (eventId) thisEvent = await getEvent(eventId);
|
||||
} catch (err) {
|
||||
if (container !== null) container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||
if (container !== null) container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powr<EFBFBD>t -></a></p>`;
|
||||
}
|
||||
|
||||
if (thisEvent == null) {
|
||||
if (container !== null) container.innerHTML = `<p class="text-danger">B³¹d we wczytywaniu wydarzenia. <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||
if (container !== null) container.innerHTML = `<p class="text-danger">Błąd we wczytywaniu wydarzenia. <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||
} else {
|
||||
|
||||
const titleText = document.getElementById( "titleText") as HTMLElement;
|
||||
@@ -51,14 +53,28 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
organizerText.innerHTML = "Organized by: " + thisEvent.organisationName;
|
||||
|
||||
if (org_id == thisEvent.organisationId) {
|
||||
// U¿ytkownik jest organizacj¹, która
|
||||
// stworzy³a to wydarzenie
|
||||
// Użytkownik jest organizacją, która
|
||||
// stworzyła to wydarzenie
|
||||
unhideElementById(document, "editBtn");
|
||||
unhideElementById(document, "removeBtn");
|
||||
} else if (org_id == -1) {
|
||||
// U¿ytkownik jest wolontariuszem
|
||||
// Użytkownik jest wolontariuszem
|
||||
try {
|
||||
const registeredIds = await getMyRegisteredEventIds();
|
||||
const isRegistered = registeredIds.includes(Number(eventId));
|
||||
|
||||
if (isRegistered) {
|
||||
unhideElementById(document, "leaveBtn");
|
||||
} else {
|
||||
unhideElementById(document, "applyBtn");
|
||||
}
|
||||
} catch {
|
||||
unhideElementById(document, "applyBtn");
|
||||
(applyBtn as HTMLButtonElement).textContent = "log in to apply";
|
||||
(applyBtn as HTMLButtonElement).disabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unhideElementById(document, "mainContainer");
|
||||
|
||||
@@ -76,7 +92,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
if (!confirmed) return;
|
||||
|
||||
try {
|
||||
// Wysy³a ¿¹danie DELETE do API
|
||||
// Wysyła żądanie DELETE do API
|
||||
const response = await fetch(`/api/events/${eventId}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
@@ -94,4 +110,59 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
});
|
||||
}
|
||||
|
||||
if (applyBtn) {
|
||||
applyBtn.addEventListener("click", async (e) => {
|
||||
try {
|
||||
const response = await fetch(`/api/events/join/${eventId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
});
|
||||
|
||||
const result: {
|
||||
success: boolean;
|
||||
error_msg?: string;
|
||||
} = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = `/view.html?event=${eventId}`;
|
||||
} else {
|
||||
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to apply:", error);
|
||||
alert("Failed to apply.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (leaveBtn) {
|
||||
leaveBtn.addEventListener("click", async (e) => {
|
||||
try {
|
||||
const response = await fetch(`/api/events/leave/${eventId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
});
|
||||
|
||||
const result: {
|
||||
success: boolean;
|
||||
error_msg?: string;
|
||||
} = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
window.location.href = `/view.html?event=${eventId}`;
|
||||
} else {
|
||||
alert(`Error: ${result.error_msg ?? "Unknown error occurred."}`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to leave:", error)
|
||||
alert("Failed to leave.")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -36,9 +36,20 @@ export async function getEvent(id: string): Promise<EventData> {
|
||||
export async function getMyAccount(): Promise<MyAccount> {
|
||||
const res = await fetch("/api/auth/my_account");
|
||||
if (!res.ok) {
|
||||
throw Error("U¿ytkownik niezalogowany!");
|
||||
throw Error("Użytkownik niezalogowany!");
|
||||
}
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getMyRegisteredEventIds(): Promise<number[]> {
|
||||
const res = await fetch("/api/auth/my_events");
|
||||
|
||||
if (!res.ok) {
|
||||
throw Error("Użytkownik niezalogowany!");
|
||||
}
|
||||
|
||||
const events = await res.json();
|
||||
|
||||
return events.map((event: { eventId: number }) => event.eventId);
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@
|
||||
|
||||
<script type="module" src="/js/eventCreate.js"></script>
|
||||
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||
<script type="module" src="/js/auth.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
@@ -70,7 +70,7 @@
|
||||
<h2 class="eventsText">Events</h2>
|
||||
<span class="position-absolute end-0 translate-middle-y me-4" style="margin-top: 20px;">
|
||||
<button class="btn btn-link" onclick="">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M440-120v-240h80v80h320v80H520v80h-80ZŁm-320-80v-80h240v80H120Zm160-160v-80H120v-80h160v-80h80v240h-80Zm160-80v-80h400v80H440Zm160-160v-240h80v80h160v80H680v80h-80Zm-480-80v-80h400v80H120Z" /></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M440-120v-240h80v80h320v80H520v80h-80Zm-320-80v-80h240v80H120Zm160-160v-80H120v-80h160v-80h80v240h-80Zm160-80v-80h400v80H440Zm160-160v-240h80v80h160v80H680v80h-80Zm-480-80v-80h400v80H120Z" /></svg>
|
||||
</button>
|
||||
<button class="btn btn-link" id="list-sort-btn" onclick=""><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z" /></svg></button>
|
||||
</span>
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
"use strict";
|
||||
// /js/auth.ts
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
function deleteCookie(name) {
|
||||
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
}
|
||||
function logoutUser() {
|
||||
// Inform backend to remove cookie if necessary
|
||||
fetch('/api/logout', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
}).catch((err) => console.warn('Logout request failed:', err));
|
||||
// Clear the auth cookie
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
deleteCookie('token');
|
||||
// Redirect to login page
|
||||
window.location.href = 'index.html';
|
||||
window.location.href = "/index.html";
|
||||
});
|
||||
}
|
||||
function redirectToLogin() {
|
||||
window.location.href = 'login.html';
|
||||
@@ -36,7 +46,10 @@ function setupAuthUI() {
|
||||
}
|
||||
if (logoutBtn) {
|
||||
logoutBtn.classList.toggle('d-none', !isAuthenticated);
|
||||
logoutBtn.addEventListener('click', logoutUser);
|
||||
logoutBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
logoutUser();
|
||||
});
|
||||
}
|
||||
}
|
||||
// Initialize on load
|
||||
|
||||
@@ -59,13 +59,18 @@ function loadEvents(org_id, evs) {
|
||||
for (const ev of events) {
|
||||
const card = document.createElement("div");
|
||||
card.className = "event-card filled";
|
||||
//card.innerHTML = `
|
||||
// <span>${ev.title}</span>`
|
||||
// Do odkomentowania kiedy widok podglądu wydarzeń będzie gotowy
|
||||
|
||||
let formattedDate = new Intl.DateTimeFormat('en-US', {
|
||||
weekday: 'long',
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric' // "1"
|
||||
}).format(new Date(ev.eventDate));
|
||||
|
||||
card.innerHTML = `
|
||||
<span>
|
||||
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
|
||||
<p style="margin: 0">${ev.organisation}</p>
|
||||
<p style="margin: 0">👥 ${ev.organisation} | 📍 ${ev.location} | 📅 ${formattedDate}</p>
|
||||
</span>`;
|
||||
if (org_id == ev.organisationId) {
|
||||
card.innerHTML += `
|
||||
|
||||
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||
import { getEvent, getMyAccount, unhideElementById, getMyRegisteredEventIds } from './generalUseHelpers.js';
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const eventId = urlParams.get('event');
|
||||
@@ -15,6 +15,8 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
||||
var container = document.getElementById("mainContainer");
|
||||
const modifyBtn = document.getElementById("editBtn");
|
||||
const removeBtn = document.getElementById("removeBtn");
|
||||
const applyBtn = document.getElementById("applyBtn");
|
||||
const leaveBtn = document.getElementById("leaveBtn");
|
||||
var org_id = -1;
|
||||
try {
|
||||
var user = yield getMyAccount();
|
||||
@@ -36,7 +38,7 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
||||
}
|
||||
catch (err) {
|
||||
if (container !== null)
|
||||
container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||
container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powr<EFBFBD>t -></a></p>`;
|
||||
}
|
||||
if (thisEvent == null) {
|
||||
if (container !== null)
|
||||
@@ -63,8 +65,22 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
||||
}
|
||||
else if (org_id == -1) {
|
||||
// Użytkownik jest wolontariuszem
|
||||
try {
|
||||
const registeredIds = yield getMyRegisteredEventIds();
|
||||
const isRegistered = registeredIds.includes(Number(eventId));
|
||||
if (isRegistered) {
|
||||
unhideElementById(document, "leaveBtn");
|
||||
}
|
||||
else {
|
||||
unhideElementById(document, "applyBtn");
|
||||
}
|
||||
}
|
||||
catch (_b) {
|
||||
unhideElementById(document, "applyBtn");
|
||||
applyBtn.textContent = "log in to apply";
|
||||
applyBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
unhideElementById(document, "mainContainer");
|
||||
}
|
||||
if (modifyBtn) {
|
||||
@@ -96,4 +112,52 @@ document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, vo
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (applyBtn) {
|
||||
applyBtn.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _c;
|
||||
try {
|
||||
const response = yield fetch(`/api/events/join/${eventId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
});
|
||||
const result = yield response.json();
|
||||
if (result.success) {
|
||||
window.location.href = `/view.html?event=${eventId}`;
|
||||
}
|
||||
else {
|
||||
alert(`Error: ${(_c = result.error_msg) !== null && _c !== void 0 ? _c : "Unknown error occurred."}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Failed to apply:", error);
|
||||
alert("Failed to apply.");
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (leaveBtn) {
|
||||
leaveBtn.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _d;
|
||||
try {
|
||||
const response = yield fetch(`/api/events/leave/${eventId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
});
|
||||
const result = yield response.json();
|
||||
if (result.success) {
|
||||
window.location.href = `/view.html?event=${eventId}`;
|
||||
}
|
||||
else {
|
||||
alert(`Error: ${(_d = result.error_msg) !== null && _d !== void 0 ? _d : "Unknown error occurred."}`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Failed to leave:", error);
|
||||
alert("Failed to leave.");
|
||||
}
|
||||
}));
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -29,9 +29,19 @@ export function getMyAccount() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const res = yield fetch("/api/auth/my_account");
|
||||
if (!res.ok) {
|
||||
throw Error("U<EFBFBD>ytkownik niezalogowany!");
|
||||
throw Error("Użytkownik niezalogowany!");
|
||||
}
|
||||
const data = yield res.json();
|
||||
return data;
|
||||
});
|
||||
}
|
||||
export function getMyRegisteredEventIds() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const res = yield fetch("/api/auth/my_events");
|
||||
if (!res.ok) {
|
||||
throw Error("Użytkownik niezalogowany!");
|
||||
}
|
||||
const events = yield res.json();
|
||||
return events.map((event) => event.eventId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,17 +1,91 @@
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Login</title>
|
||||
<script src="/js/login.js" defer></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Sign in</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/css/style.css" />
|
||||
<link rel="stylesheet" href="/css/panel.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h2>Login</h2>
|
||||
|
||||
|
||||
|
||||
<body class="bg-light">
|
||||
<div class="">
|
||||
<!-- Sidebar -->
|
||||
<div class="sidebar">
|
||||
<div class="text-center mb-4">
|
||||
</div>
|
||||
<nav class="sidebar d-flex flex-column align-items-center pt-3">
|
||||
<div class="icon-box my-2">
|
||||
<a href="index.html" class="nav-link text-info mb-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
|
||||
<br /><h8 class="iconText">Home</h8>
|
||||
</a>
|
||||
</div>
|
||||
<div class="icon-box my-2">
|
||||
<a href="#" class="nav-link text-info mb-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
|
||||
<br /><h8 class="iconText">Chats</h8>
|
||||
</a>
|
||||
</div>
|
||||
<div class="icon-box my-2">
|
||||
<a href="#" class="nav-link text-info mb-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
|
||||
<br /><h8 class="iconText">Calendar</h8>
|
||||
</a>
|
||||
</div>
|
||||
<div class="icon-box mt-auto mb-4">
|
||||
<a href="#" class="nav-link text-info mb-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
|
||||
<br /><h8 class="iconText">Settings</h8>
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
<!-- Top Nav -->
|
||||
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||
<div>
|
||||
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main" id="mainContainer">
|
||||
<h1 class="mb-4">Sign in to your organizational/volunteer account</h1>
|
||||
|
||||
<form id="loginForm">
|
||||
<label>Email: <input type="email" id="email" required /></label><br /><br />
|
||||
<label>Password: <input type="password" id="password" required /></label><br /><br />
|
||||
<button type="submit">Login</button>
|
||||
|
||||
<div class="form-group mb-2">
|
||||
<label for="email">Login</label>
|
||||
<input type="email" id="email" class="form-control input-field" required />
|
||||
</div>
|
||||
<div class="form-group mb-2">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" class="form-control input-field" required />
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<button id="logInBtn" class="button" type="submit">
|
||||
<span>Log in</span>
|
||||
<span>⮞</span>
|
||||
</button>
|
||||
<button id="signUpBtn" class="button" type="button" onclick="alert('Coming soon!')">
|
||||
<span>Sign up</span>
|
||||
<span>⮞</span>
|
||||
</button>
|
||||
<p id="message" style="color: red;"></p>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/js/login.js"></script> <!-- defer? -->
|
||||
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||
<script type="module" src="/js/auth.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
|
||||
<script type="module" src="/js/eventModify.js"></script>
|
||||
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||
<script type="module" src="/js/auth.js"></script>
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Modify existing event</title>
|
||||
<title>View event details</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/css/style.css" />
|
||||
@@ -64,6 +64,7 @@
|
||||
<h4 id="descText"></h4><br />
|
||||
|
||||
<button id="applyBtn" class="button hidden-before-load"><span>Apply</span><span>⮞</span></button>
|
||||
<button id="leaveBtn" class="button hidden-before-load"><span>Leave</span><span>⮞</span></button>
|
||||
<button id="editBtn" class="button hidden-before-load"><span>Modify</span><span>⮞</span></button>
|
||||
<button id="removeBtn" class="button hidden-before-load" style="background-color: red;"><span>Remove permanently</span><span>⮞</span></button>
|
||||
|
||||
@@ -71,6 +72,8 @@
|
||||
|
||||
<script type="module" src="/js/eventView.js"></script>
|
||||
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||
<script type="module" src="/js/auth.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user