Add function for generating random usernames

Not used yet.
This commit is contained in:
N-Pex 2020-12-10 15:12:40 +01:00
parent 6db4365b87
commit b46b06b308
2 changed files with 22 additions and 0 deletions

View file

@ -279,6 +279,26 @@ class Util {
reader.readAsArrayBuffer(file);
});
}
/** Generate a random user name */
randomUser() {
return this.randomString(
12,
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
);
}
// From here: https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
randomString(length, characters) {
var result = "";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(
Math.floor(Math.random() * charactersLength)
);
}
return result;
}
}
export default new Util();

View file

@ -1,5 +1,6 @@
global.Olm = require("olm");
import sdk from "matrix-js-sdk";
//import util from "../plugins/utils";
const LocalStorageCryptoStore = require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store")
.LocalStorageCryptoStore;
@ -59,6 +60,7 @@ export default {
var promiseLogin;
if (user.is_guest) {
//const randomUsername = util.randomUser();
promiseLogin = tempMatrixClient
.registerGuest({}, undefined)
.then((response) => {