-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.php
137 lines (101 loc) · 4.38 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
$install_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR;
function completeInstallation($message_type, $message) {
global $install_dir;
$user = Yii::app()->getComponent('user');
$user->setFlash(
$message_type, $message
);
rename($install_dir . 'installation', $install_dir . '.installation');
Yii::app()->request->redirect('/index.php');
Yii::app()->end();
}
if(file_exists($install_dir . '.installation')) {
die('Service already installed');
}
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
// change the following paths if necessary
$yii=dirname(__FILE__).'/_framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
require_once($yii);
Yii::createWebApplication($config);
$user = Users::model()->getRecordById(WebUser::ADMIN_ID);
$dirname = dirname(__FILE__);
if(!empty($user)) {
completeInstallation('warning', 'Admin already created');
}
$model = new UserForm('create_admin');
$model->username = 'admin';
if(isset($_POST['UserForm'])) {
$model->attributes = $_POST['UserForm'];
if($model->validate()) {
$user = new Users();
$user->id = 1;
$user->username = $model->username;
$user->password = CPasswordHelper::hashPassword($model->password);
$user->email = $model->email;
$user->email_verified = 1;
if($user->save()) {
MailHelper::sendUserCredentials($model->username, $model->email, $model->password);
completeInstallation('success', 'Admin user successfully created');
}
}
}
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Installation</title>
<link rel="stylesheet" type="text/css" href="<?php echo Bootstrap::getBooster()->getAssetsUrl(); ?>/bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div class="span6 offset3">
<h1 class="offset1">Installation</h1>
<h2 class="offset1"><small>Enter admin credentials</small></h2>
<?php if($model->hasErrors()): ?>
<?php echo TbHtml::errorSummary($model); ?>
<?php endif; ?>
<form method="post" class="form-horizontal">
<?php echo TbHtml::activeTextFieldControlGroup($model, 'username'); ?>
<?php echo TbHtml::activePasswordFieldControlGroup($model, 'password'); ?>
<?php echo TbHtml::activePasswordFieldControlGroup($model, 'password_verify'); ?>
<?php echo TbHtml::activeEmailFieldControlGroup($model, 'email'); ?>
<!--
<div class="span3 control-group">
<div class="controls">
<?php //echo CHtml::textField('Users[username]', $model->username, array('maxlength' => 255, 'id' => 'Users_username')); ?>
<?php echo CHtml::activeTextField($model, 'username'); ?>
</div>
</div>
<div class="span3 control-group">
<div class="controls">
<?php //echo CHtml::passwordField('Users[password]', $model->password, array('maxlength' => 60)); ?>
<?php echo CHtml::activePasswordField($model, 'password'); ?>
</div>
</div>
<div class="span3 control-group">
<div class="controls">
<?php //echo CHtml::passwordField('Users[password_verified]', $model->password_verify, array('maxlength' => 60)); ?>
<?php echo CHtml::activePasswordField($model, 'password_verify'); ?>
</div>
</div>
<div class="span3 control-group">
<div class="controls">
<?php //echo CHtml::passwordField('Users[email]', $model->email, array('maxlength' => 255)); ?>
<?php echo CHtml::activeEmailField($model, 'email'); ?>
</div>
</div>
-->
<div class=" control-group">
<div class="controls">
<?php echo CHtml::submitButton('Create', array('class' => 'btn btn-primary')); ?>
</div>
</div>
</form>
</div>
</body>
</html>