add rest application and discount-status rest method
This commit is contained in:
37
rest/controllers/RestController.php
Normal file
37
rest/controllers/RestController.php
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user