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,71 +10,83 @@ use yii\bootstrap\NavBar; ...@@ -10,71 +10,83 @@ use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs; use yii\widgets\Breadcrumbs;
use common\widgets\Alert; use common\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap"> if (Yii::$app->controller->action->id === 'login') {
<?php /**
NavBar::begin([ * Do not use this code in your template. Remove it.
'brandLabel' => 'My Company', * Instead, use the code $this->layout = '//main-login'; in your controller.
'brandUrl' => Yii::$app->homeUrl, */
'options' => [ echo $this->render(
'class' => 'navbar-inverse navbar-fixed-top', 'main-login',
], ['content' => $content]
]); );
$menuItems = [ }else{
['label' => 'Home', 'url' => ['/site/index']], AppAsset::register($this);
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>';
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?> ?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<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="container"> <div class="wrap">
<?= Breadcrumbs::widget([ <?php
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], NavBar::begin([
]) ?> 'brandLabel' => 'My Company',
<?= Alert::widget() ?> 'brandUrl' => Yii::$app->homeUrl,
<?= $content ?> 'options' => [
</div> 'class' => 'navbar-inverse navbar-fixed-top',
</div> ],
]);
<footer class="footer"> $menuItems = [
<div class="container"> ['label' => 'Home', 'url' => ['/site/index']],
<p class="pull-left">&copy; My Company <?= date('Y') ?></p> ];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>';
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<p class="pull-right"><?= Yii::powered() ?></p> <div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</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>
</div>
<br/>
<br/>
<div class="container">
<p>Please fill out the following fields to login:</p> <div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4 | blue-container">
<div class="row"> <?php $form = ActiveForm::begin([
<div class="col-lg-5"> 'action' => ['login'],
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?> '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 class="col-lg-4"></div>
</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