-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
step_6.php
84 lines (75 loc) · 2.53 KB
/
step_6.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This file is part of Fork CMS.
*
* For the full copyright and license information, please view the license
* file that was distributed with this source code.
*/
/**
* Step 6 of the Fork installer
*
* @author Davy Hellemans <davy@netlash.com>
* @author Tijs Verkoyen <tijs@sumocoders.be>
* @author Matthias Mullie <matthias@mullie.eu>
*/
class InstallerStep6 extends InstallerStep
{
/**
* Executes this step.
*/
public function execute()
{
$this->loadForm();
$this->validateForm();
$this->parseForm();
$this->tpl->display('layout/templates/step_6.tpl');
}
/**
* Is this step allowed.
*
* @return bool
*/
public static function isAllowed()
{
return InstallerStep5::isAllowed() && isset($_SESSION['db_hostname']) && isset($_SESSION['db_database']) && isset($_SESSION['db_username']) && isset($_SESSION['db_password']);
}
/**
* Loads the form.
*/
private function loadForm()
{
// guess email
$host = $_SERVER['HTTP_HOST'];
$this->frm->addText('email', (SpoonSession::exists('email') ? SpoonSession::get('email') : 'info@' . $host));
$this->frm->addPassword('password', (SpoonSession::exists('password') ? SpoonSession::get('password') : null), null, 'inputPassword', 'inputPasswordError', true);
$this->frm->addPassword('confirm', (SpoonSession::exists('confirm') ? SpoonSession::get('confirm') : null), null, 'inputPassword', 'inputPasswordError', true);
// disable autocomplete
$this->frm->getField('password')->setAttributes(array('autocomplete' => 'off'));
$this->frm->getField('confirm')->setAttributes(array('autocomplete' => 'off'));
}
/**
* Validate the form based on the variables in $_POST
*/
private function validateForm()
{
// form submitted
if($this->frm->isSubmitted())
{
// required fields
$this->frm->getField('email')->isEmail('Please provide a valid e-mailaddress.');
$this->frm->getField('password')->isFilled('This field is required.');
$this->frm->getField('confirm')->isFilled('This field is required.');
if($this->frm->getField('password')->getValue() != $this->frm->getField('confirm')->getValue()) $this->frm->getField('confirm')->addError('The passwords do not match.');
// all valid
if($this->frm->isCorrect())
{
// update session
SpoonSession::set('email', $this->frm->getField('email')->getValue());
SpoonSession::set('password', $this->frm->getField('password')->getValue());
SpoonSession::set('confirm', $this->frm->getField('confirm')->getValue());
// redirect
SpoonHTTP::redirect('index.php?step=7');
}
}
}
}