-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.php
36 lines (33 loc) · 1.12 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
// require dirname(__FILE__) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/vendor/twig/twig/lib/Twig/Autoloader.php';
Twig_Autoloader::register();
require dirname(__FILE__) . "/app/lib/api.php";
require dirname(__FILE__) . "/app/lib/config.php";
$loader = new Twig_Loader_Filesystem('app/templates');
$twig = new Twig_Environment($loader);
$data = array(
'error' => null,
'isInstalled' => hasConfig(),
);
if (!empty($_POST['username'])) {
if (!isValidUsername($_POST['username'])) {
$data['error'] = 'Username is not valid';
} else {
$config = array(
'username' => $_POST["username"]
);
$filename = dirname(__FILE__) . '/data/config-' . uniqid() . '.json';
$result = file_put_contents($filename, json_encode(array(
'username' => $_POST["username"]
)));
if ($result !== false) {
$data['error'] = null;
$data['isInstalled'] = true;
} else {
$data['error'] = "Can't save configuration";
$data['isInstalled'] = false;
}
}
}
echo $twig->render('install.html', $data);