Actual situation:
import { extend } from 'flarum/common/extend';
import SignUpModal from 'flarum/components/SignUpModal';
import Stream from 'flarum/common/utils/Stream';
SignUpModal.prototype.randomPassword = function (length) {
var chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890";
var pass = "";
for (var x = 0; x < length; x++) {
var i = Math.floor(Math.random() * chars.length);
pass += chars.charAt(i);
}
return pass;
};
app.initializers.add('justoverclock/flarum-ext-pwgen', () => {
extend(SignUpModal.prototype, 'oninit', function() {
this.confirmPassword = Stream('');
});
extend(SignUpModal.prototype, 'fields', function(items) {
items.add(
'genratePassword',
m('.Form-group', [
m(".Button Button--primary Button--block", {
name: 'generate',
type: 'button',
value: 'genera PW sicura',
onclick: () => this.password(this.randomPassword(12)),
})
]),
10
);
});
extend(SignUpModal.prototype, 'fields', function(items) {
items.add(
'genPW',
m('.Form-group', [
m('input.FormControl', {
name: 'row_password',
type: 'text',
})
]),
10
);
});
});
Warning: Professional image below XD
actually i need two things, but i cant find the right way:
- give a text to the button (maybe translatable)
- generate the password on click on the field below (visible of course).
after that, when everything works i will use a better code to generate more secure password, but for now i can't find a solution to this (stupid i think) problem.