當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::validate方法代碼示例

本文整理匯總了PHP中common\models\User::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::validate方法的具體用法?PHP User::validate怎麽用?PHP User::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\User的用法示例。


在下文中一共展示了User::validate方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
         if ($user->validate()) {
             $broker = new Broker();
             $broker->user_id = 1;
             $broker->type_id = $this->type_id;
             $broker->name = $this->name;
             $broker->company = $this->company;
             $broker->phone = $this->phone;
             $broker->email = $this->email;
             $broker->address = $this->address;
             $broker->contact = $this->contact;
             $broker->recommend = $this->recommend;
             $broker->note_user = $this->note_user;
             $broker->sale_add = $this->sale_add;
             if ($broker->validate()) {
                 $user->save();
                 $broker->user_id = $user->id;
                 $broker->save();
                 return $user;
             }
         }
     }
     return null;
 }
開發者ID:dench,項目名稱:resistor,代碼行數:36,代碼來源:SignupForm.php

示例2: 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();
     $model->scenario = User::SCENARIO_CREATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (!($role = User::getAuthItem($model->role))) {
             $model->addError('role', 'Role does not exist');
         } else {
             $transaction = $model->getDb()->beginTransaction();
             try {
                 if ($model->save(false)) {
                     if (!$model->assignRole()) {
                         throw new Exception();
                     }
                     if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
                         throw new Exception();
                     }
                     $transaction->commit();
                     return $this->redirect('index');
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:ninetor,項目名稱:yii-classifield,代碼行數:32,代碼來源:UserController.php

示例3: 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();
     $model->scenario = 'create';
     $userData = new UserData();
     //$hotelMapping = new UserHotelMapping();
     if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) {
         $validUser = $model->validate();
         $validUserData = $userData->validate();
         //$validHotelMapping = $hotelMapping->validate();
         if ($validUser && $validUserData) {
             // && $validHotelMapping
             $model->setPassword($model->password);
             $model->generateAuthKey();
             if ($model->save()) {
                 $userData->user_id = $model->id;
                 //$hotelMapping->user_id = $model->id;
                 $userData->save(false);
                 //$hotelMapping->save(false);
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('create', ['model' => $model, 'userData' => $userData]);
 }
開發者ID:vetal2409,項目名稱:example,代碼行數:30,代碼來源:UserController.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()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->setPassword($model->password);
         $model->generateAuthKey();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:pookiez797,項目名稱:Yii2-Training-Day5,代碼行數:17,代碼來源:UserController.php

示例5: actionCreate

 public function actionCreate()
 {
     $model = new User();
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             if ($model->new_password) {
                 $this->savePassword($model);
             }
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
開發者ID:afernandes465,項目名稱:fafediesel,代碼行數:13,代碼來源:UserController.php

示例6: actionRequestPasswordReset

 public function actionRequestPasswordReset()
 {
     $model = new User();
     $model->scenario = 'requestPasswordResetToken';
     if ($model->load($_POST) && $model->validate()) {
         if ($this->sendPasswordResetEmail($model->email)) {
             Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
             $this->redirect('index');
         } else {
             Yii::$app->getSession()->setFlash('error', 'There was an error sending email.');
         }
     }
     return $this->render('requestPasswordResetToken', array('model' => $model));
 }
開發者ID:nsanden,項目名稱:Yii2-AspectMock,代碼行數:14,代碼來源:SiteController.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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->setPassword($model->new_password);
         $model->generateAuthKey();
         if ($model->save(false)) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         Yii::$app->getSession()->setFlash('error', "Please correct the mistakes and try again later.");
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:api55,項目名稱:code_test,代碼行數:20,代碼來源:UserController.php

示例8: 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();
     $model->scenario = 'create';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->setPassword($model->password);
         $model->generateAuthKey();
         // Force null
         $model->full_name = empty($model->full_name) ? null : $model->full_name;
         $model->save();
         $auth = Yii::$app->authManager;
         $auth->assign($auth->getRole($model->role), $model->id);
         Yii::$app->getSession()->setFlash('user_create_success', ['type' => Growl::TYPE_SUCCESS, 'title' => '<b>' . Yii::t('backend', 'Success') . '</b>', 'icon' => 'glyphicon glyphicon-ok-sign', 'body' => '<strong>' . $model->username . '</strong> ' . Yii::t('backend', 'has been added.')]);
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:gearger,項目名稱:imagenizer,代碼行數:23,代碼來源:UserController.php

示例9: actionCreate

 /**
  * Creates a new Broker model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Broker();
     $user = new User();
     $user->group_id = 2;
     $model->type_id = Yii::$app->request->get('type_id');
     if ($model->load(Yii::$app->request->post()) && $user->load(Yii::$app->request->post())) {
         $model->user_id = 1;
         if ($model->validate() && $user->validate()) {
             $user->setPassword($user->password);
             $user->generateAuthKey();
             if ($user->save()) {
                 $model->user_id = $user->id;
                 if ($model->save()) {
                     return $this->redirect(['/broker']);
                 }
             }
         }
     }
     return $this->render('create', ['model' => $model, 'user' => $user]);
 }
開發者ID:dench,項目名稱:resistor,代碼行數:26,代碼來源:BrokerController.php

示例10: actionUpdate

 public function actionUpdate($id)
 {
     if ($id) {
         $model = User::findOne($id);
         if (!$model) {
             throw new NotFoundHttpException();
         }
     } else {
         $model = new User();
     }
     $passwordModel = new \common\forms\UserChangePassword();
     if ($model->load(Yii::$app->request->post()) && $passwordModel->load(Yii::$app->request->post()) && $model->validate() && $passwordModel->validate()) {
         if (!empty($passwordModel->password)) {
             $model->password = $passwordModel->password;
         }
         $model->save();
         Yii::$app->session->addFlash('success', 'Пользователь сохранен');
         return $this->goBack();
     } else {
         Yii::$app->user->returnUrl = Yii::$app->request->referrer;
     }
     return $this->render('update', ['model' => $model, 'passwordModel' => $passwordModel]);
 }
開發者ID:ejen,項目名稱:yii2-app-advanced,代碼行數:23,代碼來源:UserController.php

示例11: actionReset

 public function actionReset()
 {
     $this->layout = 'login';
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         if ($_POST['User']) {
             $model->attributes = $_POST['User'];
             $valid = $model->validate();
             if ($valid) {
                 $model = User::find()->where(['email' => $_POST['User']['email']])->one();
                 $str = date('ymdhis') . 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('d');
                 $potong = str_shuffle($str);
                 $random = substr($potong, 3, 8, 12);
                 $model->setPassword($random);
                 $content = '
                 <center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
                 <h4 align="center">Badan Pengawas Tenaga Nuklir  ' . date('Y') . '</h4>
                 <hr/>
                 <p>Yth ' . $model->username . ',<br/>  
                 Dengan ini kami sampaikan password telah direset  sebagai berikut:<br/> 
                 Username : ' . $model->username . ' <br/>
                 Password :<b>' . $random . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
                 <h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN  ' . date('Y') . '</h5><br/>';
                 Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
                 $model->save();
                 return $this->redirect(['/site/login']);
             }
         }
     }
     return $this->render('reset', ['model' => $model]);
 }
開發者ID:ilhammalik,項目名稱:yii2-advanced-beta,代碼行數:32,代碼來源:SiteController_backup.php

示例12: addUser

 public static function addUser($weixinUser)
 {
     #注冊新用戶
     $newuser = new User();
     $newuser->setAttribute('username', $weixinUser);
     $newuser->setAttribute('password', $newuser->generatePassword(self::generateRandString()));
     $newuser->setAttribute('wangwang', $weixinUser);
     if ($newuser->validate() && $newuser->save()) {
         $accountarray = array('user_id' => \Yii::$app->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0);
         $newAccount = new Account();
         $newAccount->setAttributes($accountarray);
         $newAccount->save();
     }
     $user = User::find()->where("username=:username", [":username" => $weixinUser])->one();
     return $user;
 }
開發者ID:uqiauto,項目名稱:wxzuan,代碼行數:16,代碼來源:WechatCheck.php

示例13: actionCreateAdmin

    /**
     * 創建一個管理員用戶
     * @author Fufeng Nie <niefufeng@gmail.com>
     */
    public function actionCreateAdmin()
    {
        echo '
         ┏┓   ┏┓+ +
        ┏┛┻━━━┛┻┓ + +
        ┃       ┃  
        ┃   ━   ┃ ++ + + +
        ████━████ ┃+
        ┃       ┃ +
        ┃   ┻   ┃
        ┃       ┃ + +
        ┗━┓   ┏━┛
          ┃   ┃           
          ┃   ┃ + + + +
          ┃   ┃    Code is far away from bug with the animal protecting       
          ┃   ┃ +     神獸保佑,代碼無bug    ' . date('Y-m-d H:i:s') . '
          ┃   ┃
          ┃   ┃  +         
          ┃    ┗━━━┓ + +
          ┃        ┣┓
          ┃        ┏┛
          ┗┓┓┏━┳┓┏┛ + + + +
           ┃┫┫ ┃┫┫
           ┗┻┛ ┗┻┛+ + + +', "\n\n\n";
        do {
            $username = trim($this->prompt('請醞釀一個用戶名,並在此輸入:'));
            if ($username !== '') {
                break;
            }
            $this->stdout("\n錯誤:用戶名不能為空\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        do {
            $email = trim($this->prompt("請給【{$username}】指定郵箱地址:"));
            if ($email !== '') {
                break;
            }
            $this->stdout("\n錯誤:郵箱地址不能為空\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        do {
            $password = trim($this->prompt("請給【{$username}】設定密碼,密碼不得少於6位:"));
            if ($password !== '') {
                break;
            }
            $this->stdout("\n錯誤:不是給你說了密碼不能少於6位麽?\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        $userModel = new User();
        $userModel->username = $userModel->nickname = $username;
        $userModel->email = $email;
        $userModel->setPassword($password);
        $userModel->generateAuthKey();
        $userModel->status = User::STATUS_ACTIVE;
        echo "\n正在驗證你輸入的數據。。。\n\n";
        if (!$userModel->validate() || !$userModel->save()) {
            $this->stdout("發生了一些錯誤,你要有心理準備。。。\n\n", Console::FG_RED, Console::UNDERLINE);
            sleep(1);
            foreach ($userModel->getErrors() as $errors) {
                foreach ($errors as $error) {
                    echo "    {$error}\n";
                }
            }
            echo "\n";
            return 1;
        }
        echo "哎呀,我成了管理員啦,好緊張好激動啊!\n\n\n";
        return 0;
    }
開發者ID:luobenyu,項目名稱:blog-1,代碼行數:70,代碼來源:InitController.php


注:本文中的common\models\User::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。