Skip to content

Commit 292aa84

Browse files
committed
1 parent 36adb01 commit 292aa84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1849
-0
lines changed

demos/login-system/.htaccess

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Deny directory browsing
2+
Options -Indexes
3+
4+
## Mod Rewrite
5+
<IfModule mod_rewrite.c>
6+
RewriteEngine On
7+
8+
RewriteCond %{REQUEST_FILENAME} !-d
9+
RewriteCond %{REQUEST_FILENAME} !-f
10+
RewriteCond %{REQUEST_FILENAME} !-l
11+
12+
# Rewrite all other URLs to index.php/URL
13+
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
14+
</IfModule>
15+
16+
<IfModule !mod_rewrite.c>
17+
ErrorDocument 404 index.php
18+
</IfModule>
19+
1.95 KB
Loading

demos/login-system/index.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Public index file
4+
*
5+
* @project ApPHP Framework
6+
* @author ApPHP <[email protected]>
7+
* @link http://www.apphpframework.com/
8+
* @copyright Copyright (c) 2012 - 2013 ApPHP Framework
9+
* @license http://www.apphpframework.com/license/
10+
*/
11+
12+
// change the following paths if necessary
13+
defined('APPHP_PATH') || define('APPHP_PATH', dirname(__FILE__));
14+
// directory separator
15+
defined('DS') || define('DS', DIRECTORY_SEPARATOR);
16+
// production | debug | demo | test
17+
defined('APPHP_MODE') or define('APPHP_MODE', 'demo');
18+
19+
20+
$apphp = dirname(__FILE__).'/../../framework/Apphp.php';
21+
$config = APPHP_PATH.'/protected/config/';
22+
23+
require_once($apphp);
24+
A::init($config)->run();
25+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deny from all
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
class AccountController extends CController
4+
{
5+
6+
public function __construct()
7+
{
8+
parent::__construct();
9+
10+
// block access to this controller for not-logged users
11+
CAuth::handleLogin();
12+
13+
$this->view->setMetaTags('title', 'Sample application - Simple Login System : My Account');
14+
$this->view->setMetaTags('keywords', 'apphp framework, simple login system, apphp');
15+
$this->view->setMetaTags('description', 'This is a simple login system, consists from the few pages and protected area.');
16+
}
17+
18+
public function editAction()
19+
{
20+
$cRequest = A::app()->getRequest();
21+
$this->view->errorField = '';
22+
$this->view->actionMessage = '';
23+
$this->view->username = $cRequest->getPost('username');
24+
$this->view->password = $cRequest->getPost('password');
25+
$msg = '';
26+
$errorType = '';
27+
28+
$model = new Accounts();
29+
$info = $model->getInfo(CAuth::getLoggedId());
30+
31+
if($cRequest->getPost('act') == 'send'){
32+
33+
// perform account edit form validation
34+
$result = CWidget::create('CFormValidation', array(
35+
'fields'=>array(
36+
//'username'=>array('title'=>'Username' 'validation'=>array('required'=>true, 'type'=>'username', 'minLength'=>6)),
37+
'password'=>array('title'=>'Password', 'validation'=>array('required'=>true, 'type'=>'password', 'minLength'=>6)),
38+
),
39+
));
40+
41+
if($result['error']){
42+
$msg = $result['errorMessage'];
43+
$this->view->errorField = $result['errorField'];
44+
$errorType = 'validation';
45+
}else{
46+
if(APPHP_MODE == 'demo'){
47+
$msg = '<b>:(</b> Sorry, but update operation is blocked in DEMO version!';
48+
$errorType = 'warning';
49+
}else{
50+
if($model->save($this->view->username, $this->view->password)){
51+
$msg = 'Username and password have been successfully saved!';
52+
$errorType = 'success';
53+
}else{
54+
$msg = 'An error occurred while saving username and password! Please re-enter.';
55+
$this->view->errorField = 'password';
56+
$errorType = 'error';
57+
}
58+
}
59+
}
60+
61+
if(!empty($msg)){
62+
$this->view->username = $cRequest->getPost('username', 'string');
63+
$this->view->actionMessage = CWidget::create('CMessage', array($errorType, $msg, array('button'=>true)));
64+
}else{
65+
$this->view->username = $info['username'];
66+
}
67+
}else{
68+
$this->view->username = $info['username'];
69+
}
70+
71+
72+
$this->view->render('account/edit');
73+
}
74+
75+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
class ErrorController extends CController
4+
{
5+
6+
public function indexAction()
7+
{
8+
$this->view->header = 'Error 404: page not found!';
9+
$this->view->text = 'THE PAGE YOU WERE LOOKING FOR COULD NOT BE FOUND
10+
<br><br>
11+
This could be the result of the page being removed, the name being changed or the
12+
page being temporarily unavailable. This could be the result of the page being removed,
13+
the name being changed or the page being temporarily unavailable.
14+
15+
<br><br>
16+
TROUBLESHOOTING
17+
<ul>
18+
<li>If you spelled the URL manually, double check the spelling</li>
19+
<li>Go to our website\'s home page, and navigate to the content in question</li>
20+
<li>Alternatively, you can search our website below</li>
21+
</ul>
22+
';
23+
24+
$this->view->render('error/index');
25+
}
26+
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
class IndexController extends CController
4+
{
5+
6+
public function __construct()
7+
{
8+
parent::__construct();
9+
10+
$this->view->setMetaTags('title', 'Sample application - Simple Login System : Index');
11+
$this->view->setMetaTags('keywords', 'apphp framework, simple login system, apphp');
12+
$this->view->setMetaTags('description', 'This is a simple login system, consists from the few pages and protected area.');
13+
}
14+
15+
public function indexAction()
16+
{
17+
$this->view->header = 'Simple Login System';
18+
$this->view->text = '
19+
This is a template for a simple login system website. It includes a few pages and simple structure<br>
20+
consists from header, footer and a central part. It also includes a protected area, that may be <br>
21+
accessed by access after login. Use it as a starting point to create something more unique.
22+
<br><br>
23+
Click links from the top menu to see the site in work.
24+
';
25+
$this->view->render('index/index');
26+
}
27+
28+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
class LoginController extends CController
4+
{
5+
6+
public function __construct()
7+
{
8+
parent::__construct();
9+
10+
$this->view->errorField = '';
11+
$this->view->actionMessage = '';
12+
$this->view->username = '';
13+
$this->view->password = '';
14+
}
15+
16+
public function indexAction()
17+
{
18+
CAuth::handleLoggedIn('page/dashboard');
19+
20+
$this->view->render('login/index');
21+
}
22+
23+
public function logoutAction()
24+
{
25+
A::app()->getSession()->endSession();
26+
$this->redirect('login/index');
27+
}
28+
29+
public function runAction()
30+
{
31+
$cRequest = A::app()->getRequest();
32+
$this->view->username = $cRequest->getPost('username');
33+
$this->view->password = $cRequest->getPost('password');
34+
$msg = '';
35+
$errorType = '';
36+
37+
if($cRequest->getPost('act') == 'send'){
38+
39+
// perform login form validation
40+
$result = CWidget::create('CFormValidation', array(
41+
'fields'=>array(
42+
'username'=>array('title'=>'Username', 'validation'=>array('required'=>true, 'type'=>'any')),
43+
'password'=>array('title'=>'Password', 'validation'=>array('required'=>true, 'type'=>'any')),
44+
),
45+
));
46+
47+
if($result['error']){
48+
$msg = $result['errorMessage'];
49+
$this->view->errorField = $result['errorField'];
50+
$errorType = 'validation';
51+
}else{
52+
$model = new Login();
53+
if($model->login($this->view->username, $this->view->password)){
54+
$this->redirect('page/dashboard');
55+
}else{
56+
$msg = 'Wrong username or password! Please re-enter.';
57+
$this->view->errorField = 'username';
58+
$errorType = 'error';
59+
}
60+
}
61+
62+
if(!empty($msg)){
63+
$this->view->username = $cRequest->getPost('username', 'string');
64+
$this->view->password = $cRequest->getPost('password', 'string');
65+
$this->view->actionMessage = CWidget::create('CMessage', array($errorType, $msg));
66+
}
67+
}
68+
$this->view->render('login/index');
69+
}
70+
71+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
class PageController extends CController
4+
{
5+
public $id;
6+
7+
public function __construct()
8+
{
9+
parent::__construct();
10+
11+
$this->view->setMetaTags('title', 'Sample application - Simple Login System : Index');
12+
$this->view->setMetaTags('keywords', 'apphp framework, simple login system, apphp');
13+
$this->view->setMetaTags('description', 'This is a simple login system, consists from the few pages and protected area.');
14+
}
15+
16+
public function indexAction()
17+
{
18+
$this->redirect('index/index');
19+
}
20+
21+
public function errorAction()
22+
{
23+
$this->view->header = 'Error 404';
24+
$this->view->text = CDebug::getMessage('errors', 'action').'<br>Please check carefully the URL you\'ve typed.';
25+
$this->view->render('error/index');
26+
}
27+
28+
public function publicAction($id = 0)
29+
{
30+
$id = (CValidator::isDigit($id) && CValidator::validateMaxlength($id, 1)) ? $id : 0;
31+
$this->view->id = $id;
32+
$this->view->header = 'Page'.$id;
33+
if($id === '1'){
34+
$this->view->text = '
35+
Mauris quis nisl sit amet augue adipiscing consectetur. Praesent lacus augue,
36+
vulputate ullamcorper pharetra in, ultricies et justo. Nulla id sem tortor.
37+
Ut hendrerit sagittis erat nec tristique. Aenean placerat massa a magna condimentum scelerisque.
38+
<br><br>
39+
Ut varius bibendum urna ac convallis. Sed non porta elit. Cum sociis natoque penatibus et magnis
40+
dis parturient montes, nascetur ridiculus mus. Vestibulum a nunc tincidunt velit egestas pulvinar
41+
ut a tellus. Cras porta suscipit lorem eget mattis. Donec fringilla, leo in vulputate interdum,
42+
dolor justo dapibus justo, eget vehicula massa velit ornare justo. Sed et mi in nunc interdum
43+
malesuada ac eu magna. Mauris ornare vestibulum congue. In scelerisque orci vel velit condimentum
44+
hendrerit.
45+
';
46+
}else{
47+
$this->view->text = '
48+
Ut varius bibendum urna ac convallis. Sed non porta elit. Cum sociis natoque penatibus et magnis
49+
dis parturient montes, nascetur ridiculus mus. Vestibulum a nunc tincidunt velit egestas pulvinar
50+
ut a tellus. Cras porta suscipit lorem eget mattis.
51+
<br><br>
52+
Donec fringilla, leo in vulputate interdum, dolor justo dapibus justo, eget vehicula massa velit
53+
ornare justo. Sed et mi in nunc interdum malesuada ac eu magna. Mauris ornare vestibulum congue.
54+
In scelerisque orci vel velit condimentum hendrerit.
55+
<br><br>
56+
Mauris quis nisl sit amet augue adipiscing consectetur. Praesent lacus augue, vulputate ullamcorper
57+
pharetra in, ultricies et justo. Nulla id sem tortor. Ut hendrerit sagittis erat nec tristique.
58+
Aenean placerat massa a magna condimentum scelerisque. Cras porta suscipit lorem eget mattis. Donec
59+
fringilla, leo in vulputate interdum, dolor justo dapibus justo, eget vehicula massa velit ornare
60+
justo. Sed et mi in nunc interdum malesuada ac eu magna. Mauris ornare vestibulum congue. In
61+
scelerisque orci vel velit condimentum hendrerit.
62+
';
63+
}
64+
65+
$this->view->render('page/index');
66+
}
67+
68+
public function dashboardAction()
69+
{
70+
CAuth::handleLogin();
71+
$this->view->render('page/dashboard');
72+
}
73+
74+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
return array(
3+
// database settings
4+
'db' => array(
5+
'type' => '<DB_TYPE>',
6+
'host' => '<DB_HOST>',
7+
'database' => '<DB_NAME>',
8+
'username' => '<DB_USER>',
9+
'password' => '<DB_PASSWORD>',
10+
'prefix' => '<DB_PREFIX>',
11+
)
12+
);

0 commit comments

Comments
 (0)