Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Authentication #16

Merged
merged 30 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
12b0690
Implement Authentication #1
mr-w1lde Nov 3, 2024
479bbf8
Implement Authentication #2
mr-w1lde Nov 3, 2024
0b19d71
Implement Authentication #3
mr-w1lde Nov 3, 2024
2dfaa2f
Add Pretix Sync Option to Disable + Some Fixes
mr-w1lde Nov 4, 2024
b5dc8d9
Add Pretix Sync Option to Disable + Some Fixes
mr-w1lde Nov 4, 2024
b65519e
Add Pretix Sync Option to Disable + Some Fixes
mr-w1lde Nov 4, 2024
884edc4
Add Pretix Sync Option to Disable + Some Fixes
mr-w1lde Nov 4, 2024
358d7bd
Implement Authentication #4
mr-w1lde Nov 4, 2024
f6a12d2
Implement Authentication #6
mr-w1lde Nov 4, 2024
df0db91
Implement Authentication #7
mr-w1lde Nov 4, 2024
14e5952
Implement Authentication #8
mr-w1lde Nov 5, 2024
22913f1
Implement Authentication #9
mr-w1lde Nov 5, 2024
7d3ce26
Implement Authentication #10
mr-w1lde Nov 5, 2024
b015920
Implement Authentication #11
mr-w1lde Nov 5, 2024
68df7ba
Implement Authentication #12
mr-w1lde Nov 5, 2024
8cff8dd
Implement Authentication #13
mr-w1lde Nov 5, 2024
1d8f397
Implement Authentication #13
mr-w1lde Nov 5, 2024
c52e2c8
Implement Virtual Threads
mr-w1lde Nov 6, 2024
86dd925
Revert "Implement Virtual Threads"
mr-w1lde Nov 6, 2024
a6b8a22
Revert "Revert "Implement Virtual Threads""
mr-w1lde Nov 6, 2024
8ed4cde
Implement Virtual Threads
mr-w1lde Nov 6, 2024
4630c35
Add Personal Info for Registration
mr-w1lde Nov 10, 2024
ad4e475
Updated and fixed db errors
stranck Nov 13, 2024
5b93f47
Updated fursonaname regex
stranck Nov 13, 2024
a960804
Update membership code
stranck Nov 13, 2024
24d8970
Moved membership year reset month/day to config
stranck Nov 14, 2024
cb8acd7
Allowed origins are now parametrized via env
Nov 14, 2024
63bc4ba
Merge branch 'authentication' of https://github.com/APSfurizon/fz-bac…
Nov 14, 2024
7e3a1f4
Merge branch 'master' into authentication
stranck Nov 14, 2024
c73af76
Fixed leftover after merge conflict
stranck Nov 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.PastOrPresent;
import jakarta.validation.constraints.Past;
import jakarta.validation.constraints.Size;
import lombok.Data;

import java.time.LocalDate;

// Italian stuff needed by law for associations.
// If for some reason you have to adopt this codebase in your country,
// you probably must adapt or change the membership code
@Data
public class PersonalUserInformation {
@NotNull
Expand All @@ -21,35 +24,58 @@ public class PersonalUserInformation {
@Size(min = 2)
private final String lastName;

@NotNull
@PastOrPresent
private final LocalDate birthday;
// Italian person "id". For non italian ppl leave this to null
// If null, in documents this should appear as ""
@Nullable
@Size(min = 16, max = 16)
private final String fiscalCode;

@NotNull
@NotEmpty
@Size(min = 2)
private final String birthCity;

@NotNull
@Nullable
@NotEmpty
@Size(min = 2)
private final String birthProvince;
private final String birthRegion;

@NotNull
@NotEmpty
@Size(min = 2)
private final String birthCountry;

@NotNull
@Past
private final LocalDate birthday;

@NotNull
@NotEmpty
@Size(min = 2)
private final String currentAddress;
private final String residenceAddress;

@NotNull
@NotEmpty
@Size(max = 16)
private final String residenceZipCode;

@NotNull
@NotEmpty
@Size(min = 2)
private final String phoneNumber;
private final String residenceCity;

@Nullable
private final String socialSecurityNumber;
@NotEmpty
@Size(min = 2)
private final String residenceRegion;

@NotNull
@NotEmpty
@Size(min = 2)
private final String residenceCountry;

@NotNull
@NotEmpty
@Size(min = 2)
private final String phoneNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.furizon.backend.feature.membership;

import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import net.furizon.backend.feature.authentication.dto.PersonalUserInformation;
import org.jetbrains.annotations.NotNull;

@Data
@RequiredArgsConstructor
@Builder
public class MembershipCard {

private final int id = -1;

private final int idInYear;

private final int issueYear;

@NotNull
private final String email;

@NotNull
private final PersonalUserInformation personalUserInformation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,32 @@ public void invoke(long userId, @NotNull PersonalUserInformation personalUserInf
MEMBERSHIP_INFO,
MEMBERSHIP_INFO.INFO_FIRST_NAME,
MEMBERSHIP_INFO.INFO_LAST_NAME,
MEMBERSHIP_INFO.INFO_FISCAL_CODE,
MEMBERSHIP_INFO.INFO_BIRTH_CITY,
MEMBERSHIP_INFO.INFO_BIRTH_REGION,
MEMBERSHIP_INFO.INFO_BIRTH_COUNTRY,
MEMBERSHIP_INFO.INFO_BIRTHDAY,
MEMBERSHIP_INFO.INFO_ADDRESS,
MEMBERSHIP_INFO.INFO_ZIP,
MEMBERSHIP_INFO.INFO_CITY,
MEMBERSHIP_INFO.INFO_REGION,
MEMBERSHIP_INFO.INFO_COUNTRY,
MEMBERSHIP_INFO.INFO_PHONE,
MEMBERSHIP_INFO.USER_ID
)
.values(
personalUserInformation.getFirstName(),
personalUserInformation.getLastName(),
personalUserInformation.getFiscalCode(),
personalUserInformation.getBirthCity(),
personalUserInformation.getBirthProvince(),
personalUserInformation.getBirthRegion(),
personalUserInformation.getBirthCountry(),
personalUserInformation.getCurrentAddress(),
personalUserInformation.getBirthday(),
personalUserInformation.getResidenceAddress(),
personalUserInformation.getResidenceZipCode(),
personalUserInformation.getResidenceCity(),
personalUserInformation.getResidenceRegion(),
personalUserInformation.getResidenceCountry(),
personalUserInformation.getPhoneNumber(),
userId
stranck marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.furizon.backend.feature.membership.action.resetIdInYearSequence;

import lombok.RequiredArgsConstructor;
import net.furizon.jooq.infrastructure.command.SqlCommand;
import org.jooq.util.postgres.PostgresDSL;
import org.springframework.stereotype.Component;

import static net.furizon.jooq.generated.Sequences.MEMBERSHIP_CARDS_ID_IN_YEARS;

@Component
@RequiredArgsConstructor
public class JooqResetIdInYearSequence implements ResetIdInYearSequence {
private final SqlCommand sqlCommand;

@Override
public void invoke() {
sqlCommand.execute(
PostgresDSL.alterSequence(MEMBERSHIP_CARDS_ID_IN_YEARS).restart()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.furizon.backend.feature.membership.action.resetIdInYearSequence;

public interface ResetIdInYearSequence {
void invoke();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.furizon.backend.infrastructure.membership;

import java.time.LocalDate;

public class MembershipYearUtils {

public static final int MEMBERSHIP_YEAR_RESET_MONTH = 10;
public static final int MEMBERSHIP_YEAR_RESET_DAY = 1;

public static short getCurrentMembershipYear() {
return getMembershipYear(LocalDate.now());
}

public static short getMembershipYear(LocalDate date) {
LocalDate reset = date.withMonth(MEMBERSHIP_YEAR_RESET_MONTH).withDayOfMonth(MEMBERSHIP_YEAR_RESET_DAY);
short year = (short) date.getYear();

if (date.isBefore(reset)) {
year--;
}
return year;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.furizon.backend.infrastructure.membership;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import static net.furizon.backend.infrastructure.membership.MembershipYearUtils.MEMBERSHIP_YEAR_RESET_MONTH;
import static net.furizon.backend.infrastructure.membership.MembershipYearUtils.MEMBERSHIP_YEAR_RESET_DAY;

@Service
public class ResetIssueYear {

public static final String CRONJOB =
stranck marked this conversation as resolved.
Show resolved Hide resolved
"0 0 6 " + MEMBERSHIP_YEAR_RESET_DAY + " " + MEMBERSHIP_YEAR_RESET_MONTH + " *";

@Scheduled(cron = CRONJOB)
public void resetIssueYear() {
//TODO
//Also: maybe a cronjob is not needed at all?
}
}
2 changes: 1 addition & 1 deletion db/migrations/000001_model.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ CREATE TABLE IF NOT EXISTS membership_cards
issue_year int2 NOT NULL,
user_id int8 NOT NULL,
CONSTRAINT cards_pkey PRIMARY KEY (card_db_id),
CONSTRAINT card_user_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT card_user_fk FOREIGN KEY (user_id) REFERENCES users (user_id) ON DELETE SET NULL ON UPDATE CASCADE
);

CREATE TABLE IF NOT EXISTS orders
Expand Down
Loading