47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?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;
|
|
}
|
|
|
|
|
|
}
|