add customerapi + customer auth

This commit is contained in:
2019-09-30 19:33:48 +02:00
committed by Roland Schneider
parent 51788f2194
commit 9aee187d11
55 changed files with 21835 additions and 14 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace customerapi\controllers;
use common\components\Helper;
use common\models\Card;
use common\models\Customer;
use yii\filters\auth\HttpBasicAuth;
class RestController extends \yii\web\Controller
{
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => [$this, 'auth']
];
return $behaviors;
}
public function auth($username, $password)
{
try {
// $query = Card::find();
// Card::addCardNumberCondition($query, Helper::fixAsciiChars($username));
// $card = $query->one();
$customer = Customer::findOne(['email' => $username]);
if (isset($customer)) {
if ($customer->validatePassword($password)) {
return $customer;
}
}
} catch (\Exception $e) {
\Yii::error("Failed to load user: " . $e->getMessage());
}
return null;
}
}