2023-10-20 22:35:26 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2022-12-20 23:56:41 +08:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'/customize/login.js',
|
|
|
|
'/common/cryptpad-common.js',
|
|
|
|
'/common/common-credential.js',
|
|
|
|
'/common/common-interface.js',
|
|
|
|
'/common/common-util.js',
|
|
|
|
'/common/common-realtime.js',
|
|
|
|
'/common/common-constants.js',
|
|
|
|
'/common/common-feedback.js',
|
|
|
|
'/common/outer/local-store.js',
|
|
|
|
'/common/hyperscript.js',
|
|
|
|
'/customize/pages.js',
|
|
|
|
'/common/rpc.js',
|
2024-05-21 07:13:55 +08:00
|
|
|
'appconfigscreen.js',
|
2024-05-24 20:36:19 +08:00
|
|
|
'/common/inner/sidebar-layout.js',
|
2022-12-20 23:56:41 +08:00
|
|
|
|
2024-06-15 01:35:51 +08:00
|
|
|
// 'css!/install/configscreen.css',
|
|
|
|
'less!/install/onboarding.less',
|
|
|
|
|
2023-01-07 15:27:22 +08:00
|
|
|
'css!/components/components-font-awesome/css/font-awesome.min.css',
|
2024-05-24 20:36:19 +08:00
|
|
|
], function ($, Login, Cryptpad, /*Test,*/ Cred, UI, Util, Realtime, Constants, Feedback, LocalStore, h, Pages, Rpc, AppConfigScreen, Sidebar) {
|
2022-12-20 23:56:41 +08:00
|
|
|
if (window.top !== window) { return; }
|
|
|
|
var Messages = Cryptpad.Messages;
|
|
|
|
$(function () {
|
2024-05-24 20:36:19 +08:00
|
|
|
|
2024-05-24 23:36:34 +08:00
|
|
|
if (LocalStore.isLoggedIn()) {
|
|
|
|
// already logged in, redirect to drive
|
|
|
|
document.location.href = '/drive/';
|
|
|
|
return;
|
|
|
|
}
|
2022-12-20 23:56:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
// text and password input fields
|
|
|
|
var $token = $('#installtoken');
|
|
|
|
var $uname = $('#username');
|
|
|
|
var $passwd = $('#password');
|
|
|
|
var $confirm = $('#password-confirm');
|
|
|
|
|
|
|
|
[ $token, $uname, $passwd, $confirm]
|
|
|
|
.some(function ($el) { if (!$el.val()) { $el.focus(); return true; } });
|
|
|
|
|
|
|
|
// checkboxes
|
|
|
|
var $register = $('button#register');
|
|
|
|
|
|
|
|
var I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = false;
|
|
|
|
var br = function () { return h('br'); };
|
|
|
|
|
|
|
|
// If the token is provided in the URL, hide the field
|
|
|
|
var token;
|
|
|
|
if (window.location.hash) {
|
|
|
|
var hash = window.location.hash.slice(1);
|
|
|
|
if (hash.length === 64) {
|
|
|
|
token = hash;
|
|
|
|
$token.hide();
|
|
|
|
console.log(`Install token: ${token}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-07 19:00:30 +08:00
|
|
|
var showTitleScreen = function (sendAdminDecree, sendAdminRpc) {
|
2024-05-24 23:36:34 +08:00
|
|
|
|
2024-06-15 01:35:51 +08:00
|
|
|
var titleScreen = AppConfigScreen.titleConfig;
|
|
|
|
var form = titleScreen(sendAdminDecree, sendAdminRpc);
|
2024-05-24 23:36:34 +08:00
|
|
|
|
2024-05-28 23:45:58 +08:00
|
|
|
var elem = document.createElement('div');
|
|
|
|
elem.setAttribute('id', 'cp-loading');
|
2024-06-15 01:35:51 +08:00
|
|
|
let frame = h('div.configscreen', form);
|
|
|
|
elem.append(frame);
|
2024-05-28 23:45:58 +08:00
|
|
|
var intr;
|
|
|
|
var append = function () {
|
|
|
|
if (!document.body) { return; }
|
|
|
|
clearInterval(intr);
|
|
|
|
document.body.appendChild(elem);
|
|
|
|
};
|
|
|
|
intr = setInterval(append, 100);
|
|
|
|
append();
|
|
|
|
|
2024-06-15 01:35:51 +08:00
|
|
|
};
|
2022-12-20 23:56:41 +08:00
|
|
|
|
2024-05-28 23:45:58 +08:00
|
|
|
var registerClick = function () {
|
2024-06-06 19:16:01 +08:00
|
|
|
showTitleScreen()
|
2024-05-29 00:48:59 +08:00
|
|
|
|
2024-06-06 19:16:01 +08:00
|
|
|
// var uname = $uname.val().trim();
|
|
|
|
// // trim whitespace surrounding the username since it is otherwise included in key derivation
|
|
|
|
// // most people won't realize that its presence is significant
|
|
|
|
// $uname.val(uname);
|
|
|
|
|
|
|
|
// var passwd = $passwd.val();
|
|
|
|
// var confirmPassword = $confirm.val();
|
|
|
|
|
|
|
|
// if (!token) { token = $token.val().trim(); }
|
|
|
|
|
|
|
|
// var shouldImport = false;
|
|
|
|
// var doesAccept;
|
|
|
|
// try {
|
|
|
|
// // if this throws there's either a horrible bug (which someone will report)
|
|
|
|
// // or the instance admins did not configure a terms page.
|
|
|
|
// doesAccept = true;
|
|
|
|
// } catch (err) {
|
|
|
|
// console.error(err);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (Cred.isEmail(uname) && !I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME) {
|
|
|
|
// var emailWarning = [
|
|
|
|
// Messages.register_emailWarning0,
|
|
|
|
// br(), br(),
|
|
|
|
// Messages.register_emailWarning1,
|
|
|
|
// br(), br(),
|
|
|
|
// Messages.register_emailWarning2,
|
|
|
|
// br(), br(),
|
|
|
|
// Messages.register_emailWarning3,
|
|
|
|
// ];
|
|
|
|
|
|
|
|
// Feedback.send("EMAIL_USERNAME_WARNING", true);
|
|
|
|
|
|
|
|
// return void UI.confirm(emailWarning, function (yes) {
|
|
|
|
// if (!yes) { return; }
|
|
|
|
// I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = true;
|
|
|
|
// registerClick();
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// /* basic validation */
|
|
|
|
// if (!Cred.isLongEnoughPassword(passwd)) {
|
|
|
|
// var warning = Messages._getKey('register_passwordTooShort', [
|
|
|
|
// Cred.MINIMUM_PASSWORD_LENGTH
|
|
|
|
// ]);
|
|
|
|
// return void UI.alert(warning);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (passwd !== confirmPassword) { // do their passwords match?
|
|
|
|
// return void UI.alert(Messages.register_passwordsDontMatch);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (Pages.customURLs.terms && !doesAccept) { // do they accept the terms of service? (if they exist)
|
|
|
|
// return void UI.alert(Messages.register_mustAcceptTerms);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let startOnboarding = function (network, proxy) {
|
|
|
|
// Rpc.create(network, proxy.edPrivate, proxy.edPublic, function (e, rpc) {
|
|
|
|
// if (e) {
|
|
|
|
// // TODO: handle error
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let sendAdminDecree = function (command, data, callback) {
|
|
|
|
// var params = ['ADMIN_DECREE', [command, data]];
|
|
|
|
// rpc.send('ADMIN', params, callback)
|
|
|
|
// };
|
|
|
|
|
2024-06-07 19:00:30 +08:00
|
|
|
// let sendAdminRpc = function (command, data, callback) {
|
|
|
|
// var params = [command, data];
|
|
|
|
// rpc.send('ADMIN', params, callback)
|
|
|
|
// };
|
|
|
|
|
|
|
|
// showTitleScreen(sendAdminDecree, sendAdminRpc)
|
2024-05-28 23:45:58 +08:00
|
|
|
|
2024-06-06 19:16:01 +08:00
|
|
|
// });
|
2024-05-28 23:45:58 +08:00
|
|
|
|
2024-06-06 19:16:01 +08:00
|
|
|
// };
|
|
|
|
|
|
|
|
// setTimeout(function () {
|
|
|
|
// var span = h('span', [
|
|
|
|
// h('h2', [
|
|
|
|
// h('i.fa.fa-warning'),
|
|
|
|
// ' ',
|
|
|
|
// Messages.register_warning,
|
|
|
|
// ]),
|
|
|
|
// Messages.register_warning_note
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// UI.confirm(span,
|
|
|
|
// function (yes) {
|
|
|
|
// if (!yes) { return; }
|
|
|
|
|
|
|
|
// Login.loginOrRegisterUI({
|
|
|
|
// uname,
|
|
|
|
// passwd,
|
|
|
|
// isRegister: true,
|
|
|
|
// onOTP: UI.getOTPScreen,
|
|
|
|
// shouldImport,
|
|
|
|
// cb: function (data) {
|
|
|
|
// var proxy = data.proxy;
|
|
|
|
// if (!proxy || !proxy.edPublic) { UI.alert(Messages.error); return true; }
|
|
|
|
|
|
|
|
// Rpc.createAnonymous(data.network, function (e, call) {
|
|
|
|
// if (e) { UI.alert(Messages.error); return console.error(e); }
|
|
|
|
// var anon_rpc = call;
|
|
|
|
|
|
|
|
// anon_rpc.send('ADD_FIRST_ADMIN', {
|
|
|
|
// token: token,
|
|
|
|
// edPublic: proxy.edPublic
|
|
|
|
// }, function (e) {
|
|
|
|
// if (e) { UI.alert(Messages.error); return console.error(e); }
|
|
|
|
// startOnboarding(data.network, proxy);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }, {
|
|
|
|
// ok: Messages.register_writtenPassword,
|
|
|
|
// cancel: Messages.register_cancel,
|
|
|
|
// /* If we're certain that we aren't using these "*Class" APIs
|
|
|
|
// anywhere else then we can deprecate them and make this a
|
|
|
|
// custom modal in common-interface (or here). */
|
|
|
|
// cancelClass: 'btn.btn-cancel.btn-register',
|
|
|
|
// okClass: 'btn.btn-danger.btn-register',
|
|
|
|
// reverseOrder: true,
|
|
|
|
// done: function ($dialog) {
|
|
|
|
// $dialog.find('> div').addClass('half');
|
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }, 150);
|
2022-12-20 23:56:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$register.click(registerClick);
|
|
|
|
|
|
|
|
var clickRegister = Util.notAgainForAnother(function () {
|
|
|
|
$register.click();
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
$register.on('keypress', function (e) {
|
|
|
|
if (e.which === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return clickRegister();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|