-
+
+
$vuetify.icons.getlink
{{ $t("getlink.title") }}
+
{{ $t("getlink.info") }}
-
Loading login flows...
-
-
-
{{ this.message }}
-
- {{ $t("getlink.create") }}
+
+ {{ $t("getlink.next") }}
+ {{ $t("menu.login")
+ }}
@@ -59,7 +35,8 @@
{{ $t("getlink.continue") }}
- {{ $t("getlink.different_link") }}
+ {{
+ $t("getlink.different_link") }}
{{ $t("getlink.qr_image_copied") }}
@@ -98,40 +75,30 @@ export default {
shareSupported() {
return !!navigator.share;
},
- passwordsSetAndMatching() {
- return this.user.password.match(this.passwordValidation) && this.user.password == this.passwordConfirm;
- }
},
watch: {
user: {
handler() {
// Reset manual errors
this.userErrorMessage = null;
- this.passErrorMessage = null;
},
deep: true,
}
},
methods: {
defaultData() {
-return {
- user: new User(this.$config.defaultServer, "", ""),
- isValid: false,
- loading: false,
- message: "",
- userErrorMessage: null,
- passErrorMessage: null,
- hasError: false,
- currentLoginServer: "",
- loadingLoginFlows: false,
- loginFlows: null,
- showPasswordFields: true,
- passwordConfirm: "",
- showPassword1: false,
- showPassword2: false,
- passwordValidation: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{12,20}$/,
- showQRCopiedToast: false
- };
+ return {
+ user: new User(this.$config.defaultServer, "", utils.randomPass()),
+ isValid: false,
+ loading: false,
+ message: "",
+ userErrorMessage: null,
+ hasError: false,
+ currentLoginServer: "",
+ loadingLoginFlows: false,
+ loginFlows: null,
+ showQRCopiedToast: false
+ };
},
goHome() {
this.$navigation.push({ name: "Home" }, -1);
@@ -144,6 +111,9 @@ return {
Object.keys(obj).forEach(k => this[k] = obj[k]);
})
},
+ goToLoginPage() {
+ this.$navigation.push({ name: "Login", params: { showCreateRoomOption: false, redirect: "GetLink" } }, 1);
+ },
handleLogin() {
if (this.user.user_id && this.user.password) {
// Reset errors
@@ -153,18 +123,27 @@ return {
const userDisplayName = this.user.user_id;
var user = Object.assign({}, this.user);
- user.user_id = utils.randomUser(this.$config.userIdPrefix);
+
+ let prefix = userDisplayName.toLowerCase().replaceAll(" ", "-").replaceAll(utils.invalidUserIdChars(), "");
+ if (prefix.length == 0) {
+ prefix = this.$config.userIdPrefix;
+ user.user_id = utils.randomUser(prefix);
+ } else {
+ // We first try with a username that is just a processed version of the display name.
+ // If it is already taken, try again with random characters appended.
+ user.user_id = prefix;
+ prefix = prefix + "-";
+ }
+
user.normalize();
this.loading = true;
+
this.$store.dispatch("createUser", { user, registrationFlowHandler: this.$refs.interactiveAuth.registrationFlowHandler }).then(
(ignoreduser) => {
this.$matrix.setUserDisplayName(userDisplayName);
- this.loading = false;
},
(error) => {
- console.error(error);
- this.loading = false;
this.message =
(error.data && error.data.error) ||
error.message ||
@@ -172,37 +151,42 @@ return {
if (error.data && error.data.errcode === 'M_FORBIDDEN') {
this.message = this.$i18n.messages[this.$i18n.locale].login.invalid_message;
this.hasError = true;
+ } else if (error.data && error.data.errcode === 'M_USER_IN_USE') {
+ // Try again with (other/new) random chars appended
+ user.user_id = utils.randomUser(prefix);
+ return this.$store.dispatch("createUser", { user, registrationFlowHandler: this.$refs.interactiveAuth.registrationFlowHandler }).then(
+ (ignoreduser) => {
+ this.$matrix.setUserDisplayName(userDisplayName);
+ },
+ (error) => {
+ this.message =
+ (error.data && error.data.error) ||
+ error.message ||
+ error.toString();
+ if (error.data && error.data.errcode === 'M_FORBIDDEN') {
+ this.message = this.$i18n.messages[this.$i18n.locale].login.invalid_message;
+ this.hasError = true;
+ }
+ }
+ );
}
- console.log("Message set to ", this.message);
- }
- );
+ })
+ .finally(() => {
+ this.loading = false;
+ })
}
},
handleCreateRoom() {
this.$navigation.push({ name: "CreateRoom" });
},
onUsernameEnter() {
- this.$refs.password.focus();
this.onUsernameBlur();
},
- validPassword(pass) {
- return !!pass;
- },
- onPasswordEntered() {
- if (this.validPassword(this.user.password)) {
- this.$nextTick(() => {
- this.$refs.passwordConfirm.focus();
- });
- }
- },
onUsernameBlur() {
var user = Object.assign({}, this.user);
user.normalize();
const server = user.home_server || this.$config.defaultServer;
if (server !== this.currentLoginServer) {
-
- this.showPasswordFields = false;
-
this.currentLoginServer = server;
this.loadingLoginFlows = true;
@@ -217,12 +201,6 @@ return {
} else {
this.message = "";
this.hasError = false;
- this.showPasswordFields = this.loginFlows.some(f => f.type == "m.login.password");
- if (this.showPasswordFields) {
- this.$nextTick(() => {
- this.$refs.password.focus();
- });
- }
}
});
}
diff --git a/src/components/Login.vue b/src/components/Login.vue
index c6bbd8f..e76c817 100644
--- a/src/components/Login.vue
+++ b/src/components/Login.vue
@@ -86,7 +86,7 @@
class="filled-button mt-4"
>{{ $t("login.login") }}
-
{{ $t("login.or") }}
+
{{ $t("login.or") }}
{{ $t("login.create_room") }}
@@ -111,6 +112,20 @@ import logoMixin from "./logoMixin";
export default {
name: "Login",
mixins:[rememberMeMixin, logoMixin],
+ props: {
+ showCreateRoomOption: {
+ type: Boolean,
+ default: function () {
+ return true;
+ },
+ },
+ redirect: {
+ type: String,
+ default: function() {
+ return null;
+ },
+ }
+ },
data() {
return {
user: new User(this.$config.defaultServer, "", ""),
@@ -171,7 +186,10 @@ export default {
this.loading = true;
this.$store.dispatch("login", { user }).then(
() => {
- if (this.$matrix.currentRoomId) {
+ if (this.redirect) {
+ this.$navigation.push({ name: this.redirect }, -1);
+ }
+ else if (this.$matrix.currentRoomId) {
this.$navigation.push(
{
name: "Chat",
diff --git a/src/plugins/utils.js b/src/plugins/utils.js
index 6c12e37..03e2b7a 100644
--- a/src/plugins/utils.js
+++ b/src/plugins/utils.js
@@ -580,6 +580,10 @@ class Util {
return null;
}
+ invalidUserIdChars() {
+ return /[^0-9a-z-.=_/]+/g;
+ }
+
getFirstVisibleElement(parentNode, where) {
let visible = this.findVisibleElements(parentNode);
if (visible) {