diff --git a/AquaNet/src/libs/i18n/en_ref.ts b/AquaNet/src/libs/i18n/en_ref.ts index 2ce7368b..b2748f8f 100644 --- a/AquaNet/src/libs/i18n/en_ref.ts +++ b/AquaNet/src/libs/i18n/en_ref.ts @@ -50,15 +50,15 @@ export const EN_REF_Welcome = { 'welcome.turnstile-timeout': 'Network verification timed out. Please try again.', 'welcome.verification-sent': 'A verification email has been sent to ${email}. Please check your inbox!', 'welcome.reset-password-sent': 'A password reset email has been sent to ${email}. Please check your inbox!', - 'welcome.verify-state-0': 'You haven\'t verified your email. A verification email had been sent to your inbox less than a minute ago. Please check your inbox!', - 'welcome.verify-state-1': 'You haven\'t verified your email. We\'ve already sent 3 emails over the last 24 hours so we\'ll not send another one. Please check your inbox!', + 'welcome.verify-state-0': 'You haven\'t verified your email. A verification email has been sent to your inbox just now. Please check your inbox!', + 'welcome.verify-state-1': 'You haven\'t verified your email. You have requested too many emails, please try again later.', 'welcome.verify-state-2': 'You haven\'t verified your email. We just sent you another verification email. Please check your inbox!', - 'welcome.reset-state-0': 'A reset email had been sent to your inbox less than a minute ago. Please check your inbox!', - 'welcome.reset-state-1': 'We\'ve already sent 3 emails over the last 24 hours so we\'ll not send another one. Please check your inbox!', + 'welcome.reset-state-0': 'A reset email has been sent to your inbox just now. Please check your inbox!', + 'welcome.reset-state-1': 'Too many emails have been sent. Another will not be sent.', 'welcome.verifying': 'Verifying your email... please wait.', 'welcome.verified': 'Your email has been verified! You can now log in now.', 'welcome.verification-failed': 'Verification failed: ${message}. Please try again.', - 'welcome.password-reset-done': 'Your password has been changed! You can log in now.', + 'welcome.password-reset-done': 'Your password has been updated! Please log back in.', } export const EN_REF_LEADERBOARD = { diff --git a/AquaNet/src/libs/sdk.ts b/AquaNet/src/libs/sdk.ts index 8cfe382c..38ae98e6 100644 --- a/AquaNet/src/libs/sdk.ts +++ b/AquaNet/src/libs/sdk.ts @@ -164,7 +164,7 @@ async function login(user: { email: string, password: string, turnstile: string } async function resetPassword(user: { email: string, turnstile: string }) { - return await post('api/v2/user/reset-password', user) + return await post('/api/v2/user/reset-password', user) } async function changePassword(user: { token: string, password: string }) { diff --git a/src/main/java/icu/samnyan/aqua/net/UserRegistrar.kt b/src/main/java/icu/samnyan/aqua/net/UserRegistrar.kt index e527076b..d7443b00 100644 --- a/src/main/java/icu/samnyan/aqua/net/UserRegistrar.kt +++ b/src/main/java/icu/samnyan/aqua/net/UserRegistrar.kt @@ -166,14 +166,14 @@ class UserRegistrar( if (!user.emailConfirmed && emailProps.enable) 400 - "Email not verified" val resets = async { resetPasswordRepo.findByAquaNetUserAuId(user.auId) } - val lasReset = resets.maxByOrNull { it.createdAt } + val lastReset = resets.maxByOrNull { it.createdAt } if (lastReset?.createdAt?.plusSeconds(60)?.isAfter(Instant.now()) == true) { 400 - "Reset request rejected - STATE_0" } // Check if we have sent more than 3 confirmation emails in the last 24 hours - if (confirmations.count { it.createdAt.plusSeconds(60 * 60 * 24).isAfter(Instant.now()) } > 3) { + if (resets.count { it.createdAt.plusSeconds(60 * 60 * 24).isAfter(Instant.now()) } > 3) { 400 - "Reset request rejected- STATE_1" } diff --git a/src/main/java/icu/samnyan/aqua/net/components/Email.kt b/src/main/java/icu/samnyan/aqua/net/components/Email.kt index a2e661a3..0dce7d5d 100644 --- a/src/main/java/icu/samnyan/aqua/net/components/Email.kt +++ b/src/main/java/icu/samnyan/aqua/net/components/Email.kt @@ -5,8 +5,9 @@ import ext.Str import ext.logger import icu.samnyan.aqua.net.db.AquaNetUser import icu.samnyan.aqua.net.db.EmailConfirmation -import icu.samnyan.aqua.net.db.PasswordReset import icu.samnyan.aqua.net.db.EmailConfirmationRepo +import icu.samnyan.aqua.net.db.ResetPassword +import icu.samnyan.aqua.net.db.ResetPasswordRepo import org.simplejavamail.api.mailer.Mailer import org.simplejavamail.email.EmailBuilder import org.simplejavamail.springsupport.SimpleJavaMailSpringSupport diff --git a/src/main/resources/db/40/V1000_42__add_reset_password.sql b/src/main/resources/db/40/V1000_42__add_reset_password.sql deleted file mode 100644 index 97c1f074..00000000 --- a/src/main/resources/db/40/V1000_42__add_reset_password.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE aqua_net_email_password_reset -( - id BIGINT AUTO_INCREMENT NOT NULL, - token VARCHAR(255) NOT NULL, - created_at datetime NOT NULL, - au_id BIGINT NULL, - CONSTRAINT pk_email_password_reset PRIMARY KEY (id) -); \ No newline at end of file diff --git a/src/main/resources/db/80/V1000_53__net_session.sql b/src/main/resources/db/80/V1000_53__net_session.sql index bdc4c5f2..47fdf780 100644 --- a/src/main/resources/db/80/V1000_53__net_session.sql +++ b/src/main/resources/db/80/V1000_53__net_session.sql @@ -4,4 +4,19 @@ CREATE TABLE aqua_net_session expiry datetime NOT NULL, au_id BIGINT NULL, CONSTRAINT pk_session PRIMARY KEY (token) -); \ No newline at end of file +); + +ALTER TABLE aqua_net_session + ADD CONSTRAINT FK_SESSION FOREIGN KEY (au_id) REFERENCES aqua_net_user (au_id); + +CREATE TABLE aqua_net_email_reset_password +( + id BIGINT AUTO_INCREMENT NOT NULL, + token VARCHAR(255) NOT NULL, + created_at datetime NOT NULL, + au_id BIGINT NULL, + CONSTRAINT pk_email_reset_password PRIMARY KEY (id) +); + +ALTER TABLE aqua_net_email_reset_password + ADD CONSTRAINT FK_EMAIL_RESET_PASSWORD_ON_AQUA_USER FOREIGN KEY (au_id) REFERENCES aqua_net_user (au_id); \ No newline at end of file