1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 22:29:41 +02:00

Detect first-time login event

This commit is contained in:
sauls8t 2019-06-19 12:46:46 +01:00
parent 4d2f30711c
commit 946c433018
2 changed files with 22 additions and 49 deletions

View file

@ -9,64 +9,37 @@
// //
// https://documize.com // https://documize.com
import $ from 'jquery';
import { empty, and } from '@ember/object/computed';
import { isEmpty } from '@ember/utils';
import stringUtil from '../../utils/string'; import stringUtil from '../../utils/string';
import { set } from '@ember/object'; import $ from 'jquery';
import { empty } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component'; import Component from '@ember/component';
export default Component.extend({ export default Component.extend({
appMeta: service(),
buttonLabel: 'Complete setup', buttonLabel: 'Complete setup',
titleEmpty: empty('model.title'), hasTitleError: empty('model.title'),
firstnameEmpty: empty('model.firstname'), hasFirstnameError: empty('model.firstname'),
lastnameEmpty: empty('model.lastname'), hasLastnameError: empty('model.lastname'),
emailEmpty: empty('model.email'), hasEmailError: empty('model.email'),
passwordEmpty: empty('model.password'), hasPasswordError: empty('model.password'),
hasEmptyTitleError: and('titleEmpty', 'titleError'), hasKeyError: empty('model.activationKey'),
hasEmptyFirstnameError: and('firstnameEmpty', 'adminFirstnameError'),
hasEmptyLastnameError: and('lastnameEmpty', 'adminLastnameError'),
hasEmptyEmailError: and('emailEmpty', 'adminEmailError'),
hasEmptyPasswordError: and('passwordEmpty', 'adminPasswordError'),
actions: { actions: {
save() { save () {
if (isEmpty(this.get('model.title'))) { if (this.get('hasTitleError')) return $("#setup-title").focus();
set(this, 'titleError', true); if (this.get('hasFirstnameError')) return $("#setup-firstname").focus();
return $("#siteTitle").focus(); if (this.get('hasLastnameError')) return $("#setup-lastname").focus();
if (this.get('hasEmailError') || !stringUtil.isEmail(this.get('model.email'))) return $("#setup-email").focus();
if (this.get('hasPasswordError')) return $("#new-password").focus();
if (this.get('model.edition') === this.get('constants').Product.EnterpriseEdition && this.get('hasKeyError')) {
return $("#activation-key").focus();
} }
if (isEmpty(this.get('model.firstname'))) { this.set('buttonLabel', 'Setting up, please wait...');
set(this, 'adminFirstnameError', true);
return $("#adminFirstname").focus();
}
if (isEmpty(this.get('model.lastname'))) { this.get('save')();
set(this, 'adminLastnameError', true);
return $("#adminLastname").focus();
}
if (isEmpty(this.get('model.email')) || !stringUtil.isEmail(this.get('model.email'))) {
set(this, 'adminEmailError', true);
return $("#adminEmail").focus();
}
if (isEmpty(this.get('model.password'))) {
set(this, 'adminPasswordError', true);
return $("#adminPassword").focus();
}
this.model.allowAnonymousAccess = $("#allowAnonymousAccess").prop('checked');
this.set('buttonLabel', 'Configuring, please wait...');
this.get('save')().then(() => {
set(this, 'titleError', false);
set(this, 'adminFirstnameError', false);
set(this, 'adminLastnameError', false);
set(this, 'adminEmailError', false);
set(this, 'adminPasswordError', false);
});
} }
} }
}); });

View file

@ -16,7 +16,7 @@ import Component from '@ember/component';
export default Component.extend(Modals, { export default Component.extend(Modals, {
localStorage: service(), localStorage: service(),
didReceiveAttrs() { didInsertElement() {
this._super(...arguments); this._super(...arguments);
let firstRun = this.get('localStorage').isFirstRun(); let firstRun = this.get('localStorage').isFirstRun();