Пример #1
0
 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();
 }
Пример #2
0
 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();
 }
Пример #3
0
 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;
 }
Пример #4
0
 private function showErrors(array $errors)
 {
     foreach ($errors as $message) {
         Alert::add($message, Alert::ERROR);
     }
 }