From 08b4a3437c853f29d7f5e626f35cb0a17354a6e5 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Aug 2023 07:25:11 +0200 Subject: [PATCH] refs #5762 feat(changePassword): salix compatibility --- debian/changelog | 2 +- forms/account/conf/index.js | 78 +--------------------- forms/account/conf/ui.xml | 69 +------------------- js/hedera/locale/ca.yml | 17 +++++ js/hedera/locale/es.yml | 19 ++++++ js/hedera/locale/fr.yml | 17 +++++ js/hedera/locale/pt.yml | 17 +++++ js/hedera/login.js | 12 +++- js/hedera/login.xml | 1 + js/htk/change-password/index.js | 111 ++++++++++++++++++++++++++++++++ js/htk/change-password/ui.xml | 62 ++++++++++++++++++ js/htk/htk.js | 33 +++++----- package.json | 2 +- 13 files changed, 279 insertions(+), 161 deletions(-) create mode 100644 js/htk/change-password/index.js create mode 100644 js/htk/change-password/ui.xml diff --git a/debian/changelog b/debian/changelog index 755bef2a..ad8892e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (23.30.1) stable; urgency=low +hedera-web (23.30.2) stable; urgency=low * Initial Release. diff --git a/forms/account/conf/index.js b/forms/account/conf/index.js index c603b618..55d73abc 100644 --- a/forms/account/conf/index.js +++ b/forms/account/conf/index.js @@ -7,79 +7,7 @@ export default new Class({ activate() { this.$.userModel.setInfo('c', 'myClient', 'hedera'); this.$.userModel.setInfo('u', 'myUser', 'account'); - - if (this.hash.$.verificationToken) - this.onPassChangeClick(); + this.$.changePassword.conn = this.conn + this.$.changePassword.user = this.gui.user } - - ,onPassChangeClick() { - this.$.oldPassword.value = ''; - this.$.newPassword.value = ''; - this.$.repeatPassword.value = ''; - - var verificationToken = this.hash.$.verificationToken; - this.$.oldPassword.style.display = verificationToken ? 'none' : 'block'; - this.$.changePassword.show(); - - if (verificationToken) - this.$.newPassword.focus(); - else - this.$.oldPassword.focus(); - } - - ,async onPassModifyClick() { - const form = this.$.changePassword.node; - Vn.Node.disableInputs(form); - try { - const oldPassword = this.$.oldPassword.value; - const newPassword = this.$.newPassword.value; - const repeatedPassword = this.$.repeatPassword.value; - - try { - if (newPassword == '' && repeatedPassword == '') - throw new Error(_('Passwords empty')); - if (newPassword !== repeatedPassword) - throw new Error(_('Passwords doesn\'t match')); - } catch (err) { - return Htk.Toast.showError(err.message); - } - - const verificationToken = this.hash.$.verificationToken; - const params = {newPassword}; - - try { - if (verificationToken) { - params.verificationToken = verificationToken; - await this.conn.send('user/restore-password', params); - } else { - let userId = this.gui.user.id; - params.oldPassword = oldPassword; - await this.conn.patch( - `Accounts/${userId}/changePassword`, params); - } - } catch(err) { - Htk.Toast.showError(err.message); - - if (verificationToken) - this.$.newPassword.select(); - else - this.$.oldPassword.select(); - - return; - } - - this.hash.unset('verificationToken'); - await this.conn.open(this.gui.user.name, newPassword); - this.$.changePassword.hide(); - } finally { - Vn.Node.disableInputs(form, false); - } - - Htk.Toast.showMessage(_('Password changed!')); - } - - ,onPassInfoClick() { - this.$.passwordInfo.show(); - } -}); - +}); \ No newline at end of file diff --git a/forms/account/conf/ui.xml b/forms/account/conf/ui.xml index 86d7c29b..d5e936ea 100644 --- a/forms/account/conf/ui.xml +++ b/forms/account/conf/ui.xml @@ -1,11 +1,5 @@ - - - SELECT length, nAlpha, nUpper, nDigits, nPunct - FROM account.userPassword - - SELECT u.id, u.name, u.email, u.nickname, @@ -27,7 +21,7 @@ + on-click="this.$.changePassword.open()"/>
@@ -74,64 +68,5 @@
- -
-
-
- Change password -
- - - -
-
- - -
-
-
- - -
-
- Password requirements -
-
    -
  • - {{passwordForm.length}} characters long -
  • -
  • - {{passwordForm.nAlpha}} alphabetic characters -
  • -
  • - {{passwordForm.nUpper}} capital letters -
  • -
  • - {{passwordForm.nDigits}} digits -
  • -
  • - {{passwordForm.nPunct}} symbols -
  • -
-
-
+ diff --git a/js/hedera/locale/ca.yml b/js/hedera/locale/ca.yml index 5ccdff26..d72f6e86 100644 --- a/js/hedera/locale/ca.yml +++ b/js/hedera/locale/ca.yml @@ -65,3 +65,20 @@ Account: Compte Addresses: Adreces Load an order: Si us plau carrega una comanda pendent a la cistella o en comença una de nova + +Old password: Contrasenya antiga +New password: Nova contrasenya +Repeat password: Repetir contrasenya +Requirements: Requisits +Modify: Modificar +Password requirements: Requisits de contrasenya +characters long: caràcters de longitud +alphabetic characters: caràcters alfabètics +capital letters: majúscules +digits: dígits +symbols: símbols +Password changed!: Contrasenya modificada! +Password doesn't meet the requirements: '' +Passwords doesn't match: Les contrasenyes no coincideixen! +Passwords empty: Les contrasenyes en blanc +Change password: Canvia la contrasenya \ No newline at end of file diff --git a/js/hedera/locale/es.yml b/js/hedera/locale/es.yml index 4fcf5573..746b0cb7 100644 --- a/js/hedera/locale/es.yml +++ b/js/hedera/locale/es.yml @@ -65,3 +65,22 @@ Account: Cuenta Addresses: Direcciones Load an order: Por favor carga un pedido pendiente en la cesta o empieza uno nuevo + +Old password: Contaseña antigua +New password: Nueva contraseña +Repeat password: Repetir contraseña +Requirements: Requisitos +Modify: Modificar +Password requirements: Requisitos de constraseña +characters long: carácteres de longitud +alphabetic characters: carácteres alfabéticos +capital letters: letras mayúsculas +digits: dígitos +symbols: 'símbolos. Ej: $%&.' +Password changed!: ¡Contraseña modificada! +Password doesn't meet the requirements: >- + La nueva contraseña no reune los requisitos de seguridad necesarios, pulsa en + info para más detalle +Passwords doesn't match: ¡Las contraseñas no coinciden! +Passwords empty: Contraseña vacía +Change password: Cambiar contraseña \ No newline at end of file diff --git a/js/hedera/locale/fr.yml b/js/hedera/locale/fr.yml index 7bc99938..8402c07b 100644 --- a/js/hedera/locale/fr.yml +++ b/js/hedera/locale/fr.yml @@ -65,3 +65,20 @@ Account: Compte Addresses: Adresses Load an order: Veuillez télécharger une commande en attente dans le panier ou en démarrer une nouvelle + +Old password: Ancien mot de passe +New password: Nouveau mot de passe +Repeat password: Répéter le mot de passe +Requirements: Exigences +Modify: Modifier +Password requirements: Mot de passe exigences +characters long: Longs caractères +alphabetic characters: les caractères alphabétiques +capital letters: lettres majuscules +digits: chiffres +symbols: 'symboles. Ej: $%&.' +Password changed!: Mot de passe modifié! +Password doesn't meet the requirements: '' +Passwords doesn't match: Les mots de passe ne correspondent pas! +Passwords empty: '' +Change password: Changer le mot de passe \ No newline at end of file diff --git a/js/hedera/locale/pt.yml b/js/hedera/locale/pt.yml index 8e3cfe61..bc7c6eae 100644 --- a/js/hedera/locale/pt.yml +++ b/js/hedera/locale/pt.yml @@ -63,3 +63,20 @@ Account: Conta Addresses: Moradas Load an order: Carregue um pedido pendente no carrinho ou inicie um novo + +Old password: Palavra-passe antiga +New password: Nova Palavra-passe +Repeat password: Repetir Palavra-passe +Requirements: Requisitos +Modify: Modificar +Password requirements: Requisitos de Palavra-passe +characters long: caracteres +alphabetic characters: caracteres alfabéticos +capital letters: letras maiúsculas +digits: dígitos +symbols: 'símbolos. Ej: $%&.' +Password changed!: Palavra-passe Modificada! +Password doesn't meet the requirements: Palavra-passe não atende aos requisitos +Passwords doesn't match: As Palavras-Passe não coincidem! +Passwords empty: Palavra-passe vazia +Change password: Mudar Palavra-passe \ No newline at end of file diff --git a/js/hedera/login.js b/js/hedera/login.js index 870518f6..3cc16484 100644 --- a/js/hedera/login.js +++ b/js/hedera/login.js @@ -26,6 +26,12 @@ module.exports = new Class({ self._onSubmit(); return false; }; + + if(this.hash.$.verificationToken){ + this.$.changePassword.conn = this.conn; + this.$.changePassword.token = this.hash.$.verificationToken; + this.$.changePassword.open(); + } } ,_onConnLoadChange(conn, isLoading) { @@ -94,7 +100,11 @@ module.exports = new Class({ return; } - await this._conn.send('user/recover-password', {recoverUser}); + await this.conn.post('VnUsers/recoverPassword', { + user: recoverUser, + app: 'hedera' + }); + Htk.Toast.showMessage(_('A mail has been sent wich you can recover your password')); } }); diff --git a/js/hedera/login.xml b/js/hedera/login.xml index 9b97e7bb..f82b2602 100644 --- a/js/hedera/login.xml +++ b/js/hedera/login.xml @@ -54,4 +54,5 @@
+
diff --git a/js/htk/change-password/index.js b/js/htk/change-password/index.js new file mode 100644 index 00000000..6494513d --- /dev/null +++ b/js/htk/change-password/index.js @@ -0,0 +1,111 @@ +var Component = require('vn/component'); +var Toast = require('../toast'); +var Tpl = require('./ui.xml').default; + +/** + * A change password popup. + */ +module.exports = new Class({ + Extends: Component, + Tag: 'htk-change-password', + Properties: { + /** + * The token url. + */ + token: { + type: String + ,set(value) { + this._token = value; + } + ,get() { + return this._token; + } + }, + conn: { + type: Db.Connection + ,set(x) { + this._conn = x + } + ,get() { + return this._conn; + } + }, + user: { + type: Object + } + }, + + initialize(props) { + Component.prototype.initialize.call(this, props); + }, + + async open() { + this.passwordForm = await this.conn.get('UserPasswords/findOne') + this.loadTemplateFromString(Tpl); + + this.$.oldPassword.value = ''; + this.$.newPassword.value = ''; + this.$.repeatPassword.value = ''; + + this.$.oldPassword.style.display = this.token ? 'none' : 'block'; + this.$.changePassword.open(); + + if (this.token) + this.$.newPassword.focus(); + else + this.$.oldPassword.focus(); + }, + + async onPassModifyClick() { + const form = this.$.changePassword.node; + Vn.Node.disableInputs(form); + try { + const oldPassword = this.$.oldPassword.value; + const newPassword = this.$.newPassword.value; + const repeatedPassword = this.$.repeatPassword.value; + + try { + if (newPassword == '' && repeatedPassword == '') + throw new Error(_('Passwords empty')); + if (newPassword !== repeatedPassword) + throw new Error(_('Passwords doesn\'t match')); + } catch (err) { + return Toast.showError(err.message); + } + + const params = {newPassword}; + + + try { + if (this.token) { + const headers = { + Authorization: this.token + }; + await this.conn.post('VnUsers/reset-password', params, {headers}); + } else { + params.userId = this.user.id; + params.oldPassword = oldPassword; + + await this.conn.patch(`Accounts/change-password`, params); + } + } catch(err) { + Toast.showError(err.message); + + if (this.token) + this.$.newPassword.select(); + else + this.$.oldPassword.select(); + + return; + } + + if(this.user) + await this.conn.open(this.user.name, newPassword); + this.$.changePassword.hide(); + } finally { + Vn.Node.disableInputs(form, false); + } + + Toast.showMessage(_('Password changed!')); + } +}); diff --git a/js/htk/change-password/ui.xml b/js/htk/change-password/ui.xml new file mode 100644 index 00000000..ebd8c92c --- /dev/null +++ b/js/htk/change-password/ui.xml @@ -0,0 +1,62 @@ + + +
+
+
+ Change password +
+ + + +
+
+ + +
+
+
+ + +
+
+ Password requirements +
+
    +
  • + {{this.passwordForm.length}} characters long +
  • +
  • + {{this.passwordForm.nAlpha}} alphabetic characters +
  • +
  • + {{this.passwordForm.nUpper}} capital letters +
  • +
  • + {{this.passwordForm.nDigits}} digits +
  • +
  • + {{this.passwordForm.nPunct}} symbols +
  • +
+
+
+ diff --git a/js/htk/htk.js b/js/htk/htk.js index 5cc21c26..8297fefe 100644 --- a/js/htk/htk.js +++ b/js/htk/htk.js @@ -3,22 +3,23 @@ require('db/db'); require('./style/index.scss'); Htk = module.exports = { - Popup : require('./popup') - ,Dialog : require('./dialog') - ,Toast : require('./toast') - ,Repeater : require('./repeater') - ,Grid : require('./grid') - ,Spinner : require('./spinner') - ,Icon : require('./icon') - ,FullImage : require('./full-image') - ,ImageEditor : require('./image-editor') - ,Assistant : require('./assistant') - ,AssistantBar : require('./assistant-bar') - ,Step : require('./step') - ,Loader : require('./loader') - ,List : require('./list') - ,Field : require('./field') - ,Column : require('./column') + Popup : require('./popup') + ,Dialog : require('./dialog') + ,Toast : require('./toast') + ,Repeater : require('./repeater') + ,Grid : require('./grid') + ,Spinner : require('./spinner') + ,Icon : require('./icon') + ,FullImage : require('./full-image') + ,ImageEditor : require('./image-editor') + ,Assistant : require('./assistant') + ,AssistantBar : require('./assistant-bar') + ,Step : require('./step') + ,Loader : require('./loader') + ,List : require('./list') + ,Field : require('./field') + ,Column : require('./column') + ,ChangePassword : require('./change-password') }; var Fields = { diff --git a/package.json b/package.json index e982d0b0..d8689b05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hedera-web", - "version": "23.30.1", + "version": "23.30.2", "description": "Verdnatura web page", "license": "GPL-3.0", "repository": {