public function actionDelete(Request $request) { if (!Oauth::isLogged()) { return $this->goBack(); } /* @var $model Unit */ $model = Unit::find($request->getAttribute('id')); if ($model->delete()) { Alert::add("Successful delete {$model->name}"); } return $this->goBack(); }
public function actionLogin(Request $request) { $model = Oauth::firstOrNew($request->getParams()); if (!$model->id) { Alert::add('Wrong pin', Alert::ERROR); return $this->render('oauth/index'); } if (!$model->validateTime()) { Alert::add('Pin is outdated', Alert::ERROR); return $this->render('oauth/index'); } $this->login(); return $this->goHome(); }
public function validate($attributes = []) { /* @var $this Model */ if (!method_exists($this, 'rules')) { return true; } $attributes = $attributes ? array_merge($this->getAttributes(), $attributes) : $this->getAttributes(); $validator = Main::$app->connection->validator->make($attributes, $this->rules()); $result = $validator->passes(); if (!$result) { $this->errors = $validator->errors(); foreach ($this->errors->getMessages() as $errors) { foreach ($errors as $error) { Alert::add($error, Alert::ERROR); } } return false; } return true; }
private function showErrors(array $errors) { foreach ($errors as $message) { Alert::add($message, Alert::ERROR); } }