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


PHP User::validate方法代码示例

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


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

示例1: actionRegister

 public function actionRegister()
 {
     $model = new User();
     $profile = new Profile();
     if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->validate()) {
         if ($model->validate()) {
             $id = $model->register();
             $profile->createProfile($id);
             return ['success' => true];
         }
     } else {
         return $model;
     }
 }
开发者ID:fosker,项目名称:dbm,代码行数:14,代码来源:DefaultController.php

示例2: actionInit

 /**
  *
  */
 public function actionInit()
 {
     // assign roles
     $oAuthManager = \Yii::$app->authManager;
     $oAuthManager->removeAll();
     // role user
     $oRoleUser = $oAuthManager->createRole('user');
     $oRoleUser->description = 'Registered user';
     $oAuthManager->add($oRoleUser);
     // create default users
     $aDefaultUser = \Yii::$app->params['aDefaultUser'];
     $oSecurity = \Yii::$app->security;
     foreach ($aDefaultUser as $sUsername => $aUserData) {
         $mUser = User::findOne(['username' => $aUserData['username']]);
         if (!$mUser) {
             $mUser = new User();
             $mUser->username = $sUsername;
             $mUser->password = $oSecurity->generatePasswordHash($aUserData['password']);
             $mUser->email = $aUserData['email'];
             $mUser->authKey = $oSecurity->generateRandomString();
         }
         if ($mUser->validate()) {
             $mUser->save();
             // assign role to each
             $oAuthManager->assign($oAuthManager->getRole($aUserData['role']), $mUser->id);
         }
     }
 }
开发者ID:Sywooch,项目名称:EVE-Manager-Yii-2.x,代码行数:31,代码来源:RbacController.php

示例3: actionCreate

 /**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $student = new Student();
     $user = new User();
     $person = new Person();
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post();
         $person->load($params);
         $user->load($params);
         $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
         $student->load($params);
         if ($person->validate() && $user->validate() && $student->validate()) {
             $person->save(false);
             $user->person_id = $person->id;
             $user->register();
             $student->user_id = $user->id;
             $student->save();
             Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
     }
 }
开发者ID:RomarioLopezC,项目名称:RobotSS,代码行数:32,代码来源:DefaultController.php

示例4: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $modelUser = new User();
     $modelProfile = new Profile();
     $roles = AuthItem::find()->all();
     $arrayRoles = ArrayHelper::map($roles, 'name', 'description');
     $regions = Region::find()->all();
     $arrayRegions = ArrayHelper::map($regions, 'id', 'name');
     if ($modelUser->load(Yii::$app->request->post())) {
         if ($modelUser->validate()) {
             $modelUser->setPassword($modelUser->password_hash);
             if ($modelUser->save(false)) {
                 $modelProfile->user_id = $modelUser->id;
                 $modelProfile->worker_name = $modelUser->worker_name;
                 $modelProfile->telephone = $modelUser->telephone;
                 $modelProfile->head_position = $modelUser->head_position;
                 $modelProfile->head_name = $modelUser->head_name;
                 $modelProfile->region_id = $modelUser->region;
                 if ($modelProfile->save(false)) {
                     $auth = Yii::$app->authManager;
                     $auth->revokeAll($modelUser->id);
                     $access = $auth->getRole($modelUser->access);
                     if ($auth->assign($access, $modelUser->id)) {
                         return $this->redirect(['view', 'id' => $modelUser->id]);
                     }
                 }
             }
         }
     }
     return $this->render('create', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
 }
开发者ID:filimonchuk93,项目名称:monitoring.my,代码行数:36,代码来源:UserController.php

示例5: actionSignup

 public function actionSignup()
 {
     $post = Application::request()->post();
     $warning = '';
     if (sizeof($post) > 0) {
         $model = new User();
         $model->load($post);
         $validation = $model->validate();
         if ($validation) {
             $user_id = $model->save();
             if ($user_id) {
                 Application::Identity()->signin($user_id);
                 $this->redirect('/search');
             } else {
                 $warning = 'Error adding row to DB';
             }
         } else {
             $warning = 'Please enter correct fields values';
         }
     }
     if (!Application::Identity()->check()) {
         $this->render('signup.html', ['salt' => Helper::generateCode(15), 'warning' => $warning]);
     } else {
         $this->redirect('/search');
     }
 }
开发者ID:dimichspb,项目名称:basic-users-app,代码行数:26,代码来源:UserController.php

示例6: _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

示例7: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:comaw,项目名称:hashtag,代码行数:16,代码来源:UsersController.php

示例8: testRegUser

 public function testRegUser()
 {
     $user = new User();
     $user->email = 'test@test.ru';
     $user->name = 'test';
     $user->setPassword('password');
     $user->generateAuthKey();
     $this->assertTrue($user->validate());
     $this->assertTrue($user->save());
     $this->tester->seeInDatabase('users', ['email' => 'test@test.ru', 'name' => 'test']);
 }
开发者ID:andrey3,项目名称:yii,代码行数:11,代码来源:UserTest.php

示例9: actionUser

 public function actionUser()
 {
     $model = new app\models\User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     return $this->render('user', ['model' => $model]);
 }
开发者ID:yodathedark,项目名称:moltis-tickets,代码行数:11,代码来源:SiteController.php

示例10: actionCreate

 public function actionCreate()
 {
     //TODO: Check rights
     $user = new User();
     if ($user->load(\yii::$app->request->post()) && $user->validate()) {
         $user->password = \yii::$app->getSecurity()->generatePasswordHash($user->password);
         $user->save();
         \Yii::$app->response->setStatusCode(201);
         return $this->actionGet($user->id);
     }
     return $user->errors;
 }
开发者ID:JiltImageBoard,项目名称:jilt-backend,代码行数:12,代码来源:UserController.php

示例11: actionCreate

 public function actionCreate()
 {
     $model = new User();
     $model->setAction('admin-insert');
     if (isset($_POST['save'])) {
         $model->setAttributes($_POST['User']);
         if ($model->validate() && $model->adminCreate()) {
             Messages::get()->success("User created!");
             $this->getRequest()->goToPage('users', 'index');
         }
     }
     $this->assign('model', $model);
 }
开发者ID:mpf-soft,项目名称:app-basic,代码行数:13,代码来源:Users.php

示例12: actionPost

 public function actionPost()
 {
     if ($userData = $this->container->request->post('User')) {
         $user = new User($this->container);
         $user->setModelData($userData);
         $user->pass = md5($user->pass);
         if ($user->validate() && $user->save()) {
             $this->redirect('/register/success');
         }
         $this->redirect('/register/error');
     }
     $this->redirect('/register');
 }
开发者ID:linpax,项目名称:micro-app-default,代码行数:13,代码来源:RegisterController.php

示例13: actionAdd

 public function actionAdd()
 {
     $user = new User();
     $user->name = 'simon1';
     $user->mail = '432423@qq.com';
     $user->password = 'fsfhsdlfh';
     //数据验证,在User类中添加rules()对数据进行校验
     $user->validate();
     if ($user->hasErrors()) {
         echo 'your data is error';
         die;
     }
     $user->save();
 }
开发者ID:thegofind,项目名称:yii2advance,代码行数:14,代码来源:DbController.php

示例14: login

 public function login(LoginRequest $request)
 {
     if ($user = User::validate($request->input())) {
         $userId = $user->id;
         if ($token = AccessToken::createToken($userId)) {
             $message = $this->getMessage('success', ['user_id' => $userId, 'username' => $user->username, 'token' => $token]);
         } else {
             $message = $this->getMessage('error', [Request::ERROR_DATABASE_INTERNAL_ERROR]);
         }
     } else {
         $message = $this->getMessage('error', [Request::ERROR_VALIDATE_USER_CREDENTIAL]);
     }
     return json_encode($message);
 }
开发者ID:kebingyu,项目名称:api-laravel,代码行数:14,代码来源:AuthController.php

示例15: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $model->salt = Str::random(10);
             $model->password = $model->generatePassword($model->password);
             if ($model->save(false)) {
                 Yii::$app->session->setFlash('create_user', '用户添加成功:您可以继续添加新用户,或返回用户列表。');
                 return $this->redirect(['create']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:NikDevPHP,项目名称:yii2-blog,代码行数:20,代码来源:UserController.php


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