Skip to content

Commit

Permalink
changed username regex to match restrictions of couch-auth (see perfo…
Browse files Browse the repository at this point in the history
…od/couch-auth#74), improved error handling
  • Loading branch information
klues committed May 25, 2023
1 parent 91781c7 commit 9bcd0fb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/lang/i18n.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"DB_SYNC_STATE_STOPPED": "synchronization with cloud paused",
"DB_SYNC_STATE_FAIL": "not synchronizing with cloud",
"DB_SYNC_STATE_ONLINEONLY": "online-only, no offline synchronization",
"VALIDATION_ERROR_REGEX": "Username must contain only letters, digits or the characters [\"-\", \"_\"], valid length is 2-50 characters.",
"VALIDATION_ERROR_REGEX": "Username must contain only lowercase letters, digits or the characters [\"-\", \"_\"], valid length is 3-16 characters.",
"VALIDATION_ERROR_EXISTING": "Username is already existing.",
"VALIDATION_ERROR_FAILED": "Couldn't check username",
"SEARCH_IMAGE_PLACEHOLDER": "input search term",
"HEADER_COMPARE_ONLINE_OFFLINE": "Information about online/offline users",
"ADVANCED_SETTINGS": "Advanced Settings",
Expand Down
2 changes: 1 addition & 1 deletion src/js/service/loginService.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ loginService.validateUsername = function (username) {
})
.catch((e) => {
log.warn("couldn't check username");
resolve(constants.VALIDATION_ERROR_EXISTING);
resolve(constants.VALIDATION_ERROR_FAILED);
});
});
};
Expand Down
3 changes: 2 additions & 1 deletion src/js/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ constants.MODEL_VERSION = '{"major": 4, "minor": 0, "patch": 0}';

constants.LOCAL_NOLOGIN_USERNAME = 'default-user';
constants.LOCAL_DEMO_USERNAME = 'local-demo-user';
constants.USERNAME_REGEX = /^[A-Za-z0-9_-]{2,50}$/;
constants.USERNAME_REGEX = /^[a-z0-9][a-z0-9_-]{2,15}$/;

constants.VALIDATION_ERROR_REGEX = 'VALIDATION_ERROR_REGEX';
constants.VALIDATION_ERROR_EXISTING = 'VALIDATION_ERROR_EXISTING';
constants.VALIDATION_ERROR_FAILED = 'VALIDATION_ERROR_FAILED';
constants.VALIDATION_VALID = 'VALIDATION_VALID';

constants.EVENT_DB_CONNECTION_LOST = 'EVENT_DB_CONNECTION_LOST';
Expand Down
18 changes: 13 additions & 5 deletions src/vue-components/views/registerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<form autocomplete="off" onsubmit="event.preventDefault()" style="margin-bottom: 0.5em">
<div class="srow">
<label for="inputUser" class="two columns"><span class="desktop-right inputlabel">{{ $t('username') }}</span></label>
<input type="text" name="username" autocapitalize="none" v-model="user" id="inputUser" class="six columns" @change="validateUsername" v-debounce="300" v-focus="" maxlength="50"/>
<input type="text" name="username" autocapitalize="none" v-model="user" id="inputUser" class="six columns" @input="validateUsername" v-focus="" maxlength="16"/>
<div class="three columns" v-show="user != null && usernameValid === undefined">
<i class="fas fa-spinner fa-spin"/>
</div>
<div class="three columns" v-show="user != null && usernameValid == false">
<i style="color: red;" class="fas fa-times"/> <span>{{usernameValidationCode | translate}}</span>
</div>
Expand Down Expand Up @@ -114,6 +117,7 @@
import {constants} from "../../js/util/constants";
import ComparisonComponent from "./../components/comparisonComponent.vue";
import HeaderIcon from '../../vue-components/components/headerIcon.vue'
import {util} from "../../js/util/util.js";
export default {
components: {ComparisonComponent, HeaderIcon},
Expand Down Expand Up @@ -163,10 +167,14 @@
},
validateUsername() {
var thiz = this;
loginService.validateUsername(thiz.user).then((code) => {
thiz.usernameValid = code === constants.VALIDATION_VALID;
thiz.usernameValidationCode = code;
});
thiz.usernameValid = undefined;
thiz.usernameValidationCode = null;
util.debounce(() => {
loginService.validateUsername(thiz.user).then((code) => {
thiz.usernameValid = code === constants.VALIDATION_VALID;
thiz.usernameValidationCode = code;
});
}, 300, 'CHECK_USERNAME');
}
},
mounted() {
Expand Down
2 changes: 1 addition & 1 deletion superlogin/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let useSSL = false;
let dotenvFlow = require('dotenv-flow');
let infoTreeAPI = require('./infoTreeAPI/infoTreeAPI.js');

const USERNAME_REGEX = /^[A-Za-z0-9_-]{2,50}$/; // also see src/js/util/constants.js:8
const USERNAME_REGEX = /^[a-z0-9][a-z0-9_-]{2,15}$/;; // also see src/js/util/constants.js:8

dotenvFlow.config({
silent: true
Expand Down

0 comments on commit 9bcd0fb

Please sign in to comment.