本文整理汇总了PHP中UserModel::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserModel::save方法的具体用法?PHP UserModel::save怎么用?PHP UserModel::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserModel
的用法示例。
在下文中一共展示了UserModel::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
function create($name)
{
$this->user->setName($name);
$this->user->set('role', 'user');
$this->user->set('email', $name . '@service.com');
$this->user->save();
return true;
}
示例2: actionRegister
public function actionRegister()
{
$connection = Yii::app()->db;
$email = $_REQUEST['email'];
$password = $_REQUEST['pwd'];
$ret = UserModel::model()->find('email=:email', array(':email' => $email));
if (isset($ret)) {
//email 已经注册
echo json_encode(array('result' => 2, 'comment' => 'Email had been registed'));
return;
}
$userModel = new UserModel();
$userModel->username = 'please set your nickname';
$userModel->password = $password;
$userModel->password2 = $password;
$userModel->email = $email;
$userModel->create_time = time();
if ($userModel->save()) {
//找到名字对应的_id。
$sql = "select _id from tbl_user where email = :email";
$command = $connection->createCommand($sql);
$tmp = $command->query(array(':email' => $email))->readAll();
echo json_encode(array('result' => 1, 'res' => $tmp[0]["_id"]));
} else {
echo json_encode(array('result' => 0));
}
}
示例3: add
function add($user_id, $cause)
{
if (strlen(trim($cause))) {
$userModel = new UserModel();
$currentUser = Project::getUser()->getDbUser();
$userModel->load($user_id);
if ($userModel->id) {
$banHistoryModel = new BanHistoryModel();
$paramModel = new ParamModel();
$n_warnings_to_ban = $paramModel->getParam("UserController", "N_WARNINGS_TO_BAN");
$t_ban_time_sec = $paramModel->getParam("UserController", "T_BAN_TIME_SEC");
$count_user_warnings = $this->getUserWarningCount($user_id);
$this->clear();
$this->user_id = (int) $user_id;
$this->cause = $cause;
$warning_id = $this->save();
if ($userModel->warnings_fromlast_ban + 1 >= $n_warnings_to_ban) {
// пора банить
$subject = "Ваш аккаун заблокирован в системе Next24.ru";
$userModel->warnings_fromlast_ban = 0;
$userModel->banned = 1;
$userModel->banned_date = time();
$banHistoryModel->ban($user_id, $currentUser->id, $warning_id, date("Y-m-d H:i:s", time() + $t_ban_time_sec));
} else {
$userModel->warnings_fromlast_ban = $userModel->warnings_fromlast_ban + 1;
$subject = "Администратор Next24.ru установил Вам предупреждение";
}
$userModel->save();
$url_referer = $_SERVER['HTTP_REFERER'];
$this->sendMessage((int) $user_id, $subject, $cause, $url_referer);
return $warning_id;
}
}
return 0;
}
示例4: execute
/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectContao($output, true);
if ($this->initContao()) {
// Username
if (($username = $input->getArgument('username')) === null) {
$dialog = $this->getHelperSet()->get('dialog');
$username = $dialog->ask($output, '<question>Username:</question>');
}
// Email
if (($email = $input->getArgument('email')) === null) {
$dialog = $this->getHelperSet()->get('dialog');
$email = $dialog->ask($output, '<question>Email:</question>');
}
// Password
if (($password = $input->getArgument('password')) === null) {
$dialog = $this->getHelperSet()->get('dialog');
$password = $dialog->ask($output, '<question>Password:</question>');
}
// Name
if (($name = $input->getArgument('name')) === null) {
$dialog = $this->getHelperSet()->get('dialog');
$name = $dialog->ask($output, '<question>Name:</question>');
}
// create new user
$user = new \UserModel();
$user->setRow(array('username' => $username, 'name' => $name, 'email' => $email, 'password' => \Encryption::hash($password), 'admin' => 1))->save();
$user->save();
$output->writeln('<info>User <comment>' . $username . '</comment> successfully created</info>');
}
}
示例5: actionInsert
public function actionInsert()
{
if (isset($_POST['submit']) && $_POST['submit'] == 'Insert Procuct') {
$pro = new ProModel();
$pro->name = $_POST['product_name'];
$pro->description = $_POST['product_desc'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp, "img/{$product_image}");
$pro->image = $product_image;
$pro->price = $_POST['product_price'];
$pro->save();
header('Location: http://localhost/task/task2/admin_area/index.php');
exit;
}
if (isset($_POST['sub'])) {
$user = new UserModel();
$user->first_name = $_POST['fn'];
$user->last_name = $_POST['ln'];
$user->email = $_POST['em'];
$user->save();
$ord = new OrdersModel();
$ord->user_id = $_POST['id'];
$ord->sum = $_POST['price'];
$ord->order_date = date("Y/m/d h:i:s");
$ord->save();
$ordPro = new OrdersProModel();
$ordPro->order_id = $_POST['id'];
$ordPro->product_id = $_POST['id'];
$ordPro->qty = $_POST['quantity'];
$ordPro->save();
header('Location: http://localhost/task/task2/admin_area/index.php');
exit;
}
}
示例6: signup
/**
* Display listing of the resource
*
* @return Response
*/
public function signup()
{
// obtin data curenta
$today = date("Y-m-d H:i:s");
$userdata = array('givenname' => Input::get('givenname'), 'surname' => Input::get('surname'), 'username' => Input::get('username'), 'email' => Input::get('email'), 'password' => Input::get('password'), 'password_confirmation' => Input::get('password_confirmation'));
//set validation rules
$rules = array('givenname' => 'alpha_num|max:50', 'surname' => 'alpha_num|max:50', 'username' => 'required|unique:users,username|alpha_dash|min:5', 'email' => 'required|unique:users,email|email');
//run validation check
$validator = Validator::make($userdata, $rules);
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
} else {
$user = new UserModel();
$user->givenname = Input::get('givenname');
$user->surname = Input::get('surname');
$user->username = Input::get('username');
$user->email = Input::get('email');
$user->photo = 'No photo found';
$user->password = Hash::make(Input::get('password'));
$user->active = "1";
$user->isdel = "0";
$user->last_login = $today;
$user->access = "User";
$user->save();
}
//else if
return Redirect::to('login')->with('message', FlashMessage::DisplayAlert('User account created', 'success'));
}
示例7: user_model_test
function user_model_test($delete)
{
$user = new UserModel("Not", "Here", "not.here@nowhere.com", "password", date("Y-m-d H:i:s"));
$user->save();
$user->print_fields();
$user->set("failed_login_attempts", 3);
$user->set("first_name", "User");
$user->set("last_name", "McUsage");
$user->save();
$user->print_fields();
if ($delete) {
$user->delete();
}
$um = UserModel::find(UserModel::first()->id);
$um->print_fields();
$um = UserModel::find(UserModel::last()->id);
$um->print_fields();
UserModel::find(999);
}
示例8: createUserModelByUser
public function createUserModelByUser($user)
{
$treeObject = $this->getTree();
$tree = $treeObject->fetchTree();
foreach ($tree as $node) {
$um = new UserModel();
$um->DomainModel = $node;
$um->User = $user;
$um->save();
}
}
示例9: save
public function save($acl = false)
{
$this->removeProperties('actags');
if (parent::save()) {
if ($acl) {
$this->saveACL($acl);
}
return true;
}
return false;
}
示例10: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new UserModel();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['user'])) {
$model->attributes = $_POST['user'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例11: processForm
function processForm()
{
$errors = [];
$errors['count'] = 0;
//form was submitted when $_POST is not empty
if (!empty($_POST)) {
try {
$firstName = Input::getString('first_name');
} catch (Exception $e) {
$errors['first_name'] = 'First Name: ' . $e->getMessage();
$errors['count']++;
}
try {
$lastName = Input::getString('last_name');
} catch (Exception $e) {
$errors['last_name'] = 'Last Name: ' . $e->getMessage();
$errors['count']++;
}
try {
$email = Input::getString('email');
} catch (Exception $e) {
$errors['email'] = 'Email Address: ' . $e->getMessage();
$errors['count']++;
}
try {
if ($_POST['password1'] != $_POST['password2']) {
throw new UnexpectedValueException("Do Not Match!");
}
$passwordOneHashed = Input::getPassword('password1', $firstName, $lastName, $email);
} catch (Exception $e) {
$errors['password1'] = 'Password: ' . $e->getMessage();
$errors['count']++;
}
if ($errors['count'] == 0) {
//no errors - add to the database
$userObject = new UserModel();
$userObject->first_name = $firstName;
$userObject->last_name = $lastName;
$userObject->email = $email;
$userObject->password = $passwordOneHashed;
$userObject->save();
header("Location: /users.show.php?id=" . $userObject->id);
//this will be the $_GET for the users.show.php
die;
}
}
return $errors;
}
示例12: actionForget
public function actionForget()
{
$model = new UserForm('foget');
$msg = '';
if (!empty($_POST['UserForm'])) {
$model->attributes = $_POST['UserForm'];
if ($model->validate()) {
$user = new UserModel();
$user->password = UserModel::model()->cryptPass($pass = UserModel::model()->genPassword());
$user->save();
Yii::app()->email->send($model->email, 'Новый пароль', 'Ваш новый пароль:' . $pass);
$msg = 'Новый пароль отправлен Вам на почту.';
}
}
$this->render('forget', ['model' => $model, 'msg' => $msg]);
}
示例13: signUpAction
public function signUpAction()
{
$form = new SignUpForm();
$this->view->form = $form;
if (isset($_POST)) {
if ($form->isValid($_POST)) {
$user = new UserModel();
$user->populate($_POST);
$user->save();
} else {
foreach ($form->getMessages() as $message) {
$this->flash->error($message);
}
}
// $this->view->disable();
}
}
示例14: register
public function register()
{
$reguser = array('regfirst' => Input::get('regfirst'), 'reglast' => Input::get('reglast'), 'reguser' => Input::get('reguser'), 'password' => Input::get('password'), 'cpassword' => Input::get('cpassword'));
$rules = array('regfirst' => 'alpha_num|max:50', 'reglast' => 'alpha_num|max:50', 'reguser' => 'required|unique:users,username|alpha_num|min:5', 'password' => 'required|alpha_num|between:6,100', 'cpassword' => 'required|alpha_num|between:6,100|same:password');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::Back()->withInput()->withErrors($validator);
} else {
$user = new UserModel();
$user->firstname = Input::get('regfirst');
$user->lastname = Input::get('reglast');
$user->username = Input::get('reguser');
$user->password = Hash::make(Input::get('password'));
$user->roles = Input::get('roles');
$user->save();
}
return Redirect::route('login')->with('flash_notice', 'You are successfully Register.');
}
示例15: actionRegistration
protected static function actionRegistration()
{
if (empty($_POST)) {
self::redirect(App::getLink('Auth'));
}
$errors = array();
if (empty($_POST['name'])) {
$errors['name'] = App::t('Введите имя');
}
if (empty($_POST['email'])) {
$errors['email'] = App::t('Введите email');
} else {
if (!preg_match('/^[-A-Za-z0-9_\\.]+@[-A-Za-z0-9_\\.]+\\.[a-z0-9]{2,4}$/', $_POST['email'])) {
$errors['email'] = App::t('Некорректный email');
}
}
if (empty($_POST['password'])) {
$errors['password'] = App::t('Введите пароль');
} else {
if (empty($_POST['confirm'])) {
$errors['confirm'] = App::t('Введите подтверждение');
} else {
if ($_POST['password'] != $_POST['confirm']) {
$errors['password'] = $errors['confirm'] = App::t('Пароли не совпадают');
}
}
}
if (empty($errors) && UserModel::getByEmail($_POST['email'])) {
$errors['email'] = App::t('Этот email уже используется');
}
if (empty($errors)) {
$user = new UserModel();
$user->name = $_POST['name'];
$user->email = $_POST['email'];
$user->password = md5($_POST['password']);
$user->save();
App::currentUser($user);
self::redirect('/');
}
self::templateVar('registration_errors', $errors);
self::templateVar('post', $_POST);
return self::displayPage('auth');
}