当前位置: 首页>>代码示例>>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;未经允许,请勿转载。