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


PHP User::insert方法代码示例

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


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

示例1: actionRegister

 public function actionRegister()
 {
     if (!Application::$app->getUser()->getIsGuest()) {
         Application::$app->getSession()->setFlash('register-warning', 'You must be unauthorized');
         return $this->redirect('site/index');
     }
     if (!empty($_POST) && (!isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['repeat_password']) || empty($_POST['repeat_password']))) {
         Application::$app->getSession()->setFlash('register-danger', 'Please fill all fields.');
     } elseif (!empty($_POST) && $_POST['password'] !== $_POST['repeat_password']) {
         Application::$app->getSession()->setFlash('register-danger', 'Passwords not match.');
     } elseif (!empty($_POST)) {
         //check email
         $model = User::findIdentityByEmail($_POST['email']);
         if (!empty($model)) {
             Application::$app->getSession()->setFlash('register-danger', 'User with email ' . HtmlPurifier::process($_POST['email']) . ' already registered.');
             return $this->redirect('user/register');
         }
         $model = new User();
         $model->load($_POST);
         $model->insert();
         Application::$app->getSession()->setFlash('register-success', 'User successfully created.');
         return $this->redirect('user/login');
     }
     return $this->render('user/register');
 }
开发者ID:ercling,项目名称:auth,代码行数:25,代码来源:UserController.php

示例2: InsertTestCode

 public function InsertTestCode()
 {
     $user = new User();
     $user->testcode = $this->GetTestCode(4);
     $user->telephone = $this->telephone;
     $isExist = User::find()->where(['telephone' => $user->telephone])->one();
     if (!empty($isExist)) {
         if (empty($isExist->username)) {
             if (User::updateAll(['testcode' => $user->testcode], 'telephone =' . $user->telephone)) {
                 $password = md5("ontee123ontee");
                 $content = urlencode("欢迎您注册ONTEE,您的验证码" . $user->testcode . ",请在10分钟之内输入。【ONTEE】");
                 $time = $this->getMillisecond();
                 $remote_server = "http://api.sms.cn/mt/?uid=ontee&pwd=" . $password . "&mobile=" . $user->telephone . "&mobileids=" . $user->telephone . $time . "&content=" . $content . "&encode=utf8";
                 $data = $this->request_by_curl($remote_server);
                 echo $user->testcode;
             }
         } else {
             echo 0;
         }
     } else {
         if ($user->insert('user', ['testcode', 'telephone'], [$user->testcode, $user->telephone])) {
             $password = md5("ontee123ontee");
             $content = urlencode("欢迎您注册ONTEE,您的验证码" . $user->testcode . ",请在10分钟之内输入。【ONTEE】");
             $time = $this->getMillisecond();
             $remote_server = "http://api.sms.cn/mt/?uid=ontee&pwd=" . $password . "&mobile=" . $user->telephone . "&mobileids=" . $user->telephone . $time . "&content=" . $content . "&encode=utf8";
             $data = $this->request_by_curl($remote_server);
             echo $user->testcode;
         }
     }
 }
开发者ID:xiaojianxin,项目名称:Ontee,代码行数:30,代码来源:RegisterForm.php

示例3: register

 public function register($attributes)
 {
     $fields = ['fb_id' => $attributes['id'], 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1];
     if (ArrayHelper::getValue($attributes, 'first_name', '') != '') {
         $fields['name_first'] = ArrayHelper::getValue($attributes, 'first_name', '');
         $fields['name_last'] = ArrayHelper::getValue($attributes, 'last_name', '');
     } else {
         $fields['name_first'] = $attributes['name'];
     }
     if (ArrayHelper::getValue($attributes, 'fb_link', '') != '') {
         $fields['fb_link'] = $attributes['link'];
     }
     if (ArrayHelper::getValue($attributes, 'fb_link', '') != '') {
         $fields['gender'] = $attributes['gender'] == 'male' ? 1 : 0;
     }
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     if (isset($attributes['email'])) {
         $fields['email'] = $attributes['email'];
         $fields['is_confirm'] = 1;
     }
     $user = User::insert($fields);
     $user->setAvatarFromUrl('https://graph.facebook.com/' . $attributes['id'] . '/picture?type=large', 'jpg');
     return $user;
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:27,代码来源:Facebook.php

示例4: actionMail

 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     $email = strtolower($email);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректная почта');
     }
     if (User::query(['email' => $email])->exists()) {
         return self::jsonErrorId(101, 'Такая почта уже зарегистрирована');
     }
     if (Yii::$app->user->isGuest) {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0, 'name_first' => $name];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user = User::insert($fields);
     } else {
         /** @var \app\models\User $user */
         $user = Yii::$app->user->identity;
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0];
         foreach (Subscribe::$userFieldList as $field) {
             $fields[$field] = 1;
         }
         $user->update($fields);
     }
     $fields = RegistrationDispatcher::add($user->getId());
     \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     return self::jsonSuccess();
 }
开发者ID:Makeyko,项目名称:galaxysss,代码行数:39,代码来源:SubscribeController.php

示例5: saveFBDetails

 public static function saveFBDetails($data)
 {
     if (!User::checkFBUser($data['fb_id'])) {
         User::insert($data);
         Notifier::sendSignupEmail($data['email'], $data['first_name'] . ' ' . $data['last_name']);
     }
 }
开发者ID:reminisense,项目名称:featherq-laravel5,代码行数:7,代码来源:User.php

示例6: create

 function create()
 {
     $input = Request::all();
     $validator = Validator::make($input, array("name" => "required", "email" => "required|email|unique:users", "password" => "required|min:6", "password_again" => "same:password"));
     if ($validator->passes()) {
         User::insert($input);
         return redirect('user/login')->with('info', 'Register success!');
     } else {
         return redirect('user/register')->withErrors($validator);
     }
 }
开发者ID:eimg,项目名称:laravel-example,代码行数:11,代码来源:UserController.php

示例7: register

 public function register($attributes)
 {
     $fields = ['vk_id' => $attributes['uid'], 'name_first' => $attributes['first_name'], 'name_last' => $attributes['last_name'], 'gender' => $attributes['sex'] == 0 ? null : ($attributes['sex'] == 1 ? 0 : 1), 'vk_link' => $attributes['screen_name'], 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'birth_date' => $this->getBirthDate($attributes)];
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     $user = User::insert($fields);
     \Yii::info('$fields: ' . \yii\helpers\VarDumper::dumpAsString($fields), 'gs\\fb_registration');
     $user->setAvatarFromUrl($attributes['photo_200']);
     return $user;
 }
开发者ID:CAPITALOV,项目名称:capitalov,代码行数:12,代码来源:VKontakte.php

示例8: saveUser

 public static function saveUser($data)
 {
     $user = new User();
     $user->username = $data['username'];
     $user->email = $data['email'];
     $user->password = md5($data['password']);
     $user->type_id = $data['type_id'];
     if ($user->insert()) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:Salvadore1987,项目名称:dev.medical.uz,代码行数:13,代码来源:User.php

示例9: create

 public function create(Request $request)
 {
     $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users', 'phone' => 'required|unique:users', 'password' => 'required|same:repassword']);
     if ($validator->fails()) {
         return \Redirect::back()->withErrors($validator)->withInput();
     } else {
         $inputData = $request->only('email', 'password', 'fullname', 'phone', 'role', 'priority');
         $inputData['password'] = Hash::make($inputData['password']);
         if (User::insert($inputData)) {
             return \Redirect::back()->with('responseData', array('statusCode' => 1, 'message' => 'Thêm mới thành công'));
         } else {
             return \Redirect::back()->withInput()->with('responseData', array('statusCode' => 2, 'message' => 'Có lỗi xảy ra, vui lòng thử lại'));
         }
     }
 }
开发者ID:phamnhuson,项目名称:VDNABARCODE,代码行数:15,代码来源:UserController.php

示例10: register

 public function register($attributes)
 {
     $fields = ['fb_id' => $attributes['id'], 'fb_link' => $attributes['link'], 'name_first' => $attributes['first_name'], 'name_last' => $attributes['last_name'], 'gender' => $attributes['gender'] == '' ? null : ($attributes['gender'] == 'male' ? 1 : 0), 'datetime_reg' => gmdate('YmdHis'), 'datetime_activate' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 1];
     // добавляю поля для подписки
     foreach (\app\services\Subscribe::$userFieldList as $field) {
         $fields[$field] = 1;
     }
     if (isset($attributes['email'])) {
         $fields['email'] = $attributes['email'];
     }
     \Yii::info('$fields: ' . \yii\helpers\VarDumper::dumpAsString($fields), 'gs\\fb_registration');
     $user = User::insert($fields);
     $user->setAvatarFromUrl('https://graph.facebook.com/' . $attributes['id'] . '/picture?type=large');
     return $user;
 }
开发者ID:CAPITALOV,项目名称:capitalov,代码行数:15,代码来源:Facebook.php

示例11: actionMail

 /**
  * AJAX
  * Создает подписку для авторизованного или неавторизованного пользователя
  * Высылает письмо подтверждения email
  *
  * @return string json
  *                error
  *                101, 'Такая почта уже зарегистрирована'
  */
 public function actionMail()
 {
     $email = self::getParam('email');
     $name = self::getParam('name');
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return self::jsonErrorId(101, 'Не корректный формат адреса');
     }
     $email = strtolower($email);
     $user = User::find(['email' => $email, 'subscribe_is_tesla' => 1]);
     if ($user) {
         $user->update(['subscribe_is_tesla' => 1]);
     } else {
         $fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'name_first' => $name, 'subscribe_is_tesla' => 1];
         $user = User::insert($fields);
         $fields = RegistrationDispatcher::add($user->getId());
         \cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
     }
     return self::jsonSuccess();
 }
开发者ID:dram1008,项目名称:gleb,代码行数:28,代码来源:SubscribeController.php

示例12: signupAction

 public function signupAction()
 {
     $form = new UserForm($this);
     if ($this->POST) {
         if ($form->validate($_POST)) {
             // Form output
             $data = $form->output;
             // Save user
             $uid = User::insert($data['default']);
             // Get user
             $account = User::get($uid);
             // Set password
             $account->setPassword($data['private']['password']);
             // Notify
             Session::success('Account created!');
             // Redirect
             return $this->_redirect('user/login');
         }
     }
     return get_defined_vars();
 }
开发者ID:rudiedirkx,项目名称:SocialPay,代码行数:21,代码来源:userController.php

示例13: insert

 /**
  * Делает заказ
  *
  * @param  int $id идентификатор генератора
  *
  * @return boolean whether the model passes validation
  */
 public function insert($fieldsCols = null)
 {
     $id = $fieldsCols;
     $request = parent::insert(['beforeInsert' => function ($fields) {
         $fields['email'] = strtolower($fields['email']);
         $fields['datetime'] = time();
         $fields['status'] = \app\models\Request::STATUS_1_WAIT;
         return $fields;
     }]);
     if ($request === false) {
         return false;
     }
     $request['product_id'] = $id;
     $this->email = strtolower($this->email);
     if (!Yii::$app->user->isGuest) {
         $user = Yii::$app->user->identity;
         $request = new \app\models\Request($request);
         $request->update(['user_id' => Yii::$app->user->getId(), 'product_id' => $id]);
         // письмо клиенту
         $result = \cs\Application::mail($user->getEmail(), 'Вы сделали очередной заказ', 'next_request_client', ['user' => $user, 'request' => $request]);
     } else {
         $fields = ['email' => $this->email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 1, 'is_confirm' => 0, 'subscribe_is_tesla' => 1, 'name_first' => $this->name, 'phone' => $this->phone];
         $user = User::insert($fields);
         $fields = \app\services\RegistrationDispatcher::add($user->getId());
         $request = new \app\models\Request($request);
         $request->update(['user_id' => $user->getId(), 'product_id' => $id]);
         // письмо им
         \cs\Application::mail($this->email, 'Поздравляем вы сделали первый шаг к своему полю коллективного счастья', 'new_request_client', ['url' => Url::to(['site/activate', 'code' => $fields['code']], true), 'user' => $user, 'request' => $request]);
     }
     foreach (\Yii::$app->params['requestMailList'] as $item) {
         // письмо нам
         $result = Application::mail($item, 'Появился заказ на TeslaGen', 'new_request', ['request' => $request, 'user' => $user]);
         //            VarDumper::dump([$result,$item]);
     }
     return $request;
 }
开发者ID:dram1008,项目名称:bogdan,代码行数:43,代码来源:Request.php

示例14: postRegister

 /**
  * Registration process
  */
 public function postRegister()
 {
     //Form not valid
     $validator = true;
     //Error messages
     $data['register_error_messages'] = [];
     //Username
     if (!isset($_POST['username']) || $_POST['username'] == '') {
         //Set error message for registration form username
         $data['register_error_messages']['username'] = 'Username is required!';
         //Validator is false
         $validator = false;
     }
     if (!isset($_POST['password']) || $_POST['password'] == '') {
         //Set error message for registration form password
         $data['register_error_messages']['password'] = 'Password is required!';
         //Validator is false
         $validator = false;
     }
     if (!isset($_POST['email']) || $_POST['email'] == '') {
         //Set error message for registration form email
         $data['register_error_messages']['email'] = 'E-mail is required!';
         //Validator is false
         $validator = false;
     }
     //If form is valid the continue processing
     if ($validator) {
         //Create new user model
         $user = new User();
         //Create new hash
         $hash = new Hash();
         //Get user data
         $data = ['username' => $_POST['username'], 'password' => $hash->make($_POST['password']), 'email' => $_POST['email'], 'created_at' => date('Y-m-d H:i:s')];
         //Send data to database
         $results = $user->insert($data);
         if ($results) {
             //Set success message
             $data['alert_msg'] = 'Your account has been created';
             //Reload page
             view('login-register', $data);
         } else {
             //Set error message
             $data['alert_msg'] = 'Your Could not be created';
             //Reload page
             view('login-register', $data);
         }
     } else {
         //Form is not valid
         view('login-register', $data);
     }
 }
开发者ID:AshniSukhoo,项目名称:blog,代码行数:54,代码来源:AuthController.php

示例15: User

<?php

/**
 * Тестирование ActiveRecord
 */
//use App\Db;
use App\Models\User;
require_once __DIR__ . '/../../index.php';
/**
 * Тестирование метода insert() в классе Model
 */
$user = new User();
$user->name = 'Андрей';
$user->email = 'a@vasnecov.ru';
echo 'Добавили: ' . $user->insert() . '<br>';
echo 'id новой записи: ' . $user->id;
echo '<hr>';
/**
 * Тестирование метода update() в классе Model
 */
$id = 2;
$user = App\Models\User::findById($id);
$user->name = 'Светлана';
$user->email = 's@sss.ru';
echo 'Изменена ли запись с id=' . $id . ': ' . $user->update();
echo '<hr>';
/**
 * Тестирование метода save() в классе Model => вызов insert()
 */
$user = new User();
$user->name = 'Агрипина';
开发者ID:webmaza75,项目名称:php2,代码行数:31,代码来源:test_active_record.php


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