Ejemplo n.º 1
0
function errorHandler($number, $message, $file, $line, $vars)
{
    /* GET ERROR */
    $errors = Errors::select('E')->where('message', $message)->andWhere('file', $file)->andWhere('line', $line)->andWhere('DATE(time_catch)', '=', 'CURDATE()', false)->get();
    if (!is_null($vars) && $vars === 3) {
        return;
    }
    if (empty($errors)) {
        $error = Errors::create();
        $error->number = $number;
        $error->message = $message;
        $error->file = $file;
        $error->line = $line;
        $error->time_catch = BaseModel::now();
        $error->save();
    }
}
Ejemplo n.º 2
0
 public function actionLogin()
 {
     $post = Yii::$app->request->post();
     if (empty($post)) {
         throw new NotFoundHttpException('Need send username and password');
     }
     /** @var User $model */
     $model = User::find()->where(["username" => $post["username"]])->one();
     if (empty($model)) {
         throw new ForbiddenHttpException(Errors::getError(Errors::USER_WRONG_PASSWORD), Errors::USER_WRONG_PASSWORD);
     }
     if ($model->validatePassword($post["password"])) {
         //            $model->last_login = Yii::$app->formatter->asTimestamp(date_create());
         //            $model->save(false);
         return ['auth_key' => $model->getAccessToken()];
     } else {
         throw new ForbiddenHttpException(Errors::getError(Errors::USER_WRONG_PASSWORD), Errors::USER_WRONG_PASSWORD);
     }
 }