diff --git a/.idea/dataSources.ids b/.idea/dataSources.ids new file mode 100644 index 0000000..894f3d6 --- /dev/null +++ b/.idea/dataSources.ids @@ -0,0 +1,2279 @@ + + + + + #@ + ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..4baf300 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + mysql + true + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306 + root + + + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6695e42..3fb41ef 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -66,16 +66,47 @@ - + + + + + + + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + @@ -84,7 +115,7 @@ - + @@ -92,69 +123,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + - - + + + + + @@ -182,20 +176,21 @@ - - - - - + + + + + + @@ -450,6 +445,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -508,6 +525,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -522,11 +739,13 @@ + - + + @@ -559,6 +778,12 @@ + + + + + + @@ -638,14 +863,14 @@ - + - + @@ -680,16 +905,6 @@ - - - - - - - - - - @@ -835,16 +1050,6 @@ - - - - - - - - - - @@ -874,11 +1079,6 @@ - - - - - @@ -886,13 +1086,6 @@ - - - - - - - @@ -900,45 +1093,15 @@ - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - @@ -946,25 +1109,102 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - + - + - + + + + + + + + + + + + + + + + + + + + diff --git a/www/protected/components/UserIdentity.php b/www/protected/components/UserIdentity.php index 3362eaa..9a25389 100644 --- a/www/protected/components/UserIdentity.php +++ b/www/protected/components/UserIdentity.php @@ -17,10 +17,14 @@ class UserIdentity extends CUserIdentity */ public function authenticate() { + $connection = Yii::app()->db; + + $command=$connection->createCommand("SELECT SValue FROM othervalues WHERE Name = 'AdminPassword'"); + $pw = $command->queryScalar(); + $users=array( // username => password - 'demo'=>'demo', - 'admin'=>'admin', //TODO Change me + 'admin' => $pw, ); if(!isset($users[$this->username])) $this->errorCode=self::ERROR_USERNAME_INVALID; diff --git a/www/protected/controllers/ProgrammeController.php b/www/protected/controllers/ProgrammeController.php index e108d3c..1b4563d 100644 --- a/www/protected/controllers/ProgrammeController.php +++ b/www/protected/controllers/ProgrammeController.php @@ -27,20 +27,20 @@ class ProgrammeController extends Controller { return array( array('allow', // allow all users to perform 'index' and 'view' actions - 'actions'=>array('index','view','create','update','admin','delete'), + 'actions'=>array('index','view'), 'users'=>array('*'), ), -// array('allow', // allow authenticated user to perform 'create' and 'update' actions -// 'actions'=>array('create','update'), -// 'users'=>array('@'), -// ), + array('allow', // allow authenticated user to perform 'create' and 'update' actions + 'actions'=>array('create','update','admin','delete'), + 'users'=>array('@'), + ), // array('allow', // allow admin user to perform 'admin' and 'delete' actions -// 'actions'=>array('admin','delete'), +// 'actions'=>array(), // 'users'=>array('admin'), // ), -// array('deny', // deny all users -// 'users'=>array('*'), -// ), + array('deny', // deny everythign else to all users + 'users'=>array('*'), + ), ); } @@ -106,6 +106,7 @@ class ProgrammeController extends Controller * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted + * @throws CHttpException on invalid request */ public function actionDelete($id) { diff --git a/www/protected/controllers/SiteController.php b/www/protected/controllers/SiteController.php index 32e9be5..3b1c4aa 100644 --- a/www/protected/controllers/SiteController.php +++ b/www/protected/controllers/SiteController.php @@ -57,8 +57,41 @@ class SiteController extends Controller $data['model'] = new SendMailForm(); } - - $this->render('about', $data); } + + /** + * 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 TbActiveForm::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); + } } \ No newline at end of file diff --git a/www/protected/models/LoginForm.php b/www/protected/models/LoginForm.php new file mode 100644 index 0000000..eb36e4a --- /dev/null +++ b/www/protected/models/LoginForm.php @@ -0,0 +1,77 @@ +'Remember me next time', + ); + } + + /** + * Authenticates the password. + * This is the 'authenticate' validator as declared in rules(). + */ + public function authenticate($attribute,$params) + { + if(!$this->hasErrors()) + { + $this->_identity=new UserIdentity($this->username,$this->password); + if(!$this->_identity->authenticate()) + $this->addError('password','Incorrect username or password.'); + } + } + + /** + * Logs in the user using the given username and password in the model. + * @return boolean whether login is successful + */ + public function login() + { + if($this->_identity===null) + { + $this->_identity=new UserIdentity($this->username,$this->password); + $this->_identity->authenticate(); + } + if($this->_identity->errorCode===UserIdentity::ERROR_NONE) + { + $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days + Yii::app()->user->login($this->_identity,$duration); + return true; + } + else + return false; + } +} diff --git a/www/protected/views/layouts/main.php b/www/protected/views/layouts/main.php index c9b40fd..2966fa6 100644 --- a/www/protected/views/layouts/main.php +++ b/www/protected/views/layouts/main.php @@ -47,6 +47,7 @@ ['label' => 'Programme', 'url' => '/programme/', 'active' => ($this->selectedNav === 'prog')], ['label' => '', 'items' => ProgrammeHelper::GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']], ['label' => 'About', 'url' => '/about', 'active' => ($this->selectedNav === 'about')], + ['label' => '[[Log "'.Yii::app()->user->name.'" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest] ], ], TbHtml::navbarSearchForm('search', '', diff --git a/www/protected/views/site/login.php b/www/protected/views/site/login.php new file mode 100644 index 0000000..11af234 --- /dev/null +++ b/www/protected/views/site/login.php @@ -0,0 +1,55 @@ +pageTitle = Yii::app()->name . ' - Login'; +$this->breadcrumbs = array( + 'Login', +); +?> + + + + Login + + Please fill out the following form with your login credentials: + + + beginWidget('TbActiveForm', array( + 'id' => 'login-form', + 'enableClientValidation' => true, + 'clientOptions' => array( + 'validateOnSubmit' => true, + ), + )); ?> + + Fields with * are required. + + + labelEx($model, 'username'); ?> + textField($model, 'username'); ?> + error($model, 'username'); ?> + + + + labelEx($model, 'password'); ?> + passwordField($model, 'password'); ?> + error($model, 'password'); ?> + + + + checkBox($model, 'rememberMe'); ?> + label($model, 'rememberMe'); ?> + error($model, 'rememberMe'); ?> + + + + + + + endWidget(); ?> + + + + \ No newline at end of file
Please fill out the following form with your login credentials:
Fields with * are required.