[FEATURE] Add email address to installation process
[Packages/TYPO3.CMS.git] / Build / Sources / TypeScript / install / Resources / Public / TypeScript / Module / Maintenance / CreateAdmin.ts
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 import {AbstractInteractableModule} from '../AbstractInteractableModule';
15 import * as $ from 'jquery';
16 import Router = require('../../Router');
17 import PasswordStrength = require('../PasswordStrength');
18 import Modal = require('TYPO3/CMS/Backend/Modal');
19 import Notification = require('TYPO3/CMS/Backend/Notification');
20
21 /**
22 * Module: TYPO3/CMS/Install/Module/CreateAdmin
23 */
24 class CreateAdmin extends AbstractInteractableModule {
25 private selectorAdminCreateButton: string = '.t3js-createAdmin-create';
26
27 public initialize(currentModal: JQuery): void {
28 this.currentModal = currentModal;
29 this.getData();
30
31 currentModal.on('click', this.selectorAdminCreateButton, (e: JQueryEventObject): void => {
32 e.preventDefault();
33 this.create();
34 });
35
36 currentModal.on('click', '.t3-install-form-password-strength', (e: JQueryEventObject): void => {
37 PasswordStrength.initialize('.t3-install-form-password-strength');
38 });
39 }
40
41 private getData(): void {
42 const modalContent = this.getModalBody();
43 $.ajax({
44 url: Router.getUrl('createAdminGetData'),
45 cache: false,
46 success: (data: any): void => {
47 if (data.success === true) {
48 modalContent.empty().append(data.html);
49 Modal.setButtons(data.buttons);
50 } else {
51 Notification.error('Something went wrong');
52 }
53 },
54 error: (xhr: XMLHttpRequest): void => {
55 Router.handleAjaxError(xhr, modalContent);
56 },
57 });
58 }
59
60 private create(): void {
61 const modalContent = this.getModalBody();
62 const executeToken = this.getModuleContent().data('create-admin-token');
63 $.ajax({
64 url: Router.getUrl(),
65 method: 'POST',
66 data: {
67 'install': {
68 'action': 'createAdmin',
69 'token': executeToken,
70 'userName': this.findInModal('.t3js-createAdmin-user').val(),
71 'userPassword': this.findInModal('.t3js-createAdmin-password').val(),
72 'userPasswordCheck': this.findInModal('.t3js-createAdmin-password-check').val(),
73 'userEmail': this.findInModal('.t3js-createAdmin-email').val(),
74 'userSystemMaintainer': (this.findInModal('.t3js-createAdmin-system-maintainer').is(':checked')) ? 1 : 0,
75 },
76 },
77 cache: false,
78 success: (data: any): void => {
79 if (data.success === true && Array.isArray(data.status)) {
80 data.status.forEach((element: any): void => {
81 if (element.severity === 2) {
82 Notification.error(element.message);
83 } else {
84 Notification.success(element.title);
85 }
86 });
87 } else {
88 Notification.error('Something went wrong');
89 }
90 },
91 error: (xhr: XMLHttpRequest): void => {
92 Router.handleAjaxError(xhr, modalContent);
93 },
94 });
95 this.findInModal('.t3js-createAdmin-user').val('');
96 this.findInModal('.t3js-createAdmin-password').val('');
97 this.findInModal('.t3js-createAdmin-password-check').val('');
98 this.findInModal('.t3js-createAdmin-email').val('');
99 this.findInModal('.t3js-createAdmin-system-maintainer').prop('checked', false);
100 }
101 }
102
103 export = new CreateAdmin();