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


PHP User::validate方法代碼示例

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


在下文中一共展示了User::validate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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()) {
         // print_r($_POST);
         // die();
         $pass = Yii::$app->security->generatePasswordHash($_POST['User']['password']);
         $model->password_hash = $pass;
         $content = '
                 <center><img src="http://i.imgur.com/rkxzCKf.png"/></center><br/>
                 <h4 align="center">Sekolah Tinggi Terpadu Nurul Fikri ' . 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>' . $_POST['User']['password'] . '</b><br/>
                 Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
                 <h5 align="center">Developer By Hendra Aditya Wijaya Mentor Ilham Malik Ibrahim' . 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($_POST['User']['password'])->send();
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
開發者ID:jigunk,項目名稱:yudisium,代碼行數:30,代碼來源:UserController.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(['scenario' => 'signup']);
     $model1 = new AmgenContactListvalidate();
     if ($model->load(Yii::$app->request->post()) && $model1->load(Yii::$app->request->post()) && $model->validate() && $model1->validate()) {
         $fname = $_POST['AmgenContactListvalidate']['first_name'];
         $lname = $_POST['AmgenContactListvalidate']['last_name'];
         $model1->first_name = $fname;
         $model1->last_name = $lname;
         $model1->Title = $_POST['AmgenContactListvalidate']['Title'];
         $model1->function_Id = $_POST['AmgenContactListvalidate']['function_Id'];
         $model1->group_Id = $_POST['AmgenContactListvalidate']['group_Id'];
         $model1->Phone = $_POST['AmgenContactListvalidate']['Phone'];
         $model1->speciality = $_POST['AmgenContactListvalidate']['speciality'];
         $fullname = $fname . " " . $lname;
         $model1->Name = $fullname;
         if ($model1->save()) {
             $id = $model1->id;
             $password = $_POST['User']['password_hash'];
             $hash = Yii::$app->getSecurity()->generatePasswordHash($password);
             $model->password_hash = $hash;
             //generating password hash
             $model->attendee_id = $id;
             $model->first_name = $fname;
             $model->last_name = $lname;
             $model->save();
             Yii::$app->session->setFlash('success', 'User Sucessfully Created');
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'model1' => $model1]);
     }
 }
開發者ID:Rakeshdrupal,項目名稱:yiifirstliveproject,代碼行數:38,代碼來源:UserController.php

示例3: actionRegister

 /**
  * Register billing account
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/site/register<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for registering user.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     name: string, the user name<br/>
  *     email: string, the user email<br/>
  *     password: string, the user password<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     ack: integer, mark the create result, 1 means create successfully, 0 means create fail<br/>
  *     message: string, if create fail, it contains the error message<br/>
  *     data: array, json array to describe all users detail information<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "name" : "harrysun",
  *     "email" : "harrysun1@augmentum.com.cn",
  *     "password" : "abc123_"
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *    'ack' : 1,
  *    'message': ''
  * }
  * </pre>
  */
 public function actionRegister()
 {
     $data = $this->getParams();
     $account = new Account();
     $account->save();
     $user = new User();
     $user->name = $data['name'];
     $user->email = $data['email'];
     $user->salt = StringUtil::rndString(6);
     $user->password = User::encryptPassword($data['password'], $user->salt);
     $user->accountId = $account->_id;
     $user->role = User::ROLE_ADMIN;
     $user->isActivated = User::NOT_ACTIVATED;
     $user->avatar = Yii::$app->params['defaultAvatar'];
     $user->language = 'zh_cn';
     if ($user->validate()) {
         // all inputs are valid
         if ($user->save()) {
             $validation = new Validation();
             $validation->userId = $user->_id;
             $validation->code = StringUtil::uuid();
             $validation->expire = new \MongoDate(strtotime('+1 day'));
             if ($validation->save()) {
                 $mail = Yii::$app->mail;
                 $host = Yii::$app->request->hostInfo;
                 $vars = ['name' => $user->name, 'link' => $host . '/api/old-site/activate?code=' . $validation->code, 'host' => $host];
                 $mail->setView('//mail/register', $vars, '//layouts/email');
                 $mail->sendMail($user->email, '歡迎注冊WeMarketing');
                 return ["ack" => 1, "message" => 'Register success.'];
             } else {
                 return ["ack" => 0, "message" => 'Validation save fail.'];
             }
         } else {
             return ["ack" => 0, "message" => 'Register user fail.'];
         }
     } else {
         // validation failed: $errors is an array containing error messages
         $errors = $user->errors;
         //revert the accout data
         Account::deleteAll(['_id' => $account->_id]);
         return ["ack" => 0, "message" => $errors];
     }
 }
開發者ID:timelessmemory,項目名稱:uhkklp,代碼行數:82,代碼來源:OldSiteController.php

示例4: actionCreateAdmin

 /**
  * 係統初始化,創建管理員
  * 
  * */
 public function actionCreateAdmin()
 {
     $params = Yii::$app->request->post("CreateUser");
     $user_name = empty($params['username']) ? '' : $params['username'];
     $pwd = empty($params['password']) ? '' : $params['password'];
     $confirm_pwd = empty($params['confirmPassword']) ? '' : $params['confirmPassword'];
     $email = empty($params['email']) ? '' : $params['email'];
     $res = new Response();
     if ($pwd != $confirm_pwd) {
         $res->success = false;
         $res->message = '兩次密碼輸入不一樣';
     }
     $is_user = User::find()->all();
     //判斷是否創建過管理員帳號
     if (!empty($is_user)) {
         $res->success = false;
         $res->message = '該係統已經創建過測試帳號';
     }
     $user = new User();
     $user->username = $user_name;
     $user->password_hash = $pwd;
     $user->email = $email;
     if ($user->validate() && $user->save()) {
         $res->success = true;
         $res->message = '創建係統管理員成功';
         //為超級管理員授權
         $auth = Yii::$app->authManager;
         // //創建管理員
         // $role = $auth->createRole('admin');
         // $role->description = '係統管理員';
         // $auth->add($role);
         // $auth->addChild($role, $privileges_manage);
         // $role = $auth->getRole( 'admin' );
         // $auth->assign($role, $user_id);
         if (!$auth->assign($role, $user->user_id)) {
             $res->success = false;
             $res->message = '創建係統管理員權限失敗';
         }
     } else {
         $res->success = false;
         $res->message = '創建係統管理員失敗';
     }
     $res->to_json();
 }
開發者ID:phpsong,項目名稱:DeviceManagementSystem,代碼行數:48,代碼來源:SiteController.php


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