本文整理汇总了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;
}
示例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];
}
示例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());
}
}
示例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;
}
示例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');
}
}
示例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;
}
}
示例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";
}
}
示例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');
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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());
}
示例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) == '') {
示例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);
}
}
示例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()));
}
}