add rest application and discount-status rest method

This commit is contained in:
Roland Schneider
2018-08-31 07:50:14 +02:00
parent 017bf0f9e4
commit 767211d6c7
33 changed files with 805 additions and 16 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace rest\controllers;
use common\models\User;
use yii\filters\auth\HttpBasicAuth;
use yii\rest\Controller;
class RestController extends Controller
{
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => [$this, 'auth']
];
return $behaviors;
}
public function auth($username, $password)
{
try {
$user = User::findOne(['username' => $username]);
if ($user->validatePassword($password)) {
return $user;
}
} catch (\Exception $e) {
\Yii::error("Failed to load user: " . $e->getMessage());
}
return null;
}
}