From b05f861667c5348212eb87d2d8d3a49b8cdd4d70 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Mon, 6 Jan 2020 10:50:57 +0100 Subject: [PATCH] add fingerpint rest --- backend/controllers/FingerprintController.php | 121 ++++++++++++++++++ backend/models/FingerprintSearch.php | 69 ++++++++++ backend/views/fingerprint/_form.php | 29 +++++ backend/views/fingerprint/_search.php | 35 +++++ backend/views/fingerprint/create.php | 21 +++ backend/views/fingerprint/index.php | 38 ++++++ backend/views/fingerprint/update.php | 23 ++++ backend/views/fingerprint/view.php | 39 ++++++ common/models/Fingerprint.php | 67 ++++++++++ .../m200103_104020_add_table_fingerprint.php | 54 ++++++++ .../m200106_093107_add_user_fingerprint.php | 52 ++++++++ rest/controllers/FingerprintController.php | 70 ++++++++++ rest/models/FingerPrintEnterForm.php | 19 +++ 13 files changed, 637 insertions(+) create mode 100644 backend/controllers/FingerprintController.php create mode 100644 backend/models/FingerprintSearch.php create mode 100644 backend/views/fingerprint/_form.php create mode 100644 backend/views/fingerprint/_search.php create mode 100644 backend/views/fingerprint/create.php create mode 100644 backend/views/fingerprint/index.php create mode 100644 backend/views/fingerprint/update.php create mode 100644 backend/views/fingerprint/view.php create mode 100644 common/models/Fingerprint.php create mode 100644 console/migrations/m200103_104020_add_table_fingerprint.php create mode 100644 console/migrations/m200106_093107_add_user_fingerprint.php create mode 100644 rest/controllers/FingerprintController.php create mode 100644 rest/models/FingerPrintEnterForm.php diff --git a/backend/controllers/FingerprintController.php b/backend/controllers/FingerprintController.php new file mode 100644 index 0000000..9fd3050 --- /dev/null +++ b/backend/controllers/FingerprintController.php @@ -0,0 +1,121 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all Fingerprint models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new FingerprintSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Fingerprint model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Fingerprint model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Fingerprint(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_fingerprint]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Fingerprint 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()) { + return $this->redirect(['view', 'id' => $model->id_fingerprint]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Fingerprint model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Fingerprint model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Fingerprint the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Fingerprint::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/FingerprintSearch.php b/backend/models/FingerprintSearch.php new file mode 100644 index 0000000..5fb3cec --- /dev/null +++ b/backend/models/FingerprintSearch.php @@ -0,0 +1,69 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_fingerprint' => $this->id_fingerprint, + 'id_customer' => $this->id_customer, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'fingerprint', $this->fingerprint]); + + return $dataProvider; + } +} diff --git a/backend/views/fingerprint/_form.php b/backend/views/fingerprint/_form.php new file mode 100644 index 0000000..7a896c5 --- /dev/null +++ b/backend/views/fingerprint/_form.php @@ -0,0 +1,29 @@ + + +
+ + + + field($model, 'id_customer')->textInput() ?> + + field($model, 'fingerprint')->textarea(['rows' => 6]) ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ isNewRecord ? Yii::t('common/fingerprint', 'Create') : Yii::t('common/fingerprint', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/fingerprint/_search.php b/backend/views/fingerprint/_search.php new file mode 100644 index 0000000..c425c71 --- /dev/null +++ b/backend/views/fingerprint/_search.php @@ -0,0 +1,35 @@ + + + diff --git a/backend/views/fingerprint/create.php b/backend/views/fingerprint/create.php new file mode 100644 index 0000000..9d36717 --- /dev/null +++ b/backend/views/fingerprint/create.php @@ -0,0 +1,21 @@ +title = Yii::t('common/fingerprint', 'Create Fingerprint'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/fingerprint', 'Fingerprints'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/fingerprint/index.php b/backend/views/fingerprint/index.php new file mode 100644 index 0000000..9f008b0 --- /dev/null +++ b/backend/views/fingerprint/index.php @@ -0,0 +1,38 @@ +title = Yii::t('common/fingerprint', 'Fingerprints'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> +

+ + $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id_fingerprint', + 'id_customer', + 'fingerprint:ntext', + 'created_at', + 'updated_at', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + +
diff --git a/backend/views/fingerprint/update.php b/backend/views/fingerprint/update.php new file mode 100644 index 0000000..d2cd23e --- /dev/null +++ b/backend/views/fingerprint/update.php @@ -0,0 +1,23 @@ +title = Yii::t('common/fingerprint', 'Update {modelClass}: ', [ + 'modelClass' => 'Fingerprint', +]) . ' ' . $model->id_fingerprint; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/fingerprint', 'Fingerprints'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_fingerprint, 'url' => ['view', 'id' => $model->id_fingerprint]]; +$this->params['breadcrumbs'][] = Yii::t('common/fingerprint', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/fingerprint/view.php b/backend/views/fingerprint/view.php new file mode 100644 index 0000000..157c365 --- /dev/null +++ b/backend/views/fingerprint/view.php @@ -0,0 +1,39 @@ +title = $model->id_fingerprint; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/fingerprint', 'Fingerprints'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id_fingerprint], ['class' => 'btn btn-primary']) ?> + $model->id_fingerprint], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/fingerprint', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id_fingerprint', + 'id_customer', + 'fingerprint:ntext', + 'created_at', + 'updated_at', + ], + ]) ?> + +
diff --git a/common/models/Fingerprint.php b/common/models/Fingerprint.php new file mode 100644 index 0000000..2a64343 --- /dev/null +++ b/common/models/Fingerprint.php @@ -0,0 +1,67 @@ + TimestampBehavior::className(), + 'value' => function(){ return date('Y-m-d H:i:s' ); }, + 'updatedAtAttribute' => false, + ] + ], parent::behaviors()); + } + + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'fingerprint'; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [['id_customer'], 'integer'], + [['fingerprint'], 'string'], + [['created_at', 'updated_at'], 'required'], + [['created_at', 'updated_at'], 'safe'] + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_fingerprint' => Yii::t('common/fingerprint', 'Id Fingerprint'), + 'id_customer' => Yii::t('common/fingerprint', 'Id Customer'), + 'fingerprint' => Yii::t('common/fingerprint', 'Fingerprint'), + 'created_at' => Yii::t('common/fingerprint', 'Created At'), + 'updated_at' => Yii::t('common/fingerprint', 'Updated At'), + ]; + } +} diff --git a/console/migrations/m200103_104020_add_table_fingerprint.php b/console/migrations/m200103_104020_add_table_fingerprint.php new file mode 100644 index 0000000..8e2dea6 --- /dev/null +++ b/console/migrations/m200103_104020_add_table_fingerprint.php @@ -0,0 +1,54 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('{{%fingerprint}}', [ + 'id_fingerprint' => $this->primaryKey(), + 'id_customer' => $this->integer(11), + 'fingerprint' => $this->text(), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m200103_104020_add_table_fingerprint cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m200103_104020_add_table_fingerprint cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/console/migrations/m200106_093107_add_user_fingerprint.php b/console/migrations/m200106_093107_add_user_fingerprint.php new file mode 100644 index 0000000..0140ad6 --- /dev/null +++ b/console/migrations/m200106_093107_add_user_fingerprint.php @@ -0,0 +1,52 @@ +username = 'fingerprint_system'; + $user->email = 'fingerprint_system@rocho-net.hu'; + $user->setPassword('Vn?y0c?DI|Ar6Kfvmf?$'); + $user->generateAuthKey(); + $user->save(); + + $role = Yii::$app->authManager->createRole('fingerprint_system'); + Yii::$app->authManager->add($role); + Yii::$app->authManager->assign($role, $user->id); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m200106_093107_add_user_fingerprint cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m200106_093107_add_user_fingerprint cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/rest/controllers/FingerprintController.php b/rest/controllers/FingerprintController.php new file mode 100644 index 0000000..58a00c3 --- /dev/null +++ b/rest/controllers/FingerprintController.php @@ -0,0 +1,70 @@ +$idCustomer]); + + $fingerPrintModel = new Fingerprint(); + $fingerPrintModel->id_customer = $customer->id_customer; + $fingerPrintModel->fingerprint = $fingerPrint; + $fingerPrintModel->save(false); + } + + /** + * @param string the sha string of the fingerprint $fingerPrint + * @return array the response + * @throws HttpException on any error + */ + public function actionEnter($fingerPrint) + { + + + /** @var Fingerprint $fingerPrint */ + $fingerPrint = Fingerprint::find()->andWhere(['fingerPrint' => $fingerPrint])->one(); + + if ( null === $fingerPrint) { + throw new HttpException(404, 'Not Found'); + } + + $customer = Customer::findOne($fingerPrint->id_customer); + + + if ( null === $customer) { + throw new HttpException(404, 'Not Found'); + } + + return + [ + 'id_customer' => $customer->id_customer + ]; + + } + +} diff --git a/rest/models/FingerPrintEnterForm.php b/rest/models/FingerPrintEnterForm.php new file mode 100644 index 0000000..ae69aa3 --- /dev/null +++ b/rest/models/FingerPrintEnterForm.php @@ -0,0 +1,19 @@ +