本文整理汇总了PHP中Users::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::save方法的具体用法?PHP Users::save怎么用?PHP Users::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Users
的用法示例。
在下文中一共展示了Users::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register()
{
$user = new Users();
$user->attributes = $this->attributes;
$salt = md5(uniqid() . time());
$user->email = $this->email;
$user->salt = $salt;
$user->pass = crypt(trim($this->pass) . $salt);
if ($user->validate() && $user->save()) {
if (!Settings::model()->getValue('mail_confirm')) {
$user->status = 1;
$user->save();
return 1;
}
Yii::import('ext.YiiMailer.YiiMailer');
$code = md5(md5($user->pass . $user->email));
$mail = new YiiMailer();
$mail->setFrom(Settings::model()->getValue('register'));
$mail->setTo($user->email);
$mail->setSubject(Yii::t('register', 'Account activation'));
$mail->setBody(Yii::t('register', "Hello {nick},<br/><br/>Your activation code: {code}<br/>{link}", array('{nick}' => $user->nick, '{code}' => $code, '{link}' => Yii::app()->createAbsoluteUrl('site/confirm', array('user' => $user->nick, 'code' => $code)))));
$mail->send();
return 1;
}
}
示例2: sendEmail
public function sendEmail()
{
$this->user_model->password_reset_code = Common::generateSalt();
$this->user_model->password_reset_request_date = date('Y-m-d H:i:s');
$this->user_model->save(false);
$template = SettingsEmailTemplate::model()->getRow('*', '`key`=:t1', array(':t1' => SettingsEmailTemplate::KEY_FORGOT_PASSWORD));
if (empty($template)) {
return FALSE;
}
//placeholders : {name},{link}
$body = Common::myStringReplace($template['body'], array('{name}' => Person::model()->get($this->user_model->id, 'CONCAT(first_name," ",last_name)'), '{link}' => Yii::app()->createAbsoluteUrl('auth/default/resetPassword', array('id' => $this->user_model->id, 'token' => $this->user_model->password_reset_code))));
//$from, $this->user_model->email, $template->title, $template->body, true
MsgEmailOutbox::model()->push(array('from_name' => Yii::app()->settings->get(Constants::CATEGORY_GENERAL, Constants::KEY_SITE_NAME, Yii::app()->name), 'from_email' => $template['from'], 'to_email' => $this->user_model->email, 'subject' => $template['subject'], 'message' => $body));
}
示例3: actionCreate
public function actionCreate()
{
$model = new Users();
if (isset($_POST) && !empty($_POST)) {
foreach ($_POST as $k => $v) {
// if ($k == "password") {
// $crypt = new bCrypt();
// $v = $crypt->hash($v);
// }
$_POST['Users'][$k] = $v;
}
$model->attributes = $_POST['Users'];
$msg = "User gagal disimpan";
if ($model->save()) {
$status = true;
$msg = "User berhasil di simpan dengan id " . $model->id;
} else {
$status = false;
}
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('success' => $status, 'msg' => $msg));
Yii::app()->end();
} else {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例4: actionCreate
public function actionCreate($id = '')
{
if ($id) {
$this->checkPower('updateUser');
$model = Users::model()->findByPk($id);
if (!$model) {
$this->message(0, '您所编辑的用户不存在');
}
$isNew = false;
} else {
$this->checkPower('addUser');
$model = new Users();
$isNew = true;
}
if (isset($_POST['Users'])) {
if ($isNew || md5($_POST['Users']['password']) != $model->password) {
$_POST['Users']['password'] = md5($_POST['Users']['password']);
}
$model->attributes = $_POST['Users'];
if ($model->save()) {
$this->redirect(array('users/index'));
}
}
$this->render('create', array('model' => $model));
}
示例5: setCookie
private function setCookie(Users $user)
{
$token = SecurityFacade::getToken();
$user->save(['remember_token' => $token]);
setcookie('auth[email]', CryptFacade::encrypt($user->email), Carbon::now()->addDay(15)->timestamp);
setcookie('auth[token]', CryptFacade::encrypt($token), Carbon::now()->addDay(15)->timestamp);
}
示例6: actionCreateUser
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'index' page.
*/
public function actionCreateUser()
{
Yii::log("actionCreate called", "trace", self::LOG_CAT);
$cancelLink = $this->createUrl('site/login');
$model = new Users();
if (isset($_POST['Users'])) {
$model->attributes = $_POST['Users'];
$model->roles = $_POST['Users']['roles'];
if ($model->validate("insert")) {
if ($model->save() && $model->saveRoles($model->userId, "create")) {
// send the user the email link:
$toMailName = $model->userName;
$email = $model->email;
// construct data and set expiry to 24 hrs
$resetEncrypt = base64_encode($email . ",resetTrue," . (strtotime(date("H:i:s")) + 86400));
$passwordUrl = "http://" . $_SERVER["HTTP_HOST"] . Yii::app()->request->baseUrl . "/index.php/site/changepassword?data={$resetEncrypt}" . "&redirect_uri=" . $cancelLink;
$mail = new TTMailer();
$subject = Yii::t('translation', 'User created');
$altBody = Yii::t('translation', 'To view the message, please use an HTML compatible email viewer!');
$message = Yii::t('translation', 'Dear ') . $toMailName . ',<br /><br />' . Yii::t('translation', 'your user account has been created, please visit ');
$message .= '<a href="' . $passwordUrl . '">' . $passwordUrl . '</a>' . Yii::t('translation', ' to activate it and set a new password. ') . '<p></p>' . Yii::t('translation', 'This message was automatically generated.') . '<br />' . Yii::t('translation', ' If you think it was sent incorrectly, ') . Yii::t('translation', 'please contact your administrator.');
//if mail is not sent successfully issue appropriate message
if (!$mail->ttSendMail($subject, $altBody, $message, $email, $toMailName)) {
Yii::log("Error in sending the password to the user", "error", self::LOG_CAT);
$msg = Yii::t('translation', "Error in sending the password to the user");
return $msg;
}
Yii::app()->user->setFlash('success', "User successfully created.");
$this->redirect(array('users/index'));
}
}
}
$this->render('create', array('model' => $model));
}
示例7: indexAction
public function indexAction()
{
if ($this->request->isPost()) {
$username = $this->request->getPost('username', 'alphanum');
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$name = $this->request->getPost('name');
$phone = $this->request->getPost('phone');
$user = new Users();
$user->username = $username;
$user->email = $email;
$user->password = sha1($password);
$user->name = $name;
$user->created_at = new Phalcon\Db\RawValue('now()');
$user->active = 'Y';
$user->class = '1';
$user->phone = $phone;
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->tag->setDefault('email', '');
$this->tag->setDefault('password', '');
$this->flash->success('Спасибо за регистрацию, пожалуйста войдите в вашу учетную запись');
return $this->view->pick("login/index");
}
}
}
示例8: registerAction
public function registerAction()
{
if ($this->request->isPost()) {
$name = $this->request->getPost('name', 'string');
$username = $this->request->getPost('username', 'string');
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$repeatPassword = $this->request->getPost('repeatPassword');
if ($password != $repeatPassword) {
Flash::error((string) $message, 'alert alert-error');
return false;
}
$name = strip_tags($name);
$username = strip_tags($username);
$user = new Users();
$user->username = $username;
$user->password = sha1($password);
$user->name = $name;
$user->email = $email;
$user->created_at = new Phalcon_Db_RawValue('now()');
$user->active = 'Y';
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
Flash::error((string) $message, 'alert alert-error');
}
} else {
Tag::setDefault('email', '');
Tag::setDefault('password', '');
Flash::success('Thanks for sign-up, please log-in to start generating invoices', 'alert alert-success');
return $this->_forward('session/index');
}
}
}
示例9: indexAction
/**
* Action to register a new user
*/
public function indexAction()
{
$form = new RegisterForm();
if ($this->request->isPost()) {
$name = $this->request->getPost('name', array('string', 'striptags'));
$username = $this->request->getPost('username', 'alphanum');
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$repeatPassword = $this->request->getPost('repeatPassword');
if ($password != $repeatPassword) {
$this->flash->error('Passwords are different');
return false;
}
$user = new Users();
$user->username = $username;
$user->password = sha1($password);
$user->name = $name;
$user->email = $email;
$user->created_at = new Phalcon\Db\RawValue('now()');
$user->active = 'Y';
$user->key = md5($email);
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->tag->setDefault('email', '');
$this->tag->setDefault('password', '');
$this->flash->success('Спасибо за регисрация. Пожалуйста залогинтесь для использования API');
return $this->forward('session/index');
}
}
$this->view->form = $form;
}
示例10: add
public function add($phone, $addate)
{
$bean = new Users();
$bean->user_name = $phone;
$bean->addate = $addate;
return $bean->save();
}
示例11: signupAction
/**
* [POST]アカウントの登録メゾット
*
* Endpoint POST /auth/signup
*
* @access public
* @return JSON Responce
*/
public function signupAction()
{
$post = ['name' => true, 'password' => true, 'screen_name' => true, 'other_profile' => false];
if ($this->_getPost($post)) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 201;
$this->_status['response']['detail'] = $post['empty'];
}
if ($this->_status['response']['status'] && !$this->_checkName($this->_post['name'], $detail)) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 205;
$this->_status['response']['detail'] = $detail;
}
if (!$this->_status['response']['status']) {
return $this->response->setJsonContent($this->_status);
}
$profile = empty($this->_post['other_profile']) ? serialize([]) : serialize(json_decode($this->_post['other_profile'], true));
$users = new Users();
$users->assign(['name' => $this->_post['name'], 'password' => $this->security->hash($this->_post['password']), 'screen_name' => $this->_post['screen_name'], 'other_profile' => $profile]);
if (!$users->save()) {
$this->_status['response']['status'] = false;
$this->_status['response']['code'] = 102;
return $this->response->setJsonContent($this->_status);
}
return $this->response->setJsonContent($this->_status);
}
示例12: loginFbAction
public function loginFbAction()
{
$response = new ApiResponse();
if ($this->request->isPost()) {
$fbId = $this->request->getPost('fbId');
$username = $this->request->getPost('username');
$email = $this->request->getPost('email');
$avatar = $this->request->getPost('avatar');
$user = Users::findFirstByFbId($fbId);
if ($user == true) {
$response->setResponseMessage('Login successfully!');
return $response;
} else {
$user = new Users();
$user->id = uniqid();
$user->fbId = $fbId;
$user->avatar = $avatar;
$user->username = $username;
$user->email = $email;
try {
if ($user->save() == false) {
$response->setResponseError(implode(', ', $user->getMessages()));
} else {
$response->setResponseMessage('Register successfully!');
}
} catch (PDOException $e) {
$response->setResponseError($e->getMessage());
}
}
} else {
$response->setResponseError('Wrong HTTP Method');
}
return $response;
}
示例13: actionRegister
public function actionRegister()
{
if (!Yii::app()->user->isGuest) {
$this->redirect(array('site/index'));
}
$model = new Users();
if (isset($_POST['Users'])) {
$model->CreatedDate = date('Y-m-d H:i:s');
$model->UserId = $this->getRandomNumber();
$model->ActivationCode = $this->generateRandomString(15);
$model->attributes = $_POST['Users'];
if ($model->save()) {
$message = Messages::model()->mailHeader();
$message .= '<p>Dear ' . $model->UserName . '</p>';
$message .= 'Thank you for registering with Getweiss.com';
$message .= '<p>Please click the link below to activate your account</p>';
$message .= '<p><a style="color:#FFF; text-decoration:none" href="' . Yii::app()->getBaseUrl(true) . '/site/activate/?ac=' . $model->ActivationCode . '">' . Yii::app()->getBaseUrl(true) . '/site/activate/?ac=' . $model->ActivationCode . '</a></p>';
$message .= 'Regards<br/>Getweiss.com.';
$message .= Messages::model()->mailFooter();
// Messages::model()->sendMail('Get Weiss', 'Activation', Yii::app()->params['adminEmail'], $model->EmailAddress, $message);
$adminmessage = Messages::model()->mailHeader();
$adminmessage .= 'New User Registered in Getweiss.com';
$adminmessage .= '<p><u>Name</u>: ' . $model->UserName . '</p>';
$adminmessage .= '<p><u>Email</u>: ' . $model->EmailAddress . '</p>';
$adminmessage .= Messages::model()->mailFooter();
//Messages::model()->sendMail($model->UserName, 'New User Registration', $model->EmailAddress, Yii::app()->params['adminEmail'], $adminmessage);
$this->redirect(array('index', 'msg' => 'success'));
}
}
$this->render('index', array('model' => $model));
}
示例14: register
/**
* 注册方法
* 完成数据的插入
* @return boolean whether register is successful
*/
public function register()
{
//将已经验证成功的数据插入数据库
if (!$this->hasErrors()) {
$user = new Users();
$user->username = $this->username;
$user->email = $this->email;
$user->salt = Help::fetchSalt();
$user->password = md5(md5($this->password) . $user->salt);
$user->reg_ip = Yii::app()->request->userHostAddress;
$user->last_ip = Yii::app()->request->userHostAddress;
$user->reg_time = time();
$user->last_login = time();
if (!$user->save()) {
return false;
}
}
//实行登入操作
if ($this->_identity === null) {
$this->_identity = new UserIdentity($this->email, $this->password);
$this->_identity->authenticate();
}
if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
Yii::app()->user->login($this->_identity);
return true;
} else {
return false;
}
}
示例15: 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 PropelPDO $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(PropelPDO $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 coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aUsers !== null) {
if ($this->aUsers->isModified() || $this->aUsers->isNew()) {
$affectedRows += $this->aUsers->save($con);
}
$this->setUsers($this->aUsers);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = UserInformationPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setNew(false);
} else {
$affectedRows += UserInformationPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
$this->alreadyInSave = false;
}
return $affectedRows;
}