当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getErrors方法代码示例

本文整理汇总了PHP中app\models\User::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getErrors方法的具体用法?PHP User::getErrors怎么用?PHP User::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\User的用法示例。


在下文中一共展示了User::getErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->status = 0;
         if ($user->save()) {
             Yii::$app->getSession()->setFlash('success', ['type' => 'success', 'duration' => 5000, 'icon' => 'fa fa-users', 'message' => 'Successfully Register', 'title' => 'Hi, ' . $user->username . ' Thanks for register..', 'positonY' => 'top', 'positonX' => 'left']);
             $notification = new \sintret\gii\models\Notification();
             $notification->title = 'user';
             $notification->message = 'new user, username:' . $user->username;
             $notification->params = \yii\helpers\Json::encode(['model' => 'User', 'id' => $user->id]);
             if ($notification->save()) {
                 $this->sendEmail($this->email);
             } else {
                 print_r($notification->getErrors());
                 exit(0);
             }
             return $user;
         } else {
             return $user->getErrors();
         }
     }
     return null;
 }
开发者ID:sintret,项目名称:yii2-basic-sintret,代码行数:33,代码来源:SignupForm.php

示例2: _addOrUpdate

 private function _addOrUpdate($params)
 {
     if ($params['id']) {
         $user = User::findOne(['id' => $params['id']]);
         if (!$user) {
             return ['success' => 0, 'message' => 'No such user exist'];
         }
     } else {
         $user = new User();
     }
     $user->username = $params['username'];
     $user->email = $params['email'];
     $user->phone = $params['phone'];
     $user->password = $params['password'];
     if (!$user->validate()) {
         return ['success' => 0, 'message' => $user->getErrors()];
     }
     if (count($_FILES)) {
         $uploader = new FileUploader($_FILES['profile_picture']);
         $fileName = md5($user->email . Yii::$app->security->generateRandomString());
         $path = Yii::$app->basePath . '/web/images/profile/' . $fileName . '.' . $uploader->extension();
         $uploadStatus = $uploader->save($path);
         if (!$uploadStatus['success']) {
             return ['success' => 0, 'message' => $uploadStatus['error']];
         }
         $user->profile_picture = $file_name . '.' . $uploader->extension();
     }
     if (!$user->save()) {
         return ['success' => 0, 'message' => 'Some error occurred'];
     }
     return ['success' => 1, 'payload' => $user];
 }
开发者ID:aniruddhanath,项目名称:yii2-rest-api,代码行数:32,代码来源:UserController.php

示例3: actionInit

 public function actionInit()
 {
     $model = new User();
     $model->username = 'admin';
     $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG';
     $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC';
     $model->email = 'sintret@gmail.com';
     $model->phone = '6281575068530';
     $model->role = User::ROLE_ADMIN;
     $model->status = User::STATUS_ACTIVE;
     if ($model->save()) {
         echo 'success insert user, with usename:admin and password:123456';
     } else {
         echo json_encode($model->getErrors());
     }
     $setting = new Setting();
     $setting->emailAdmin = 'sintret@gmail.com';
     $setting->emailSupport = 'sintret@gmail.com';
     $setting->emailOrder = 'sintret@gmail.com';
     $setting->facebook = 'https://www.facebook.com/sintret';
     $setting->instagram = 'https://instagram.com/andyfitria/';
     $setting->google = 'https://google.com/sintret/';
     if ($setting->save()) {
         echo "\r\n success insert basic settings";
     } else {
         echo json_encode($setting->getErrors());
     }
 }
开发者ID:sintret,项目名称:yii2-basic,代码行数:28,代码来源:InsertController.php

示例4: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->status = 0;
         if ($user->save()) {
             $notification = new Notification();
             $notification->title = 'user';
             $notification->message = 'new user, username:' . $user->username;
             $notification->params = \yii\helpers\Json::encode(['model' => 'User', 'id' => $user->id]);
             if ($notification->save()) {
                 $this->sendEmail($this->email);
             } else {
                 print_r($notification->getErrors());
                 exit(0);
             }
             return $user;
         } else {
             return $user->getErrors();
         }
     }
     return null;
 }
开发者ID:sintret,项目名称:yii2-basic,代码行数:32,代码来源:SignupForm.php

示例5: actionRegister

 /**
  * 注册
  */
 public function actionRegister()
 {
     $layout = Yii::$app->request->get('layout', 0);
     if ($layout == 1) {
         $this->layout = false;
     } else {
         $this->layout = 'userLayout';
     }
     $postData = $this->getPostJSON();
     if ($postData) {
         $model = new User();
         $model->load($postData);
         $model->authKey = $this->getUUID(self::AUTH_PREFIX);
         $transtion = Yii::$app->db->beginTransaction();
         try {
             if ($model->save()) {
                 $userValidate = new UserValidate();
                 $userValidate->email = $model->email;
                 $userValidate->userid = $model->id;
                 if (!$userValidate->save()) {
                     $transtion->rollBack();
                     $error = current($model->getErrors());
                     $message = current($error);
                     return json_encode(['success' => 0, 'message' => $message]);
                 }
                 //$this->sendVaildateMail($model->email, 'user-validate', ['token'=>$userValidate->token]);
                 $resultLog = OperationLog::saveLog($model->username . "注册", $model->id, OperationLog::TYPE_USER);
                 if (!$resultLog['result']) {
                     $transtion->rollBack();
                     return json_encode(['success' => 0, 'message' => $resultLog['message']]);
                 }
                 $transtion->commit();
                 return json_encode(['success' => 1, 'message' => '注册成功']);
             } else {
                 $transtion->rollBack();
                 $error = current($model->getErrors());
                 $message = current($error);
                 return json_encode(['success' => 0, 'message' => $message]);
             }
         } catch (Exception $e) {
             $transtion->rollBack();
             return json_encode(['success' => 0, 'message' => $e->getMessage()]);
         }
     } else {
         return $this->render('_register');
     }
 }
开发者ID:superman1982,项目名称:mars,代码行数:50,代码来源:UserController.php

示例6: reg

 public function reg()
 {
     $user = new User();
     var_dump($this->status);
     $user->username = $this->username;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     if ($user->save()) {
         return $user;
     } else {
         var_dump($user->getErrors());
         exit;
         $this->addErrors($user->getErrors());
         return null;
     }
 }
开发者ID:pmesher,项目名称:taskmy,代码行数:18,代码来源:RegForm.php

示例7: actionCreate

 /**
  * Create user command.
  *
  * @param $email email address
  * @param $password plain password
  */
 public function actionCreate($email, $password)
 {
     $user = new User();
     $user->email = $email;
     $user->password = $password;
     $user->generateAuthKey();
     if (!$user->save()) {
         $this->outputValidateErrors($user->getErrors());
     } else {
         echo "[32mCreate new user with ID {$user->id}[0m\n";
     }
 }
开发者ID:starcode-solutions,项目名称:star-tracker,代码行数:18,代码来源:UserController.php

示例8: create

 public function create()
 {
     if ($this->request->data) {
         $user = new User($this->request->data);
         if ($user->save()) {
             $this->message('Successfully to create User');
             $this->redirect('Users::index');
         } else {
             $this->message('Failed to create User, please check the error');
             $errors = $user->getErrors();
         }
     }
     return compact('user', 'errors');
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:14,代码来源:UsersController.php

示例9: register

 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->password = $this->password;
     $user->firstname = $this->firstname;
     $user->lastname = $this->lastname;
     if (!$user->save()) {
         Yii::warning($user->getErrors());
         return false;
     }
     Yii::$app->user->login($user);
     return true;
 }
开发者ID:kyuchukovv,项目名称:restaurant-rate,代码行数:18,代码来源:RegisterForm.php

示例10: register

 /**
  * Logs in a user using the provided username and password.
  * @return boolean whether the user is logged in successfully
  */
 public function register()
 {
     if ($this->validate()) {
         $user = new User();
         $user->setScenario(User::SCENARIO_REGISTER);
         $user->email = $this->email;
         $user->password = $this->password;
         $saveResult = $user->save();
         if (!$saveResult) {
             /**
              * @todo: remove when you need to use this on real server
              */
             var_dump($user->getErrors());
             die;
         }
         return $saveResult;
     }
     return false;
 }
开发者ID:arossokha,项目名称:webcamp_php_adv_29_11,代码行数:23,代码来源:RegistrationForm.php

示例11: actionCreate

 /**
  * Creates a new user.
  * @param string $name user name
  * @param string $email user email
  * @param string $password uncrypted password, if skipped random password will be generated.
  */
 public function actionCreate($name, $email, $password = '')
 {
     if (empty($password)) {
         $random = Yii::$app->security->generateRandomString(8);
     }
     $user = new User();
     $user->name = $name;
     $user->email = $email;
     $user->status = User::STATUS_ENABLED;
     $user->setPassword(empty($password) ? $random : $password);
     if ($user->save()) {
         $this->p('User "{name}" has been created.', ['name' => $user->name]);
         if (empty($password)) {
             $this->p('Random password "{password}" has been generated.', ['password' => $random]);
         }
     } else {
         $this->err('Couldn\'t create user.');
         foreach ($user->getErrors() as $attribute => $error) {
             print reset($error) . PHP_EOL;
         }
     }
 }
开发者ID:skoro,项目名称:yii2-admin-template,代码行数:28,代码来源:UserController.php

示例12: testValidateModel

 public function testValidateModel()
 {
     $user = new User(array('fullname' => 'Mukhamad Ikhsan', 'email' => 'some.email@email.com'));
     $this->assertFalse($user->save());
     $this->assertEqual(array('password' => array('Password cannot be empty.')), $user->getErrors());
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:6,代码来源:ModelTest.php

示例13: fire


//.........这里部分代码省略.........
         $this->comment('First Name: ' . $first_name);
         $this->comment('Last Name: ' . $last_name);
         $this->comment('Username: ' . $user_username);
         $this->comment('Email: ' . $user_email);
         $this->comment('Category Name: ' . $user_asset_category);
         $this->comment('Item: ' . $user_asset_name);
         $this->comment('Manufacturer ID: ' . $user_asset_mfgr);
         $this->comment('Model No: ' . $user_asset_modelno);
         $this->comment('Serial No: ' . $user_asset_serial);
         $this->comment('Asset Tag: ' . $user_asset_tag);
         $this->comment('Location: ' . $user_asset_location);
         $this->comment('Purchase Date: ' . $user_asset_purchase_date);
         $this->comment('Purchase Cost: ' . $user_asset_purchase_cost);
         $this->comment('Notes: ' . $user_asset_notes);
         $this->comment('Company Name: ' . $user_asset_company_name);
         $this->comment('------------- Action Summary ----------------');
         if ($user_username != '') {
             if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) {
                 $this->comment('User ' . $user_username . ' already exists');
             } else {
                 $user = new \App\Models\User();
                 $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
                 $user->first_name = $first_name;
                 $user->last_name = $last_name;
                 $user->username = $user_username;
                 $user->email = $user_email;
                 $user->permissions = '{user":1}';
                 $user->password = bcrypt($password);
                 $user->activated = 1;
                 if ($user->save()) {
                     $this->comment('User ' . $first_name . ' created');
                 } else {
                     $this->error('ERROR CREATING User ' . $first_name . ' ' . $last_name);
                     $this->error($user->getErrors());
                 }
             }
         } else {
             $user = new User();
         }
         // Check for the location match and create it if it doesn't exist
         if ($location = Location::where('name', e($user_asset_location))->first()) {
             $this->comment('Location ' . $user_asset_location . ' already exists');
         } else {
             $location = new Location();
             if ($user_asset_location != '') {
                 $location->name = e($user_asset_location);
                 $location->address = '';
                 $location->city = '';
                 $location->state = '';
                 $location->country = '';
                 $location->user_id = 1;
                 if (!$this->option('testrun') == 'true') {
                     if ($location->save()) {
                         $this->comment('Location ' . $user_asset_location . ' was created');
                     } else {
                         $this->error('Something went wrong! Location ' . $user_asset_location . ' was NOT created');
                         $this->error($location->getErrors());
                     }
                 } else {
                     $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only');
                 }
             } else {
                 $this->comment('No location given, so none created.');
             }
         }
         if (e($user_asset_category) == '') {
开发者ID:dmeltzer,项目名称:snipe-it,代码行数:67,代码来源:AssetImportCommand.php

示例14: actionCreateAdmin

 /**
  * Создание учётной записи администратора
  */
 public function actionCreateAdmin()
 {
     $this->stdout('Добавление администратора' . PHP_EOL);
     $this->stdout('Логин: ' . PHP_EOL);
     $username = Console::stdin();
     $this->stdout('E-mail: ' . PHP_EOL);
     $email = Console::stdin();
     $this->stdout('Пароль: ' . PHP_EOL);
     $password = Console::stdin();
     $user = new User();
     $user->username = $username;
     $user->email = $email;
     $user->setPassword($password);
     $user->generateAuthKey();
     if ($user->validate() === false) {
         $this->stdout('Ошибки при вводе данных: ' . print_r($user->getErrors(), true));
         return;
     }
     if ($user->save()) {
         $this->stdout('Пользователь добавлен' . PHP_EOL, Console::FG_GREEN);
         /** @var ManagerInterface $auth */
         $auth = Yii::$app->authManager;
         $authorRole = $auth->getRole(AclHelper::ROLE_ADMIN);
         $auth->assign($authorRole, $user->id);
         $this->stdout('Права пользователя добавлены' . PHP_EOL, Console::FG_GREEN);
     }
 }
开发者ID:Konsul117,项目名称:phonebook,代码行数:30,代码来源:InitController.php

示例15: userInit

 /**
  * @return User
  */
 private function userInit()
 {
     $user = new User();
     $user->username = 'admin';
     $user->email = 'admin@admin.com';
     $user->setPassword('admin');
     $user->first_name = 'admin';
     $user->last_name = 'admin';
     $user->generateAuthKey();
     if ($user->save()) {
         $this->rbacInit($user->id);
         return $user;
     } else {
         die(var_dump($user->getErrors()));
     }
 }
开发者ID:mops1k,项目名称:yiimine,代码行数:19,代码来源:InstallController.php


注:本文中的app\models\User::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。