Skip to content

Commit

Permalink
add initial yii files
Browse files Browse the repository at this point in the history
  • Loading branch information
gedelumbung committed Jun 28, 2014
1 parent 4979042 commit 2a773d6
Show file tree
Hide file tree
Showing 30 changed files with 896 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yii-core
.DS_Store
assets
13 changes: 13 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

// change the following paths if necessary
$yii=dirname(__FILE__).'/yii-core/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// 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);

require_once($yii);
Yii::createWebApplication($config)->run();
1 change: 1 addition & 0 deletions protected/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
23 changes: 23 additions & 0 deletions protected/components/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
}
33 changes: 33 additions & 0 deletions protected/components/UserIdentity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
}
37 changes: 37 additions & 0 deletions protected/config/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',

// preloading 'log' component
'preload'=>array('log'),

// application components
'components'=>array(
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
);
90 changes: 90 additions & 0 deletions protected/config/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',

// preloading 'log' component
'preload'=>array('log'),

// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),

'modules'=>array(
// uncomment the following to enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
*/
),

// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
*/
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'[email protected]',
),
);
17 changes: 17 additions & 0 deletions protected/config/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
'components'=>array(
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
/* uncomment the following to provide test database connection
'db'=>array(
'connectionString'=>'DSN for test database',
),
*/
),
)
);
109 changes: 109 additions & 0 deletions protected/controllers/SiteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}

/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
}

/**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}

/**
* Displays the contact page
*/
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-Type: text/plain; charset=UTF-8";

mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}

/**
* Displays the login page
*/
public function actionLogin()
{
$model=new LoginForm;

// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}

// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}

/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
}
}
28 changes: 28 additions & 0 deletions protected/data/schema.mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE tbl_user (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(128) NOT NULL,
password VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL
);

INSERT INTO tbl_user (username, password, email) VALUES ('test1', 'pass1', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test2', 'pass2', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test3', 'pass3', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test4', 'pass4', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test5', 'pass5', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test6', 'pass6', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test7', 'pass7', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test8', 'pass8', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test9', 'pass9', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test10', 'pass10', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test11', 'pass11', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test12', 'pass12', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test13', 'pass13', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test14', 'pass14', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test15', 'pass15', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test16', 'pass16', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test17', 'pass17', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test18', 'pass18', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test19', 'pass19', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test20', 'pass20', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test21', 'pass21', '[email protected]');
28 changes: 28 additions & 0 deletions protected/data/schema.sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE tbl_user (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
username VARCHAR(128) NOT NULL,
password VARCHAR(128) NOT NULL,
email VARCHAR(128) NOT NULL
);

INSERT INTO tbl_user (username, password, email) VALUES ('test1', 'pass1', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test2', 'pass2', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test3', 'pass3', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test4', 'pass4', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test5', 'pass5', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test6', 'pass6', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test7', 'pass7', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test8', 'pass8', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test9', 'pass9', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test10', 'pass10', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test11', 'pass11', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test12', 'pass12', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test13', 'pass13', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test14', 'pass14', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test15', 'pass15', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test16', 'pass16', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test17', 'pass17', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test18', 'pass18', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test19', 'pass19', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test20', 'pass20', '[email protected]');
INSERT INTO tbl_user (username, password, email) VALUES ('test21', 'pass21', '[email protected]');
Binary file added protected/data/testdrive.db
Binary file not shown.
Loading

0 comments on commit 2a773d6

Please sign in to comment.