Commit f8bc488f by Reynaldo

First commit

parent 0bb2180e
...@@ -13,6 +13,7 @@ class AppAsset extends AssetBundle ...@@ -13,6 +13,7 @@ class AppAsset extends AssetBundle
public $baseUrl = '@web'; public $baseUrl = '@web';
public $css = [ public $css = [
'css/site.css', 'css/site.css',
'css/background.css',
]; ];
public $js = [ public $js = [
]; ];
......
...@@ -6,6 +6,7 @@ use yii\web\Controller; ...@@ -6,6 +6,7 @@ use yii\web\Controller;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\models\LoginForm; use common\models\LoginForm;
use yii\web\Response;
/** /**
* Site controller * Site controller
...@@ -22,11 +23,11 @@ class SiteController extends Controller ...@@ -22,11 +23,11 @@ class SiteController extends Controller
'class' => AccessControl::className(), 'class' => AccessControl::className(),
'rules' => [ 'rules' => [
[ [
'actions' => ['login', 'error'], 'actions' => ['login', 'error', 'index'],
'allow' => true, 'allow' => true,
], ],
[ [
'actions' => ['logout', 'index'], 'actions' => ['logout'],
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
], ],
...@@ -70,13 +71,29 @@ class SiteController extends Controller ...@@ -70,13 +71,29 @@ class SiteController extends Controller
*/ */
public function actionLogin() public function actionLogin()
{ {
if (!Yii::$app->user->isGuest) { $model = new LoginForm();
if(!Yii::$app->user->isGuest){
return $this->goHome(); return $this->goHome();
} }
$model = new LoginForm(); if($model->load(Yii::$app->request->post())){
if ($model->load(Yii::$app->request->post()) && $model->login()) { $url = 'https://cis.del.ac.id/api/authentication/do-auth';
return $this->goBack(); $data = array('username' => $model->username, 'password' => $model->password);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
\Yii::$app->response->format = Response::FORMAT_JSON;
echo parent::$result;
die();
return $this->redirect(['/site/index']);
} else { } else {
return $this->render('login', [ return $this->render('login', [
'model' => $model, 'model' => $model,
......
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use backend\assets\AppAsset;
use common\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body class="bluebox">
<?php $this->beginBody() ?>
<div class="wrap">
<?= Alert::widget() ?>
<?= $content ?>
</div>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
\ No newline at end of file
...@@ -10,23 +10,34 @@ use yii\bootstrap\NavBar; ...@@ -10,23 +10,34 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use common\widgets\Alert; use common\widgets\Alert;
AppAsset::register($this);
?> if (Yii::$app->controller->action->id === 'login') {
<?php $this->beginPage() ?> /**
<!DOCTYPE html> * Do not use this code in your template. Remove it.
<html lang="<?= Yii::$app->language ?>"> * Instead, use the code $this->layout = '//main-login'; in your controller.
<head> */
echo $this->render(
'main-login',
['content' => $content]
);
}else{
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"> <meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?> <?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title> <title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?> <?php $this->head() ?>
</head> </head>
<body> <body class="bluebox">
<?php $this->beginBody() ?> <?php $this->beginBody() ?>
<div class="wrap"> <div class="wrap">
<?php <?php
NavBar::begin([ NavBar::begin([
'brandLabel' => 'My Company', 'brandLabel' => 'My Company',
...@@ -64,17 +75,18 @@ AppAsset::register($this); ...@@ -64,17 +75,18 @@ AppAsset::register($this);
<?= Alert::widget() ?> <?= Alert::widget() ?>
<?= $content ?> <?= $content ?>
</div> </div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div> </div>
</footer>
<?php $this->endBody() ?> <!--<footer class="footer">-->
</body> <!-- <div class="container">-->
</html> <!-- <p class="pull-left">&copy; My Company --><?//= date('Y') ?><!--</p>-->
<?php $this->endPage() ?> <!---->
<!-- <p class="pull-right">--><?//= Yii::powered() ?><!--</p>-->
<!-- </div>-->
<!--</footer>-->
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php } ?>
...@@ -7,17 +7,33 @@ ...@@ -7,17 +7,33 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="site-login"> <div class="site-login">
<h1><?= Html::encode($this->title) ?></h1> <br/>
<br/>
<br/>
<br/>
<div class="container">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<img src="/PortalMahasiswa/backend/web/img/logo_new_v02.png" height="90px" align="center">
</div>
<div class="col-lg-4"></div>
<p>Please fill out the following fields to login:</p> </div>
<br/>
<br/>
<div class="container">
<div class="row"> <div class="row">
<div class="col-lg-5"> <div class="col-lg-4"></div>
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <div class="col-lg-4 | blue-container">
<?php $form = ActiveForm::begin([
'action' => ['login'],
'id' => 'login-form'
]); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
...@@ -25,11 +41,14 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -25,11 +41,14 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $form->field($model, 'rememberMe')->checkbox() ?> <?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group"> <div class="form-group" style="text-align: right">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> <?= Html::submitButton('Login', ['class' => 'login-button', 'name' => 'login-button']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
<div class="col-lg-4"></div>
</div> </div>
</div>
</div> </div>
.bluebox{
background-color: #40437c;
}
.blue-container{
background-color: #cccccc;
padding: 30px 30px 30px 30px;
}
.login-button {
background-color: #40437c; /* Green */
border: none;
color: white;
padding: 5px 30px 5px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
}
.login-button:hover {
background-color: #f4a259; /* Green */
color: white;
}
\ No newline at end of file
...@@ -62,6 +62,10 @@ class LoginForm extends Model ...@@ -62,6 +62,10 @@ class LoginForm extends Model
} }
} }
public function myLogin($username) {
return Yii::$app->user->login($username, $this->rememberMe ? 3600 * 24 * 30 : 0);
}
/** /**
* Finds user by [[username]] * Finds user by [[username]]
* *
......
...@@ -118,3 +118,9 @@ a.desc:after { ...@@ -118,3 +118,9 @@ a.desc:after {
.nav > li > form > button.logout:focus { .nav > li > form > button.logout:focus {
outline: none; outline: none;
} }
.test{
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment