本文整理汇总了PHP中user::save方法的典型用法代码示例。如果您正苦于以下问题:PHP user::save方法的具体用法?PHP user::save怎么用?PHP user::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user
的用法示例。
在下文中一共展示了user::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_coursepermissions
/**
* Test for correct assignment of course permissions
*/
public function test_coursepermissions()
{
global $DB, $CFG, $USER;
accesslib_clear_all_caches(true);
set_config('siteguest', '');
set_config('siteadmins', '');
$this->assertFalse($this->has_program_create_capability());
$this->assertFalse($this->has_associate_and_manage_capability());
$this->assertFalse($this->has_program_view_capability());
$syscontext = context_system::instance();
$assigninguser = new user(array('idnumber' => 'testuserid', 'username' => 'testuser', 'firstname' => 'testuser', 'lastname' => 'testuser', 'email' => 'testuser@testuserdomain.com', 'country' => 'CA'));
$assigninguser->save();
$roleid = create_role('userrole', 'userrole', 'userrole');
$usr = $DB->get_record('user', array('username' => 'testuser'));
$this->setUser($usr);
$USER = $usr;
assign_capability('local/elisprogram:associate', CAP_ALLOW, $roleid, $syscontext->id);
assign_capability('local/elisprogram:manage', CAP_ALLOW, $roleid, $syscontext->id);
assign_capability('local/elisprogram:program_create', CAP_ALLOW, $roleid, $syscontext->id);
assign_capability('local/elisprogram:program_enrol', CAP_ALLOW, $roleid, $syscontext->id);
assign_capability('local/elisprogram:program_view', CAP_ALLOW, $roleid, $syscontext->id);
role_assign($roleid, $usr->id, $syscontext->id);
$this->assertTrue($this->has_program_create_capability());
$this->assertTrue($this->has_associate_and_manage_capability());
$this->assertTrue($this->has_program_view_capability());
$this->setUser(null);
}
示例2: test_student_save_nouserobject
/**
* Test student save works when $USER object not set
*/
public function test_student_save_nouserobject()
{
global $DB, $USER;
// Create Moodle course category.
$crscat = create_course_category((object) array('name' => 'Test Course category', 'idnumber' => 'MCC-1'));
// Create Moodle course.
$crsdata = array('category' => $crscat->id, 'fullname' => 'MC-TEST-ELIS-8484', 'shortname' => 'MC-TEST-ELIS-8484', 'idnumber' => 'MC-TEST-ELIS-8484');
$mdlcrs = new stdClass();
$mdlcrs->id = $DB->insert_record('course', (object) $crsdata);
$cddata = array('name' => 'CD-ELIS-8484', 'code' => 'CD-ELIS-8484', 'idnumber' => 'CD-ELIS-8484', 'syllabus' => 'syllabus');
$cd = new course($cddata);
$cd->save();
$ci = new pmclass(array('idnumber' => 'CI-ELIS-8484', 'courseid' => $cd->id, 'moodlecourseid' => $mdlcrs->id, 'autocreate' => 0));
$ci->save();
$testuser = new user(array('idnumber' => 'testuserelis8484', 'username' => 'testuserelis8484', 'firstname' => 'Test', 'lastname' => 'User-ELIS8484', 'email' => 'tu8484@noreply.com', 'city' => 'Waterloo', 'country' => 'CA'));
$testuser->save();
$USER = null;
$sturec = new stdClass();
$sturec->userid = $testuser->id;
$sturec->classid = $ci->id;
$sturec->grade = 0;
$sturec->enrolmenttime = time();
$student = new student($sturec);
$student->save();
$this->assertFalse(empty($student));
if (!empty($student)) {
$this->assertFalse(empty($student->id));
}
}
示例3: hasPasswordExpired
function hasPasswordExpired($username)
{
// if ($syst_generated_pwd == '0'){
// $type='syst';
// }else{
$type = 'user';
// }
$current_user = new user();
$usr_id = $current_user->retrieve_user_id($username);
$current_user->retrieve($usr_id);
if ($current_user->portal_only == '0') {
global $mod_strings;
$res = $GLOBALS['sugar_config']['passwordsetting'];
if ($res[$type . 'expiration'] == '1') {
global $timedate;
if ($current_user->pwd_last_changed == '') {
$current_user->pwd_last_changed = $timedate->to_display_date_time(gmdate($GLOBALS['timedate']->get_db_date_time_format()));
$current_user->save();
}
$expireday = $res[$type . 'expirationtype'] * $res[$type . 'expirationtime'];
$stim = strtotime($current_user->pwd_last_changed);
//add day to timestamp
$expiretime = date("Y-m-d H:i:s", mktime(date("H", $stim), date("i", $stim), date("s", $stim), date("m", $stim), date("d", $stim) + $expireday, date("Y", $stim)));
$timenow = $timedate->to_display_date_time(gmdate($GLOBALS['timedate']->get_db_date_time_format()));
if ($timenow < $expiretime) {
return false;
} else {
$_SESSION['expiration_type'] = $mod_strings['LBL_PASSWORD_EXPIRATION_TIME'];
return true;
}
}
if ($res[$type . 'expiration'] == '2') {
$login = $current_user->getPreference('loginexpiration');
$current_user->setPreference('loginexpiration', $login + 1);
$current_user->save();
if ($login >= $res[$type . 'expirationlogin']) {
$_SESSION['expiration_type'] = $mod_strings['LBL_PASSWORD_EXPIRATION_LOGIN'];
return true;
} else {
return false;
}
}
if ($res[$type . 'expiration'] == '0') {
return false;
}
}
}
示例4: create_test_user
/**
* Create a test user record
*
* @return int The id of the user record
*/
private function create_test_user()
{
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/data/user.class.php';
$user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'country' => 'CA'));
$user->save();
return $user->id;
}
示例5: approve
function approve($id)
{
if ($_POST) {
$users = new user($id);
$users->from_array($_POST);
$users->save();
}
}
示例6: actionCreate
/**
* Creates a new user model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new user();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例7: setUp
/**
* Create user for testing
*/
public function setUp()
{
parent::setUp();
$user = new user();
$user->id = -1;
$user->mail = 'unittesting@unittesting.com';
$user->save();
$this->user = $user;
$this->be($user);
}
示例8: newUser
function newUser($validator)
{
$email = $validator->getVar("email");
$q = Doctrine_Query::create()->from('user u')->where("u.email='{$email}'");
$rows = $q->execute();
$random = rand(0, 999999999);
if (count($rows) == 0) {
$random = rand(0, 999999999);
$entity = new user();
$entity->email = $email;
$entity->password = $validator->getVar("password");
$entity->validation_code = $random;
$entity->save();
} else {
$validator->addError('The user "' . $email . '" already exists.');
}
$idUsuario = mysql_insert_id();
if ($validator->getTotalErrors() == 0) {
require_once 'phputils/class.phpmailer.php';
try {
$mail = new PHPMailer(true);
//New instance, with exceptions enabled
//$body = file_get_contents('contents.html');
$body = 'Hi ' . $email . ', Welcome!, your validation code is ' . $random . '. Before you can log into the system you must click on the following link: ' . $GLOBALS["baseURL"] . 'crud.php?public_action=validate&a=' . $random . '&b=' . $entity->id;
$body = preg_replace('/\\\\/', '', $body);
//Strip backslashes
//$mail->IsSMTP(); // tell the class to use SMTP
//$mail->SMTPAuth = true; // enable SMTP authentication
//$mail->Port = 587; // set the SMTP server port
//$mail->Host = "smtp.gmail.com"; // SMTP server
//$mail->Username = "email@gmail.com"; // SMTP server username
//$mail->Password = ""; // SMTP server password
//$mail->IsSendmail(); // tell the class to use Sendmail
//$mail->AddReplyTo("email@domain.com","domain.com");
$mail->From = "no-reply@domain.com";
$mail->FromName = "Domain.com";
$mail->AddBCC($email);
$mail->Subject = "Domain.com Registration";
$mail->AltBody = 'Hi ' . $email . ', welcome!, your validation code is ' . $random . '. Before you can log into the system you must copy the following link into you browser: ' . $GLOBALS["baseURL"] . 'crud.php?public_action=validate&a=' . $random . '&b=' . $entity->id;
$mail->WordWrap = 80;
// set word wrap
$mail->MsgHTML($body);
$mail->IsHTML(true);
// send as HTML
$mail->Send();
$_SESSION['user']->status = 'pending';
$_SESSION['user']->name = $email;
} catch (phpmailerException $e) {
//$validator->addError("PHPMailer:".$e->errorMessage());
}
}
return 'controller.php?view=validate';
}
示例9: test_block_elisadmin_load_menu_children_course
/**
* Test block_elisadmin_load_menu_children_course function.
*/
public function test_block_elisadmin_load_menu_children_course()
{
global $DB, $USER;
accesslib_clear_all_caches(true);
// Create test user - ensure the returned user is NOT a site admin. if they are, our capability restrictions won't work.
$testuser = new user();
$testuser->username = 'testELIS4093';
$testuser->idnumber = 'testELIS4093';
$testuser->firstname = 'testELIS4093';
$testuser->lastname = 'testELIS4093';
$testuser->email = 'testELIS4093@example.com';
$testuser->country = 'CA';
$testuser->save();
$testmuser = $testuser->get_moodleuser();
// Create role with cap: 'local/elisprogram:class_view'.
$testrole = new stdClass();
$testrole->name = 'ELIS Class View';
$testrole->shortname = '_test_ELIS_4093';
$testrole->description = 'ELIS Class View';
$testrole->archetype = '';
$testrole->id = create_role($testrole->name, $testrole->shortname, $testrole->description, $testrole->archetype);
// Ensure our new role is assignable to ELIS class contexts.
set_role_contextlevels($testrole->id, array(CONTEXT_ELIS_CLASS));
// Ensure the role has our required capability assigned.
$sitecontext = context_system::instance();
assign_capability('local/elisprogram:class_view', CAP_ALLOW, $testrole->id, $sitecontext->id, true);
$sitecontext->mark_dirty();
// Create ELIS Course Description.
$testcrs = new course(array('name' => 'CD-ELIS-4093', 'idnumber' => 'CDELIS4093', 'syllabus' => ''));
$testcrs->save();
$testcrs->load();
// Create three(3) Class Instances for Course Descrption.
$testcls1 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.1'));
$testcls1->save();
$testcls1->load();
$testcls2 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.2'));
$testcls2->save();
$testcls2->load();
$testcls3 = new pmclass(array('courseid' => $testcrs->id, 'idnumber' => 'CI_ELIS_4093.3'));
$testcls3->save();
$testcls3->load();
// Assign testuser new role in one Class Instance.
$context = \local_elisprogram\context\pmclass::instance($testcls2->id);
role_assign($testrole->id, $testmuser->id, $context->id);
// Switch to testuser.
$USER = $testmuser;
$this->setUser($testmuser);
$items = block_elisadmin_load_menu_children_course($testcrs->id, 0, 0, 5, '');
$this->assertEquals(1, count($items));
$this->assertTrue($items[0]->name == 'pmclass_2');
}
示例10: getUserFromDatabase
/**
* Retourne les données de l'utilisateur depuis la base de données.
* L'utilisateur sera créé s'il n'existe pas.
* @return User
*/
public function getUserFromDatabase()
{
$user = Doctrine::getTable('user')->retrieveByLdapId($this->getProfileVar(sfConfig::get('app_profile_var_translation_uid')));
if ($user === null) {
// L'utilisateur se connecte pour la première fois
$user = new user();
$user->setLdapId($this->getProfileVar(sfConfig::get('app_profile_var_translation_uid')));
$user->setName($this->getProfileVar(sfConfig::get('app_profile_var_translation_name')));
$user->setSurname($this->getProfileVar(sfConfig::get('app_profile_var_translation_surname')));
$user->setMail($this->getProfileVar(sfConfig::get('app_profile_var_translation_mail')));
$user->save();
}
return $user;
}
示例11: check_and_save
public static function check_and_save($session_id, $user_id, $username, $password)
{
$session = session::get_session($session_id);
if ($session != null && $session->is_valid()) {
$user = ormlib::get_from_instance(new user(), array("id"), array($session->user_id));
if ($user->has_group(session::GROUP_METADATA) === true) {
if ($username != "" && $password != "") {
user::save($user_id, $username, $password);
return array("response" => "OK");
} else {
return array("response" => "error", "message" => "name or password is empty");
}
}
}
return array("response" => "error", "message" => "no privileg");
}
示例12: test_user_sync_on_pm_user_create
/**
* Validate that appropriate fields are synched over to Moodle when PM user is enrolled in a class instance during an import.
*/
public function test_user_sync_on_pm_user_create()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elispm::lib('data/classmoodlecourse.class.php');
require_once elispm::lib('data/course.class.php');
require_once elispm::lib('data/pmclass.class.php');
require_once elispm::lib('data/user.class.php');
// Configure the elis enrolment plugin.
$roleid = $DB->get_field('role', 'id', array(), IGNORE_MULTIPLE);
set_config('roleid', $roleid, 'enrol_elis');
$user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'test@useremail.com', 'country' => 'CA'));
$user->save();
$course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
$course->save();
$class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
$class->save();
$category = new stdClass();
$category->name = 'testcategoryname';
$category->id = $DB->insert_record('course_categories', $category);
// Create the associated context.
context_coursecat::instance($category->id);
$mdlcourse = new stdClass();
$mdlcourse->category = $category->id;
$mdlcourse->fullname = 'testcoursefullname';
$mdlcourse = create_course($mdlcourse);
// Associate class instance to Moodle course.
$classmoodlecourse = new classmoodlecourse(array('classid' => $class->id, 'moodlecourseid' => $mdlcourse->id));
$classmoodlecourse->save();
// Run the enrolment create action.
$record = new stdClass();
$record->context = 'class_testclassidnumber';
$record->user_username = 'testuserusername';
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->class_enrolment_create($record, 'bogus', 'testclassidnumber');
// Validate the enrolment.
$enrolid = $DB->get_field('enrol', 'id', array('enrol' => 'elis', 'courseid' => $mdlcourse->id));
$this->assertNotEquals(false, $enrolid);
$mdluserid = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
$this->assertNotEquals(false, $mdluserid);
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid' => $enrolid, 'userid' => $mdluserid)));
// Validate the role assignment.
$mdlcoursecontext = context_course::instance($mdlcourse->id);
$this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $roleid, 'contextid' => $mdlcoursecontext->id, 'userid' => $mdluserid)));
}
示例13: register_action
function register_action()
{
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$cnf_password = isset($_POST['confirm_password']) ? $_POST['confirm_password'] : '';
if ($name != '' || $email != '' || $password != '') {
$user = new user($name, $email, $password);
if ($user->save()) {
// it successfully saved the user data
header("HTTP/1.1 200 ok");
header("Location: " . "http://" . HOST . '/' . APPLICATION . '/index.php?page=login');
} else {
header("HTTP/1.1 400 Invalid input");
header("Location: " . "http://" . HOST . 'index.php?page=register');
}
}
}
示例14: action_signup
/**
* авторизует пользователя
* если такого пользователя нет, то создает его
*/
public function action_signup()
{
try {
if (empty($_REQUEST['email']) || empty($_REQUEST['username'])) {
throw new Exception('Все поля должны быть заполнены.');
}
$user = user::find_by_email($_REQUEST['email']);
if ($user != null) {
throw new Exception('Пользователь с таким электронным адресом уже зарегистирован.');
}
$user = new user(array('name' => $_REQUEST['username'], 'email' => $_REQUEST['email']));
$user->save();
//зарегистрировали, тут же авторизуем
$this->action_login();
} catch (Exception $e) {
$this->_actions_data['_errors'][] = $e->getMessage();
$this->_actions_data['_ok'] = 0;
}
}
示例15: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new user();
$user->username = $this->username;
$user->dealer = 1;
$user->email = $this->email;
$user->city = $this->city;
$user->firstname = $this->fname;
$user->lastname = $this->lname;
$user->setPassword($this->password);
$user->generateAuthKey();
\Yii::$app->mailer->compose(['html' => 'auth-html'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Authenticate your account ' . \Yii::$app->name)->send();
if ($user->save()) {
return $user;
}
}
return null;
}