Commit f8bc488f by Reynaldo

First commit

parent 0bb2180e
......@@ -13,6 +13,7 @@ class AppAsset extends AssetBundle
public $baseUrl = '@web';
public $css = [
'css/site.css',
'css/background.css',
];
public $js = [
];
......
......@@ -6,6 +6,7 @@ use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use yii\web\Response;
/**
* Site controller
......@@ -22,11 +23,11 @@ class SiteController extends Controller
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'actions' => ['login', 'error', 'index'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
......@@ -70,13 +71,29 @@ class SiteController extends Controller
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
$model = new LoginForm();
if(!Yii::$app->user->isGuest){
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
if($model->load(Yii::$app->request->post())){
$url = 'https://cis.del.ac.id/api/authentication/do-auth';
$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 {
return $this->render('login', [
'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;
use yii\widgets\Breadcrumbs;
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">
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
];
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();
if (Yii::$app->controller->action->id === 'login') {
/**
* Do not use this code in your template. Remove it.
* Instead, use the code $this->layout = '//main-login'; in your controller.
*/
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 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">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; My Company <?= date('Y') ?></p>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
];
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>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<!--<footer class="footer">-->
<!-- <div class="container">-->
<!-- <p class="pull-left">&copy; My Company --><?//= date('Y') ?><!--</p>-->
<!---->
<!-- <p class="pull-right">--><?//= Yii::powered() ?><!--</p>-->
<!-- </div>-->
<!--</footer>-->
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php } ?>
......@@ -7,17 +7,33 @@
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<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">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?php $form = ActiveForm::begin([
'action' => ['login'],
'id' => 'login-form'
]); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
......@@ -25,11 +41,14 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<div class="form-group" style="text-align: right">
<?= Html::submitButton('Login', ['class' => 'login-button', 'name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php ActiveForm::end(); ?>
</div>
<div class="col-lg-4"></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
}
}
public function myLogin($username) {
return Yii::$app->user->login($username, $this->rememberMe ? 3600 * 24 * 30 : 0);
}
/**
* Finds user by [[username]]
*
......
......@@ -118,3 +118,9 @@ a.desc:after {
.nav > li > form > button.logout:focus {
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