From 7dc22774532872fc99aa7768cf299ab623e9d155 Mon Sep 17 00:00:00 2001
From: tusooa <tusooa@kazv.moe>
Date: Mon, 9 Jan 2023 13:02:16 -0500
Subject: Use stylelint

---
 src/components/registration/registration.vue | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'src/components/registration/registration.vue')

diff --git a/src/components/registration/registration.vue b/src/components/registration/registration.vue
index 24d9b59b..a26162f0 100644
--- a/src/components/registration/registration.vue
+++ b/src/components/registration/registration.vue
@@ -277,7 +277,7 @@
 
 <script src="./registration.js"></script>
 <style lang="scss">
-@import '../../_variables.scss';
+@import "../../variables";
 $validations-cRed: #f04124;
 
 .registration-form {
@@ -321,7 +321,7 @@ $validations-cRed: #f04124;
 
   .form-group--error {
     animation-name: shakeError;
-    animation-duration: .6s;
+    animation-duration: 0.6s;
     animation-timing-function: ease-in-out;
   }
 
@@ -350,7 +350,7 @@ $validations-cRed: #f04124;
   }
 
   form textarea {
-    line-height:16px;
+    line-height: 16px;
     resize: vertical;
   }
 
-- 
cgit v1.2.3-70-g09d2


From dd97a23ce70fc564d3142eb9d218ff1a929107b1 Mon Sep 17 00:00:00 2001
From: tusooa <tusooa@kazv.moe>
Date: Sun, 22 Jan 2023 11:15:52 -0500
Subject: Add birthday to registration form

---
 src/boot/after_store.js                      |  2 ++
 src/components/registration/registration.js  | 27 +++++++++++++++++++++-
 src/components/registration/registration.vue | 34 ++++++++++++++++++++++++++++
 src/i18n/en.json                             |  8 +++++--
 src/modules/instance.js                      |  2 ++
 5 files changed, 70 insertions(+), 3 deletions(-)

(limited to 'src/components/registration/registration.vue')

diff --git a/src/boot/after_store.js b/src/boot/after_store.js
index 1fa9dd2a..d2e7f488 100644
--- a/src/boot/after_store.js
+++ b/src/boot/after_store.js
@@ -60,6 +60,8 @@ const getInstanceConfig = async ({ store }) => {
 
       store.dispatch('setInstanceOption', { name: 'textlimit', value: textlimit })
       store.dispatch('setInstanceOption', { name: 'accountApprovalRequired', value: data.approval_required })
+      store.dispatch('setInstanceOption', { name: 'birthdayRequired', value: !!data.pleroma.metadata.birthday_required })
+      store.dispatch('setInstanceOption', { name: 'birthdayMinAge', value: data.pleroma.metadata.birthday_min_age || 0 })
 
       if (vapidPublicKey) {
         store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js
index 6eb316d0..3139bdd2 100644
--- a/src/components/registration/registration.js
+++ b/src/components/registration/registration.js
@@ -3,6 +3,7 @@ import { required, requiredIf, sameAs } from '@vuelidate/validators'
 import { mapActions, mapState } from 'vuex'
 import InterfaceLanguageSwitcher from '../interface_language_switcher/interface_language_switcher.vue'
 import localeService from '../../services/locale/locale.service.js'
+import { DAY } from 'src/services/date_utils/date_utils.js'
 
 const registration = {
   setup () { return { v$: useVuelidate() } },
@@ -13,6 +14,7 @@ const registration = {
       username: '',
       password: '',
       confirm: '',
+      birthday: '',
       reason: '',
       language: ''
     },
@@ -32,6 +34,12 @@ const registration = {
           required,
           sameAs: sameAs(this.user.password)
         },
+        birthday: {
+          required: requiredIf(() => this.birthdayRequired),
+          maxValue: value => {
+            return !this.birthdayRequired || new Date(value).getTime() <= this.birthdayMin.getTime()
+          }
+        },
         reason: { required: requiredIf(() => this.accountApprovalRequired) },
         language: {}
       }
@@ -52,6 +60,21 @@ const registration = {
     reasonPlaceholder () {
       return this.replaceNewlines(this.$t('registration.reason_placeholder'))
     },
+    birthdayMin () {
+      const minAge = this.birthdayMinAge
+      const today = new Date()
+      today.setUTCMilliseconds(0)
+      today.setUTCSeconds(0)
+      today.setUTCMinutes(0)
+      today.setUTCHours(0)
+      const minDate = new Date()
+      minDate.setTime(today.getTime() - minAge * DAY)
+      return minDate
+    },
+    birthdayMinFormatted () {
+      const browserLocale = localeService.internalToBrowserLocale(this.$i18n.locale)
+      return this.user.birthday && new Date(Date.parse(this.birthdayMin)).toLocaleDateString(browserLocale, { timeZone: 'UTC', day: 'numeric', month: 'long', year: 'numeric' })
+    },
     ...mapState({
       registrationOpen: (state) => state.instance.registrationOpen,
       signedIn: (state) => !!state.users.currentUser,
@@ -59,7 +82,9 @@ const registration = {
       serverValidationErrors: (state) => state.users.signUpErrors,
       termsOfService: (state) => state.instance.tos,
       accountActivationRequired: (state) => state.instance.accountActivationRequired,
-      accountApprovalRequired: (state) => state.instance.accountApprovalRequired
+      accountApprovalRequired: (state) => state.instance.accountApprovalRequired,
+      birthdayRequired: (state) => state.instance.birthdayRequired,
+      birthdayMinAge: (state) => state.instance.birthdayMinAge
     })
   },
   methods: {
diff --git a/src/components/registration/registration.vue b/src/components/registration/registration.vue
index a26162f0..6d7fe76e 100644
--- a/src/components/registration/registration.vue
+++ b/src/components/registration/registration.vue
@@ -167,6 +167,40 @@
               </ul>
             </div>
 
+            <div
+              class="form-group"
+              :class="{ 'form-group--error': v$.user.birthday.$error }"
+            >
+              <label
+                class="form--label"
+                for="sign-up-birthday"
+              >
+                {{ birthdayRequired ? $t('registration.birthday') : $t('registration.birthday_optional') }}
+              </label>
+              <input
+                id="sign-up-birthday"
+                v-model="user.birthday"
+                :disabled="isPending"
+                class="form-control"
+                type="date"
+                max="birthdayMin"
+                :aria-required="birthdayRequired"
+              >
+            </div>
+            <div
+              v-if="v$.user.birthday.$dirty"
+              class="form-error"
+            >
+              <ul>
+                <li v-if="v$.user.birthday.required.$invalid">
+                  <span>{{ $t('registration.validations.birthday_required') }}</span>
+                </li>
+                <li v-if="v$.user.birthday.maxValue.$invalid">
+                  <span>{{ $tc('registration.validations.birthday_min_age', { date: birthdayMinFormatted }) }}</span>
+                </li>
+              </ul>
+            </div>
+
             <div
               class="form-group"
               :class="{ 'form-group--error': v$.user.language.$error }"
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 1846c4c5..15d3bec4 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -312,9 +312,13 @@
       "email_required": "cannot be left blank",
       "password_required": "cannot be left blank",
       "password_confirmation_required": "cannot be left blank",
-      "password_confirmation_match": "should be the same as password"
+      "password_confirmation_match": "should be the same as password",
+      "birthday_required": "cannot be left blank",
+      "birthday_min_age": "must be on or before {date}"
     },
-    "email_language": "In which language do you want to receive emails from the server?"
+    "email_language": "In which language do you want to receive emails from the server?",
+    "birthday": "Birthday:",
+    "birthday_optional": "Birthday (optional):"
   },
   "remote_user_resolver": {
     "remote_user_resolver": "Remote user resolver",
diff --git a/src/modules/instance.js b/src/modules/instance.js
index 8e8d13d3..72694e2c 100644
--- a/src/modules/instance.js
+++ b/src/modules/instance.js
@@ -107,6 +107,8 @@ const defaultState = {
   restrictedNicknames: [],
   safeDM: true,
   knownDomains: [],
+  birthdayRequired: false,
+  birthdayMinAge: 0,
 
   // Feature-set, apparently, not everything here is reported...
   shoutAvailable: false,
-- 
cgit v1.2.3-70-g09d2


From 03d5c2e140fc70937d3533665fa88d055ab486f1 Mon Sep 17 00:00:00 2001
From: tusooa <tusooa@kazv.moe>
Date: Sun, 22 Jan 2023 11:22:24 -0500
Subject: Make date picker aware of the birthday max value

---
 src/components/registration/registration.js  | 3 +++
 src/components/registration/registration.vue | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

(limited to 'src/components/registration/registration.vue')

diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js
index 3139bdd2..22ca6ad6 100644
--- a/src/components/registration/registration.js
+++ b/src/components/registration/registration.js
@@ -71,6 +71,9 @@ const registration = {
       minDate.setTime(today.getTime() - minAge * DAY)
       return minDate
     },
+    birthdayMinAttr () {
+      return this.birthdayMin.toJSON().replace(/T.+$/, '')
+    },
     birthdayMinFormatted () {
       const browserLocale = localeService.internalToBrowserLocale(this.$i18n.locale)
       return this.user.birthday && new Date(Date.parse(this.birthdayMin)).toLocaleDateString(browserLocale, { timeZone: 'UTC', day: 'numeric', month: 'long', year: 'numeric' })
diff --git a/src/components/registration/registration.vue b/src/components/registration/registration.vue
index 6d7fe76e..5701b05e 100644
--- a/src/components/registration/registration.vue
+++ b/src/components/registration/registration.vue
@@ -183,7 +183,7 @@
                 :disabled="isPending"
                 class="form-control"
                 type="date"
-                max="birthdayMin"
+                :max="birthdayRequired ? birthdayMinAttr : undefined"
                 :aria-required="birthdayRequired"
               >
             </div>
-- 
cgit v1.2.3-70-g09d2


From 65d78ced93aab31217a74624cb313be6ff7114f9 Mon Sep 17 00:00:00 2001
From: tusooa <tusooa@kazv.moe>
Date: Sun, 12 Feb 2023 15:38:36 -0500
Subject: Fix registration error with email language selected

---
 src/components/registration/registration.js  | 4 ++--
 src/components/registration/registration.vue | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

(limited to 'src/components/registration/registration.vue')

diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js
index 22ca6ad6..b88bdeec 100644
--- a/src/components/registration/registration.js
+++ b/src/components/registration/registration.js
@@ -16,7 +16,7 @@ const registration = {
       confirm: '',
       birthday: '',
       reason: '',
-      language: ''
+      language: ['']
     },
     captcha: {}
   }),
@@ -100,7 +100,7 @@ const registration = {
       this.user.captcha_token = this.captcha.token
       this.user.captcha_answer_data = this.captcha.answer_data
       if (this.user.language) {
-        this.user.language = localeService.internalToBackendLocale(this.user.language)
+        this.user.language = localeService.internalToBackendLocaleMulti(this.user.language.filter(k => k))
       }
 
       this.v$.$touch()
diff --git a/src/components/registration/registration.vue b/src/components/registration/registration.vue
index 5701b05e..7438a5f4 100644
--- a/src/components/registration/registration.vue
+++ b/src/components/registration/registration.vue
@@ -210,6 +210,7 @@
                 :prompt-text="$t('registration.email_language')"
                 :language="v$.user.language.$model"
                 :set-language="val => v$.user.language.$model = val"
+                @click.stop.prevent
               />
             </div>
 
-- 
cgit v1.2.3-70-g09d2

