本文整理汇总了PHP中Model\User::save方法的典型用法代码示例。如果您正苦于以下问题:PHP User::save方法的具体用法?PHP User::save怎么用?PHP User::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model\User
的用法示例。
在下文中一共展示了User::save方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
public function registerUser()
{
$user = new User();
$user->setEmail($this->request_body->email);
$user->setPassword(md5($this->request_body->password));
$user->save();
$token = new AccessToken();
$token->setTokenContent(uniqid());
$token->setUser($user);
$token->save();
return array('user' => $user->toArray(), 'token' => $token->toArray());
}
示例2: helloMathis
public static function helloMathis($app)
{
$ajout = false;
$username = 'mathis';
$user = User::find($username);
// Si $user n'est pas set, c'est qu'il n'y a rien et on ajoute donc en base !
if (!isset($user)) {
$user = new User();
$user->name = $username;
$user->save();
$ajout = true;
}
$app->render('user.html.twig', array('ajout' => $ajout, 'autre' => 'ahah !', 'name' => $user->name));
}
示例3: homeAction
public function homeAction()
{
$form = new Form\Register($_POST, array('db' => $this->db));
$form_login = new Form\Login($_POST, array('db' => $this->db));
if ($this->method == 'POST' && $form->isValid()) {
$user = new Model\User($form->getValues());
$user->save();
$_SESSION['user_id'] = $user->getPk();
$this->redirect('backoffice');
}
if ($this->method == 'POST' && $form_login->isValid()) {
$_SESSION['user_id'] = $form_login->getValues()['user_id'];
$this->redirect('backoffice');
}
return array('form' => $form, 'form_login' => $form_login);
}
示例4: action_uloginAuth
/**
* gets info from social network. If profile already linked to user authenticates, otherwise create new user instance
* @throws \Kohana_Database_Exception
*/
public function action_uloginAuth()
{
$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
$user = json_decode($s, true);
if (strlen($user['error']) > 0) {
$this->response->body($this->template->fetch('internal.tpl'));
return;
}
$condition = (new \DBCriteria())->addColumnCondition(['uid' => $user['uid'], 'network' => $user['network']]);
/** @var $ULogin \Model\ULogin */
$ULogin = \Model\ULogin::model()->with('user')->find($condition);
if (null === $ULogin) {
\Session::instance()->set('UloginData', $user);
$user['bdate'] = date('Y-m-d', strtotime($user['bdate']));
$user_model = new User();
$user_model->login = $user['login'];
$user_model->first_name = $user['first_name'];
$user_model->email = $user['email'];
$access_level = new \Auth\Access();
$access_level->set(\Auth\Access::User_Login);
$user_model->access_level = $access_level->getValue();
if (!$user_model->save()) {
throw new \Kohana_Database_Exception('Unable to save user model');
}
$ULogin = new ULogin();
$ULogin->network = $user['network'];
$ULogin->uid = $user['uid'];
$ULogin->profile = $user['identity'];
$ULogin->user_id = $user_model->id;
if (!$ULogin->save()) {
$this->response->body('Unable to save social network data');
}
\Auth\Base::startSession($ULogin['user']);
$this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add']));
} else {
\Auth\Base::startSession($ULogin['user']);
$this->redirect(\Route::get('pages')->uri(['controller' => 'Map', 'action' => 'Add']));
}
}
示例5: action_continue
/**
* @throws \Kohana_Database_Exception
*/
public function action_continue()
{
$user = \Session::instance()->get('UloginData');
if (!$user) {
$this->response->body($this->template->fetch('internal.tpl'));
return;
}
$dynamic_salt = \Utils\Math::rand();
$pass = $_POST['password'] . \Cookie::$salt;
$crypted_pass = \Utils\Protect::Crypt($pass, $dynamic_salt);
$user_model = new User();
$user_model->nickname = $_POST['nickname'];
$user_model->first_name = $_POST['first_name'];
$user_model->email = $_POST['email'];
$user_model->salt = $dynamic_salt;
$user_model->pass = $crypted_pass;
$user_model->gender = $_POST['gender'];
$user_model->date_birthday = strtotime($_POST['bdate']);
$user_model->avatar = $_POST['avatar_url'];
//TODO: uploaded file handler
$access_level = new \Auth\Access();
/*Allow user to authenticate*/
$access_level->set(\Auth\Access::User_Login);
$user_model->access_level = $access_level->getValue();
if (!$user_model->save()) {
throw new \Kohana_Database_Exception('Unable to save user model');
}
$ULogin = new ULogin();
$ULogin->network = $user['network'];
$ULogin->uid = $user['identity'];
$ULogin->user_id = $user_model->id;
if (!$ULogin->save()) {
$this->response->body('Unable to save social network data');
} else {
$this->redirect(\Route::get('')->uri());
}
}
示例6: create
/**
* @return bool|int
*/
public static function create($data)
{
$dynamic_salt = Math::rand();
$pass = $data['pass'] . $dynamic_salt;
$crypted_pass = Protect::Crypt($pass, $dynamic_salt);
$user_data = new User();
//$user_data->login = $data['login'];
$user_data->email = $data['email'];
$user_data->first_name = $data['first_name'];
$user_data->phone = $data['phone'];
if ($data['last_name']) {
$user_data->last_name = $data['last_name'];
}
$user_data->pass = $crypted_pass;
$user_data->gender = $data['gender'];
$user_data->date_birthday = strtotime($data['birthday']);
$user_data->salt = $dynamic_salt;
$access_level = new Access();
/*Разрешаем юзверю банально логинится*/
$access_level->set(Access::User_Login);
$user_data->access_level = $access_level->getValue();
if ($user_data->save()) {
return $user_data;
} else {
return false;
}
}
示例7: User
$user2->save();
echo "\n=CREATE=\n\n";
listUsers(User::findAll());
$user2->delete();
echo "\n=DELETE Lucky Luke=\n\n";
listUsers(User::findAll());
$user1->setProp('lastname', 'Vader');
$user1->save();
echo "\n=UPDATE Skywalker -> Vader=\n\n";
listUsers(User::findAll());
$user3 = new User();
$user3->setProp('firstname', 'Darth');
$user3->setProp('lastname', 'Vader');
$user3->setProp('age', 350);
$user3->setProp('date', new \DateTime('2000-01-01 00:00:00'));
$user3->save();
echo "\n=ADD Darth Vader=\n\n";
listUsers(User::findAll());
echo '</pre>';
?>
<br>
<br>
<br>
<div>
<a href="logs/log.sql.txt">sqlLog</a>
</div>
<div>
<a href="logs/log.err.txt">sqlErr</a>
示例8: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param ConnectionInterface $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(ConnectionInterface $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their corresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aUser !== null) {
if ($this->aUser->isModified() || $this->aUser->isNew()) {
$affectedRows += $this->aUser->save($con);
}
$this->setUser($this->aUser);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
$affectedRows += 1;
} else {
$affectedRows += $this->doUpdate($con);
}
$this->resetModified();
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例9: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param ConnectionInterface $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(ConnectionInterface $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their corresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aUser !== null) {
if ($this->aUser->isModified() || $this->aUser->isNew()) {
$affectedRows += $this->aUser->save($con);
}
$this->setUser($this->aUser);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
$affectedRows += 1;
} else {
$affectedRows += $this->doUpdate($con);
}
$this->resetModified();
}
if ($this->ordersScheduledForDeletion !== null) {
if (!$this->ordersScheduledForDeletion->isEmpty()) {
\Model\OrderQuery::create()->filterByPrimaryKeys($this->ordersScheduledForDeletion->getPrimaryKeys(false))->delete($con);
$this->ordersScheduledForDeletion = null;
}
}
if ($this->collOrders !== null) {
foreach ($this->collOrders as $referrerFK) {
if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例10: register
/**
* @JSON
*/
public function register()
{
$result = array('error' => 1, 'message' => '注册失败');
$email = strtolower(trim($_POST['r_email']));
$userName = trim($_POST['r_user_name']);
$passwd = trim($_POST['r_passwd']);
$repasswd = trim($_POST['r_passwd2']);
$inviteCode = trim($_POST['r_invite']);
$invite = Invite::getInviteByInviteCode($inviteCode);
//校验 invite 是否可用
if ($invite->status != 0 || $invite == null || empty($invite)) {
$result['message'] = '邀请码不可用';
} else {
if ($repasswd != $passwd) {
$result['message'] = '两次密码输入不一致';
} else {
if (strlen($passwd) < 6) {
$result['message'] = '密码太短,至少8字符';
} else {
if ($chkEmail = Utils::mailCheck($email)) {
$result['message'] = $chkEmail;
} else {
$user = new User();
$user->email = $email;
if ($userName == null) {
$userName = $email;
}
$userCount = Stats::countUser();
$user->nickname = $userName;
// LEVEL 从数据库中获取
$custom_transfer_level = json_decode(Option::get('custom_transfer_level'), true);
// 定义邀请码套餐与流量单位
$transferNew = Utils::GB * intval($custom_transfer_level[$invite->plan]);
$user->transfer = $transferNew;
$user->invite = $inviteCode;
$user->plan = $invite->plan;
// 将邀请码的账户类型设定到注册用户上.
$user->regDateLine = time();
$user->lastConnTime = $user->regDateLine;
$user->sspwd = Utils::randomChar();
$user->payTime = time();
// 注册时支付时间
$user_test_day = Option::get('user_test_day') ?: 7;
$user->expireTime = time() + 3600 * 24 * intval($user_test_day);
// 到期时间
$mailVerify = Option::get('mail_verify');
// 邮件验证是否开启
if ($userCount > 0 && $mailVerify) {
$user->enable = 0;
// 停止账户
$code = Utils::randomChar(10);
$forgePwdCode['verification'] = $code;
$forgePwdCode['time'] = time();
$user->forgePwdCode = json_encode($forgePwdCode);
$mailer = Mailer::getInstance();
$mailer->toQueue(false);
$mail = new Mail();
$mail->to = $user->email;
$mail->subject = '[' . SITE_NAME . '] 新账户注册邮箱校验';
$mail->content = Option::get('custom_mail_verification_content');
$params = ['code' => $code, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime), 'REGISTER_URL' => base64_encode($user->email . "\t" . $forgePwdCode['verification'] . "\t" . $forgePwdCode['time'])];
$mail->content = Utils::placeholderReplace($mail->content, $params);
$mailer->send($mail);
} else {
$user->enable = 1;
// 第一个账户,默认设定为启用
$user->forgePwdCode = null;
}
$user->port = Utils::getNewPort();
// 端口号
$user->setPassword($passwd);
$user->save();
$invite->reguid = $user->uid;
$invite->regDateLine = $user->regDateLine;
$invite->status = 1;
// -1过期 0-未使用 1-已用
$invite->inviteIp = Utils::getUserIP();
$invite->save();
if (null != $user->uid && 0 != $user->uid) {
$result['error'] = 0;
$result['message'] = '注册成功';
}
if ($mailVerify) {
$result['message'] .= ',您需要验证邮箱后才能使用本站功能。';
}
Logger::getInstance()->info('user [' . $user->email . '] register success');
}
}
}
}
return $result;
}