本文整理汇总了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');
}
示例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;
}
}
}
示例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;
}
示例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();
}
示例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']);
}
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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'));
}
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
}
示例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 = 'Агрипина';