54e3099c56
- Controller lifetime is bound to route lifetime - View lifetime is bound to controller lifetime - Control lifetime is bound to view lifetime - Enhanced event dispatching - Enhanced responsiveness in some places - Views communicate user input to controllers via new event system
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const router = require('../router.js');
|
|
const api = require('../api.js');
|
|
const topNavigation = require('../models/top_navigation.js');
|
|
const RegistrationView = require('../views/registration_view.js');
|
|
|
|
class UserRegistrationController {
|
|
constructor() {
|
|
topNavigation.activate('register');
|
|
this._view = new RegistrationView();
|
|
this._view.addEventListener('submit', e => this._evtRegister(e));
|
|
}
|
|
|
|
_evtRegister(e) {
|
|
this._view.clearMessages();
|
|
this._view.disableForm();
|
|
api.post('/users/', {
|
|
name: e.detail.name,
|
|
password: e.detail.password,
|
|
email: e.detail.email
|
|
}).then(() => {
|
|
api.forget();
|
|
return api.login(e.detail.name, e.detail.password, false);
|
|
}, response => {
|
|
return Promise.reject(response.description);
|
|
}).then(() => {
|
|
const ctx = router.show('/');
|
|
ctx.controller.showSuccess('Welcome aboard!');
|
|
}, errorMessage => {
|
|
this._view.showError(errorMessage);
|
|
this._view.enableForm();
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = router => {
|
|
router.enter('/register', (ctx, next) => {
|
|
new UserRegistrationController();
|
|
});
|
|
};
|