Commit 749be554 by henny flora panjaitan

by henny

parent 026e0bb1
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\commands;
use yii\console\Controller;
use yii\console\ExitCode;
/**
* This command echoes the first argument that you have entered.
*
* This command is provided as an example for you to learn how to create console commands.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class HelloController extends Controller
{
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
* @return int Exit code
*/
public function actionIndex($message = 'hello world')
{
echo $message . "\n";
return ExitCode::OK;
}
}
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@tests' => '@app/tests',
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
],
'params' => $params,
/*
'controllerMap' => [
'fixture' => [ // Fixture generation command line.
'class' => 'yii\faker\FixtureController',
],
],
*/
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_online_voting',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',
];
<?php
return [
'adminEmail' => 'admin@example.com',
'senderEmail' => 'noreply@example.com',
'senderName' => 'Example.com mailer',
];
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/test_db.php';
/**
* Application configuration shared by all test types
*/
return [
'id' => 'basic-tests',
'basePath' => dirname(__DIR__),
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'language' => 'en-US',
'components' => [
'db' => $db,
'mailer' => [
'useFileTransport' => true,
],
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
'urlManager' => [
'showScriptName' => true,
],
'user' => [
'identityClass' => 'app\models\User',
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
// but if you absolutely need it set cookie domain to localhost
/*
'csrfCookie' => [
'domain' => 'localhost',
],
*/
],
],
'params' => $params,
];
<?php
$db = require __DIR__ . '/db.php';
// test database! Important not to run tests on production or development databases
$db['dsn'] = 'mysql:host=localhost;dbname=yii2_basic_tests';
return $db;
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '123',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => false,
'authTimeout' => 1000,
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => 'mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
/*'host' => 'email-smtp.us-west-2.amazonaws.com',
'username' => 'AKIA5TT7FXGNG7WGIZ5T',
'password' => 'BFNUb8VDVUGDvtshQIrQlpgvWJfoTBIu64R98/L48T5E',*/
'host' => 'smtp.gmail.com',
'username' => 'gtconlinesystem@gmail.com',
'password' => 'GtcKey@2019OK!',
'port' => '587',
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
'authManager' => [
'class' => 'yii\rbac\DbManager', // only support DbManager
],
],
'as access' => [
'class' => '\hscstudio\mimin\components\AccessControl',
'allowActions' => [
// add wildcard allowed action here!
'site/*',
//'user/*',
//'debug/*',
//'mimin/*', // only in dev mode
],
],
'modules' => [
'mimin' => [
'class' => '\hscstudio\mimin\Module',
],
'gridview' =>[
'class' => 'kartik\grid\Module',
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
<?php
namespace app\controllers;
use Yii;
use app\models\TKandidat;
use app\models\TKandidatSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* KandidatController implements the CRUD actions for TKandidat model.
*/
class KandidatController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all TKandidat models.
* @return mixed
*/
public function actionIndex($id_voting)
{
$model = TKandidat::find()->where(['id_voting' => $id_voting]);
$searchModel = new TKandidatSearch();
$dataProvider = $searchModel->searchData($model,Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single TKandidat model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->renderAjax('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new TKandidat model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id_voting)
{
$model = new TKandidat();
if ($model->load(Yii::$app->request->post())) {
$model->id_voting = $id_voting;
$model->save();
return $this->redirect(['index','id_voting'=>$id_voting]);
}
return $this->renderAjax('create', [
'model' => $model,
]);
}
/**
* Updates an existing TKandidat model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index', 'id_voting' => $model->id_voting]);
}
return $this->renderAjax('update', [
'model' => $model,
]);
}
/**
* Deletes an existing TKandidat model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id,$id_voting)
{
$this->findModel($id)->delete();
return $this->redirect(['index','id_voting'=>$id_voting]);
}
/**
* Finds the TKandidat model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return TKandidat the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = TKandidat::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use yii\web\NotFoundHttpException;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\RegistrationForm;
use app\models\User;
use hscstudio\mimin\models\AuthAssignment;
use app\models\TUser;
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
/**
* Login action.
*
* @return Response|string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
//return $this->goHome();
return $this->redirect(['site/index']);
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
//return $this->redirect(['site/index']);
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
/**
* Logout action.
*
* @return Response
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* Displays contact page.
*
* @return Response|string
*/
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
/**
* Displays about page.
*
* @return string
*/
public function actionAbout()
{
return $this->render('about');
}
/*
Fungsi Register : Untuk menambahkan user baru
*/
public function actionRegister()
{
$model = new User();
$modelRole = new AuthAssignment();
if ($model->load(Yii::$app->request->post())) {
$password = $model->password_hash;
//print_r($password);die;
$model->setPassword($password);
$model->status = 10;
if ($model->save()) {
$user = TUser::find()->where(['username' => $model->username])->andWhere(['email'=>$model->email])->one();
$modelRole->item_name = "PESERTA_VOTING";
$modelRole->user_id = $user->id;
if($modelRole->save()){
Yii::$app->session->setFlash('success', 'Registrasi User Berhasil');
}else{
$user->delete();
Yii::$app->session->setFlash('danger', 'Mohon Maaf, Registrasi User Gagal');
}
} else {
Yii::$app->session->setFlash('danger', 'Mohon Maaf, Registrasi User Gagal');
}
return $this->redirect(['index']);
} else {
return $this->render('register_user', [
'model' => $model,
]);
}
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\User;
use hscstudio\mimin\models\AuthAssignment;
use hscstudio\mimin\models\AuthItem;
use hscstudio\mimin\models\UserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\filters\AccessControl;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all User models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single User model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->column();
$authItems = ArrayHelper::map(
AuthItem::find()->where([
'type' => 1,
])->asArray()->all(),
'name', 'name');
$authAssignment = new AuthAssignment([
'user_id' => $model->id,
]);
if (Yii::$app->request->post()) {
$authAssignment->load(Yii::$app->request->post());
// delete all role
AuthAssignment::deleteAll(['user_id' => $model->id]);
if (is_array($authAssignment->item_name)) {
foreach ($authAssignment->item_name as $item) {
if (!in_array($item, $authAssignments)) {
$authAssignment2 = new AuthAssignment([
'user_id' => $model->id,
]);
$authAssignment2->item_name = $item;
$authAssignment2->created_at = time();
$authAssignment2->save();
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->column();
}
}
}
Yii::$app->session->setFlash('success', 'Data tersimpan');
}
$authAssignment->item_name = $authAssignments;
return $this->render('view', [
'model' => $model,
'authAssignment' => $authAssignment,
'authItems' => $authItems,
]);
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$model->setPassword('123456');
$model->status = $model->status==1?10:0;
if ($model->save()) {
Yii::$app->session->setFlash('success', 'User berhasil dibuat dengan password 123456');
} else {
Yii::$app->session->setFlash('error', 'User gagal dibuat');
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (!empty($model->new_password)) {
$model->setPassword($model->new_password);
}
$model->status = $model->status==1?10:0;
if ($model->save()) {
Yii::$app->session->setFlash('success', 'User berhasil diupdate');
} else {
Yii::$app->session->setFlash('error', 'User gagal diupdate');
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->status = $model->status==10?1:0;
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
$authAssignments = AuthAssignment::find()->where([
'user_id' => $model->id,
])->all();
foreach ($authAssignments as $authAssignment) {
$authAssignment->delete();
}
Yii::$app->session->setFlash('success', 'Delete success');
$model->delete();
return $this->redirect(['index']);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace app\controllers;
use Yii;
use app\models\MVoting;
use app\models\MVotingSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* MVotingController implements the CRUD actions for MVoting model.
*/
class VotingController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all MVoting models.
* @return mixed
*/
public function actionIndex()
{
//$model_voting = MVoting::find()->all();//"Select * from m_voting";
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
//'model_voting' => $model_voting,
]);
}
/**
* Displays a single MVoting model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->renderAjax('view', [
'model' => $this->findModel($id),
]);
}
public function actionViewdata(){
return $this->render('view_data', [
]);
}
/**
* Creates a new MVoting model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new MVoting();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$email = \Yii::$app->mailer->compose()
->setFrom(['gtconlinesystem@gmail.com'=>'Online Voting System'])
->setTo('goklasif10029@gmail.com')
->setSubject('Informasi Pemberitahuan Voting')
->setHtmlBody('
<b>Terima Kasih Buat Partisipasi Anda Telah Melakukan Voting</b>
<br><br>
<b>Hasil Voting Akan Ditunjukkan Jika Periode Voting Telah Berakhir</b>')
->send();
if($email){
Yii::$app->session->setFlash('success', "Voting Berhasil Dilakukan, Informasi bahwa anda telah berhasil melakukan Voting dikirim ke Email Anda");
}
else{
Yii::$app->session->setFlash('warning', "Voting Gagal Dilakukan, Silahkan Coba Kembali");
}
return $this->redirect(['index']);
}
return $this->renderAjax('create', [
'model' => $model,
]);
}
/**
* Updates an existing MVoting model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->renderAjax('update', [
'model' => $model,
]);
}
/**
* Deletes an existing MVoting model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the MVoting model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return MVoting the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = MVoting::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionIndexHasilVoting()
{
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index_hasil_voting', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionIndexPenggunaVoting()
{
$searchModel = new MVotingSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index_pengguna_voting', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
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