aboutsummaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
authorGravatar piotrruss <mail@pruss.it> 2021-09-02 22:28:11 +0200
committerGravatar piotrruss <mail@pruss.it> 2021-09-02 23:54:56 +0200
commitf08f6ca0a9d337efff280d4d1669a41b5d9c31c2 (patch)
tree7dee778ba742deb5f499f2aa08a1ba040606d633 /helpers
parent9f74c550927671f4ded301d0cf3e9d592716375c (diff)
downloadmy_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.gz
my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.bz2
my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.zip
finish translations, force maximize
Diffstat (limited to 'helpers')
-rw-r--r--helpers/appList.js8
-rw-r--r--helpers/crypt.js19
-rw-r--r--helpers/email.js8
-rw-r--r--helpers/fetchJson.js23
-rw-r--r--helpers/submitForm.js26
5 files changed, 69 insertions, 15 deletions
diff --git a/helpers/appList.js b/helpers/appList.js
deleted file mode 100644
index a114a70..0000000
--- a/helpers/appList.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import {Notes, Settings} from 'apps'
-
-const appList = {
- Notes: {component: Notes, icon: true, buttons: ['min', 'max', 'close'], height: '64em', width: '64em'},
- Settings: {component: Settings, icon: false, buttons: ['min'], height: '23em', width: '20em'},
-};
-
-export default appList
diff --git a/helpers/crypt.js b/helpers/crypt.js
new file mode 100644
index 0000000..5d3d79e
--- /dev/null
+++ b/helpers/crypt.js
@@ -0,0 +1,19 @@
+const crypto = require('crypto')
+const algorithm = 'aes-256-ctr'
+const secretKey = process.env.MYAPPS_NOTES_KEY
+
+export const encrypt = (text) => {
+ const iv = crypto.randomBytes(16)
+ const cipher = crypto.createCipheriv(algorithm, secretKey, iv)
+ const encrypted = Buffer.concat([cipher.update(text), cipher.final()])
+
+ return iv.toString('hex') + '::' + encrypted.toString('hex')
+}
+
+export const decrypt = (hash) => {
+ const [iv, content] = hash.split('::')
+ const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.from(iv, 'hex'))
+ const decrpyted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()])
+
+ return decrpyted.toString();
+}
diff --git a/helpers/email.js b/helpers/email.js
index d79426c..30e95c8 100644
--- a/helpers/email.js
+++ b/helpers/email.js
@@ -1,4 +1,6 @@
-export const subject = 'Verification of your new Notes App account'
-export const text = key => `Thank you for creating an account in Notes App.\nWe are sending you the verification code:\n\n${key}\n\nTo finish verification log in and paste this code.`
-export const html = key => `<p>Thank you for creating an account in Notes App.<br/>We are sending you the verification code:</p><p style="font-size: 150%;padding: 1em;border: 1px solid black">${key}</p><p>To finish verification log in and paste this code.</p></br>`
+import {t} from 'configs/translations'
+
+export const subject = l => t(l, 'mail_ver_subject')
+export const text = (l, key) => `${t(l, 'mail_ver_t1')}\n${t(l, 'mail_ver_t2')}\n\n${key}\n\n${t(l, 'mail_ver_t3')}`
+export const html = (l, key) => `<p>${t(l, 'mail_ver_t1')}<br/>${t(l, 'mail_ver_t2')}</p><p style="font-size: 150%;padding: 1em;border: 1px solid black">${key}</p><p>${t(l, 'mail_ver_t3')}</p></br>`
diff --git a/helpers/fetchJson.js b/helpers/fetchJson.js
new file mode 100644
index 0000000..5db80b5
--- /dev/null
+++ b/helpers/fetchJson.js
@@ -0,0 +1,23 @@
+export default async function fetcher(...args) {
+ try {
+ const response = await fetch(...args)
+
+ // if the server replies, there's always some data in json
+ // if there's a network error, it will throw at the previous line
+ const data = await response.json()
+
+ if (response.ok) {
+ return data
+ }
+
+ const error = new Error(response.statusText)
+ error.response = response
+ error.data = data
+ throw error
+ } catch (error) {
+ if (!error.data) {
+ error.data = {message: error.message}
+ }
+ throw error
+ }
+}
diff --git a/helpers/submitForm.js b/helpers/submitForm.js
index 77b283d..631c174 100644
--- a/helpers/submitForm.js
+++ b/helpers/submitForm.js
@@ -1,11 +1,31 @@
-import fetchJson from 'lib/fetchJson'
+import fetchJson from 'helpers/fetchJson'
const submitForm = async (e, url, mutateUser, setErrorMsg) => {
e.preventDefault()
+ const isRegister = url.includes('register')
+ if (
+ isRegister && e.currentTarget.password_confirm
+ && e.currentTarget.password_confirm.value
+ !== e.currentTarget.password.value
+ ) {
+ setErrorMsg('passwords_not_match')
+ return
+ } else {
+ setErrorMsg()
+ }
+
const body = {
email: e.currentTarget.email.value,
password: e.currentTarget.password.value,
+ ...(e.currentTarget.language
+ ? {language: e.currentTarget.language.value}
+ : {}
+ ),
+ ...(e.currentTarget.theme
+ ? {theme: e.currentTarget.theme.value}
+ : {}
+ ),
}
try {
@@ -17,9 +37,7 @@ const submitForm = async (e, url, mutateUser, setErrorMsg) => {
})
)
} catch (err) {
- url.includes('login')
- ? setErrorMsg('Could not log in')
- : setErrorMsg('Could not register user')
+ setErrorMsg(isRegister ? 'register_error' : 'login_error')
}
}