Skip to content

Commit

Permalink
correção da recuperação de senha e novo componente password-strongness
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelchavesfreitas committed Sep 16, 2023
1 parent b07f5ee commit 9153e2e
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 58 deletions.
3 changes: 2 additions & 1 deletion assets-src/sass/4-components/_c-change-password.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@

.password {
position: relative;

margin-top:1em;
&-rules {
font-size: 14px;
line-height: 19px;
margin-top:1em;

strong {
color: var(--mc-secondary-500);
Expand Down
85 changes: 45 additions & 40 deletions assets-src/sass/4-components/_c-create-account.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@
.password {
position: relative;
&-rules {
margin-top:1em;
font-size: 14px;
line-height: 19px;
color: var(--mc-secondary-500);
>strong{
color: var(--mc-secondary-500);
}
}

.seePassword {
Expand All @@ -126,45 +129,7 @@
}
}

.progressbar {
display: flex;
align-items: center;
gap: 8px;

progress[value] {
appearance: none;
height: 8px;
width: 210px;

&::-webkit-progress-bar {
background-color: var(--mc-low-300);
border-radius: var(--mc-border-radius-sm);
}

&::-webkit-progress-value {
border-radius: var(--mc-border-radius-sm);
transition: 1s;
}

&.fraco {
&::-webkit-progress-value {
background: red;
}
}

&.medio {
&::-webkit-progress-value {
background: yellow;
}
}

&.forte {
&::-webkit-progress-value {
background: green;
}
}
}
}


.g-recaptcha {
display: flex;
Expand Down Expand Up @@ -305,4 +270,44 @@
}
}

}

.progressbar {
display: flex;
align-items: center;
gap: 8px;

progress[value] {
appearance: none;
height: 8px;
width: 210px;

&::-webkit-progress-bar {
background-color: var(--mc-low-300);
border-radius: var(--mc-border-radius-sm);
}

&::-webkit-progress-value {
border-radius: var(--mc-border-radius-sm);
transition: 1s;
}

&.fraco {
&::-webkit-progress-value {
background: red;
}
}

&.medio {
&::-webkit-progress-value {
background: yellow;
}
}

&.forte {
&::-webkit-progress-value {
background: green;
}
}
}
}
1 change: 1 addition & 0 deletions assets-src/sass/4-components/_c-login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
&-rules {
font-size: 14px;
line-height: 19px;
margin-top:1em;

strong {
color: var(--mc-danger-500);
Expand Down
15 changes: 5 additions & 10 deletions components/create-account/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
mc-card
mc-icon
mc-stepper
password-strongness
');
?>

Expand Down Expand Up @@ -57,22 +58,16 @@
<label for="pwd"> <?= i::__('Senha'); ?> </label>
<input autocomplete="off" id="pwd" type="password" name="password" v-model="password" />
<div class="seePassword" @click="togglePassword('pwd', $event)"></div>
<span class="password-rules">
<strong><?= i::__('A senha deve ter:') ?></strong>
{{passwordRules.minimumPasswordLength}}<?= i::__(' caracteres, um número, um caractere especial (! @ # $ & *), pelo menos uma letra maiúscula e uma minúscula.') ?>
</span>
</div>
<div class="field col-12 password">
<label for="pwd-check">
<?= i::__('Confirmar senha'); ?>
<?= i::__('Confirme sua senha'); ?>
</label>
<input autocomplete="off" id="pwd-check" type="password" name="confirm_password" v-model="confirmPassword" />
<div class="seePassword" @click="togglePassword('pwd-check', $event)"></div>
</div>
<div class="progressbar col-12">
<span> <?= i::__('Força da senha'); ?> </span>
<progress id="progress" :class="strongnessClass" :value="passwordStrongness" max="100"></progress>
<span id="progresslabel">{{passwordStrongness}}%</span>
</div>
<div class="col-12">
<password-strongness :password="password"></password-strongness>
</div>
<VueRecaptcha v-if="configs['google-recaptcha-sitekey']" :sitekey="configs['google-recaptcha-sitekey']" @verify="verifyCaptcha" @expired="expiredCaptcha" class="g-recaptcha col-12"></VueRecaptcha>
<button class="col-12 button button--primary button--large button--md" type="submit"> <?= i::__('Continuar') ?> </button>
Expand Down
15 changes: 8 additions & 7 deletions components/login/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

$this->import('
mc-card
password-strongness
');
?>

Expand All @@ -17,7 +18,6 @@
<!-- Login action -->

<div v-if="!recoveryRequest && !recoveryMode" class="login__action">

<div class="login__card">
<div class="login__card__header">
<h3> <?= $this->text('welcome', i::__('Boas vindas!')) ?> </h3>
Expand Down Expand Up @@ -114,7 +114,7 @@

<!-- Recovery action -->
<div v-if="recoveryMode" class="login__recovery--action">
<div class="login__card" v-if="recoveryEmailSent">
<div class="login__card">
<div class="login__card__header">
<h3> <?= i::__('Redefinir senha de acesso') ?> </h3>
</div>
Expand All @@ -124,17 +124,18 @@
<div class="field col-12 password">
<label for="pwd"> <?= i::__('Senha'); ?> </label>
<input autocomplete="off" id="pwd" type="password" name="password" v-model="password" />
<span class="password-rules">
<?= i::__('A senha deve ter:') ?>
<strong> {{passwordRules.minimumPasswordLength}}<?= i::__(' caracteres, um número, um caractere especial (! @ # $ & *), pelo menos uma letra maiúscula e uma minúscula.') ?></strong>
</span>

</div>

<div class="field col-12 password">
<label for="pwd"> <?= i::__('Senha'); ?> </label>
<label for="pwd"> <?= i::__('Confirme sua nova senha'); ?> </label>
<input autocomplete="off" id="pwd" type="password" name="confirmPassword" v-model="confirmPassword" />
</div>

<div class="col-12">
<password-strongness :password="password"></password-strongness>
</div>

<button class="col-12 button button--primary button--large button--md" type="submit"> <?= i::__('Redefinir senha') ?> </button>
</form>
</div>
Expand Down
17 changes: 17 additions & 0 deletions components/password-strongness/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Componente `<create-account>`
Componente para cadastrar uma conta no mapas culturais BaseV2

## Propriedades
- *String **config*** - json com configurações necessárias para o funcionamento da criação de contas (definidas no php)

### Importando componente
```PHP
<?php
$this->import('create-account');
?>
```
### Exemplos de uso
```HTML
<!-- utilizaçao básica -->
<create-account config='<?= $configs; ?>'></create-account>
```
135 changes: 135 additions & 0 deletions components/password-strongness/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
app.component('password-strongness', {
template: $TEMPLATES['password-strongness'],

components: {
VueRecaptcha
},

props: {
password: {
type: String,
required: true
}
},

setup() {
const text = Utils.getTexts('password-strongness')
return { text }
},

mounted() {
let api = new API();
api.GET($MAPAS.baseURL + "auth/passwordvalidationinfos").then(async response => response.json().then(validations => {

this.passwordRules = validations.passwordRules;

this.passwordRules.minimumPasswordLength = this.passwordRules.minimumPasswordLength || 8;
}));
},

data() {
const passwordRules = {};

const passwordMustHaveCapitalLetters = /[A-Z]/;
const passwordMustHaveLowercaseLetters = /[a-z]/;
const passwordMustHaveSpecialCharacters = /[$@$!%*#?&\.\,\:<>+\_\-\"\'()]/;
const passwordMustHaveNumbers = /[0-9]/;

return {
passwordRules,
passwordMustHaveCapitalLetters,
passwordMustHaveLowercaseLetters,
passwordMustHaveSpecialCharacters,
passwordMustHaveNumbers
}
},

methods: {
getErrors() {
const errors = [];

if (this.password.length < this.passwordRules.minimumPasswordLength) {
errors.push(this.text('{num} caracteres').replace('{num}', this.passwordRules.minimumPasswordLength));
}

if (this.passwordRules.passwordMustHaveCapitalLetters && !this.passwordMustHaveCapitalLetters.test(this.password)) {
errors.push(this.text('pelo menos uma letra maiúscula'));
}

if (this.passwordRules.passwordMustHaveLowercaseLetters && !this.passwordMustHaveLowercaseLetters.test(this.password)) {
errors.push(this.text('pelo menos uma letra minúscula'));
}

if (this.passwordRules.passwordMustHaveSpecialCharacters && !this.passwordMustHaveSpecialCharacters.test(this.password)) {
errors.push(this.text('um caracter especial'));
}

if (this.passwordRules.passwordMustHaveNumbers && !this.passwordMustHaveNumbers.test(this.password)) {
errors.push(this.text('um número'));
}

return errors.join(', ');
},

rules() {
const rules = [];

if (this.passwordRules.passwordMustHaveCapitalLetters) {
rules.push(this.passwordMustHaveCapitalLetters);
}

if (this.passwordRules.passwordMustHaveLowercaseLetters) {
rules.push(this.passwordMustHaveLowercaseLetters);
}

if (this.passwordRules.passwordMustHaveSpecialCharacters) {
rules.push(this.passwordMustHaveSpecialCharacters);
}

if (this.passwordRules.passwordMustHaveNumbers) {
rules.push(this.passwordMustHaveNumbers);
}

return rules;
},
strongness() {
if (this.password) {
const minimumPasswordLength = this.passwordRules.minimumPasswordLength;
const rules = this.rules();

const rulesLength = rules.length;
const percentToAdd = 100 / (rulesLength + 1);
const pass = this.password;

let prog = 0;

for(let rule of rules) {
if(rule.test(this.password)) {
prog++;
}
}

let currentPercent = prog * 100 / (rulesLength + 1);

if (this.password.length > minimumPasswordLength - 1) {
currentPercent = currentPercent + percentToAdd;
}

return currentPercent.toFixed(0)
} else {
return 0;
}

},

strongnessClass() {
if (this.strongness <= 40) {
return 'fraco';
} else if (this.strongness <= 85) {
return 'medio';
} else {
return 'forte';
}
}
},
});
20 changes: 20 additions & 0 deletions components/password-strongness/template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @var \MapasCulturais\Themes\BaseV2\Theme $this
* @var \MapasCulturais\App $app
*
*/

use MapasCulturais\i;

?>
<div class="progressbar">
<span> <?= i::__('Força da senha'); ?> </span>
<progress id="progress" :class="strongnessClass()" :value="strongness()" max="100"></progress>
<span id="progresslabel">{{strongness()}}%</span>
</div>

<div v-if="getErrors()" class="password-rules">
<?= i::__('A senha deve conter:') ?>
<strong> {{getErrors()}}</strong>
</div>
Loading

0 comments on commit 9153e2e

Please sign in to comment.