本文整理汇总了PHP中jAuth::createUserObject方法的典型用法代码示例。如果您正苦于以下问题:PHP jAuth::createUserObject方法的具体用法?PHP jAuth::createUserObject怎么用?PHP jAuth::createUserObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jAuth
的用法示例。
在下文中一共展示了jAuth::createUserObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAll
public function testAll()
{
if ($this->config === null) {
$this->sendMessage('Ldap plugin for jauth is not tested because there isn\'t configuration.' . ' To test it, you should create and configure an auth_ldap.coord.ini.php file.');
return;
}
for ($i = 1; $i <= NB_USERS_LDAP; $i++) {
$myUser = jAuth::createUserObject("testldap usr {$i}", "pass{$i}");
$this->assertTrue($myUser instanceof jAuthUserLDAP);
jAuth::saveNewUser($myUser);
$myUserLDAP = jAuth::getUser("testldap usr {$i}");
$user = "\n <object class=\"jAuthUserLDAP\">\n <string property=\"login\" value=\"testldap usr {$i}\" />\n <string property=\"email\" value=\"\" />\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n ";
$this->assertComplexIdenticalStr($myUserLDAP, $user);
$myUser->email = "usr{$i}.testldap@domain.com";
jAuth::updateUser($myUser);
$myUserLDAP = jAuth::getUser("testldap usr {$i}");
$user = "\n <object>\n <string property=\"login\" value=\"testldap usr {$i}\" />\n <array property=\"email\">array('usr{$i}.testldap@domain.com')</array>\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n ";
$this->assertComplexIdenticalStr($myUserLDAP, $user);
$this->assertTrue(jAuth::verifyPassword("testldap usr {$i}", "pass{$i}"));
$this->assertTrue(jAuth::changePassword("testldap usr {$i}", "newpass{$i}"));
}
$myUsersLDAP = jAuth::getUserList('testldap usr*');
$users = "<array>";
for ($i = 1; $i <= NB_USERS_LDAP; $i++) {
$users .= "\n <object>\n <array property=\"login\">array('testldap usr {$i}')</array>\n <array property=\"email\">array('usr{$i}.testldap@domain.com')</array>\n <array property=\"cn\">array('testldap usr {$i}')</array>\n <array property=\"distinguishedName\">array('CN=testldap usr {$i},{$this->config['ldap']['searchBaseDN']}')</array>\n <array property=\"name\">array('testldap usr {$i}')</array>\n <string property=\"password\" value=\"\" />\n </object>\n ";
}
$users .= "</array>";
$this->assertComplexIdenticalStr($myUsersLDAP, $users);
for ($i = 1; $i <= NB_USERS_LDAP; $i++) {
$this->assertTrue(jAuth::removeUser("testldap usr {$i}"));
}
$myUsersLDAP = jAuth::getUserList('testldap usr*');
$this->assertFalse(count($myUsersLDAP) > 0);
}
示例2: create
function create()
{
$rep = $this->getResponse('html');
$rep->title = "Bienvenue | " . $rep->appName;
//
$password = $this->param('password');
$firstname = $this->param('firstname');
$lastname = $this->param('lastname');
$email = $this->param('email');
$professionnel = $this->param('professionnel', 'NO', true);
$this->success = false;
$this->message = "Erreur: veuillez remplir tous les champs obligatoires.";
//si ville et commune existe
if (!empty($email) && !empty($password) && !empty($lastname) && !empty($firstname)) {
// instanciation
$user = jAuth::createUserObject($email, $password);
// infos user
$user->firstname = $firstname;
$user->lastname = $lastname;
$user->email = $email;
$user->keyactivate = uniqid('', true);
// $user->professionnel = $professionnel;
//jLog::dump($user);
try {
$nu = jAuth::saveNewUser($user);
//set user as customer
// $tbcust = jDao::get('customer~account');
// $custRecord = jDao::createRecord('customer~account');
// $custRecord->user_id = $nu->id;
// $tbcust->insert($custRecord);
// end
$this->success = true;
$this->message = "Votre compte a été crée avec succès, un e-mail de " . " confirmation vous " . " a été envoyé à l'adresse : " . $email;
/* $mail = new jMailer();
$tpl = $mail->Tpl('user~createmail',true);
$tpl->assign('user',$user);
$mail->Send();
*/
} catch (Exception $exc) {
$this->message = "Désole votre inscription a échouée veuillez reesayer ultérieurement.";
$rep = $this->getResponse('redirect');
$rep->action = "user~user:inscription";
$rep->params = array('msg' => $this->message);
return $rep;
}
}
$rep->bodyTpl = 'create';
$rep->body->assign('message', $this->message);
return $rep;
}
示例3: save
/**
* save new user and send an email for a confirmation, with
* a key to activate the account
*/
function save()
{
if (jAuth::isConnected()) {
return $this->noaccess();
}
$rep = $this->getResponse("redirect");
$rep->action = "registration:index";
$form = jForms::get('registration');
if (!$form) {
return $rep;
}
jEvent::notify('jcommunity_registration_init_form', array('form' => $form));
$form->initFromRequest();
if (!$form->check()) {
return $rep;
}
$login = $form->getData('reg_login');
if (jAuth::getUser($login)) {
$form->setErrorOn('reg_login', jLocale::get('register.form.login.exists'));
return $rep;
}
$pass = jAuth::getRandomPassword(8);
$key = substr(md5($login . '-' . $pass), 1, 10);
$user = jAuth::createUserObject($login, $pass);
$user->email = $form->getData('reg_email');
$user->nickname = $login;
$user->status = JCOMMUNITY_STATUS_NEW;
$user->request_date = date('Y-m-d H:i:s');
$user->keyactivate = $key;
$ev = jEvent::notify('jcommunity_registration_prepare_save', array('form' => $form, 'user' => $user));
if (count($form->getErrors())) {
return $rep;
}
$responses = $ev->getResponse();
$hasErrors = false;
foreach ($responses as $response) {
if (isset($response['errorRegistration']) && $response['errorRegistration'] != "") {
jMessage::add($response['errorRegistration'], 'error');
$hasErrors = true;
}
}
if ($hasErrors) {
return $rep;
}
jAuth::saveNewUser($user);
jEvent::notify('jcommunity_registration_after_save', array('form' => $form, 'user' => $user));
$gJConfig = jApp::config();
$mail = new jMailer();
$mail->From = $gJConfig->mailer['webmasterEmail'];
$mail->FromName = $gJConfig->mailer['webmasterName'];
$mail->Sender = $gJConfig->mailer['webmasterEmail'];
$mail->Subject = jLocale::get('register.mail.new.subject');
$tpl = new jTpl();
$tpl->assign(compact('login', 'pass', 'key'));
$tpl->assign('server', $_SERVER['SERVER_NAME']);
$mail->Body = $tpl->fetch('mail_registration', 'text');
$mail->AddAddress($user->email);
$mail->Send();
jForms::destroy('registration');
$rep->action = "registration:confirmform";
$rep->params = array('login' => $login);
return $rep;
}
示例4: save
/**
*
*/
function save()
{
$rep = $this->getResponse('json');
//parametres
$id = $this->intParam('id', null, true);
$active = $this->param('active', 'NO', true);
$login = $this->param('login');
$password = $this->param('password');
$lastname = $this->param('lastname');
$firstname = $this->param('firstname');
$email = $this->param('email');
$phone = $this->param('phone');
//verification
if ($id) {
//update
if (!empty($firstname) && !empty($lastname) && !empty($active) && jFilter::isEmail($email)) {
// instanciation de la factory
$user = jAuth::getUser($login);
// infos user
$user->phone = $phone;
$user->lastname = $lastname;
$user->firstname = $firstname;
$user->email = $email;
$user->active = $active;
// on le sauvegarde dans la base
try {
jAuth::updateUser($user);
if (!empty($password) && $user->password != $password) {
jAuth::changePassword($user->login, $password);
}
$this->success = true;
$this->msg = "utilisateur modifié ";
} catch (Exception $e) {
$this->success = false;
$this->msg = "utilisateur non modifié";
}
}
} else {
//insert
if (!empty($login) && !empty($password) && !empty($firstname) && !empty($lastname) && !empty($active) && jFilter::isEmail($email)) {
// instanciation
$user = jAuth::createUserObject($login, $password);
// infos user
$user->phone = $phone;
$user->lastname = $lastname;
$user->firstname = $firstname;
$user->email = $email;
$user->active = $active;
// on le sauvegarde dans la base
try {
$this->success = jAuth::saveNewUser($user);
$this->msg = "utilisateur ajouté ";
} catch (Exception $e) {
$this->success = false;
$this->msg = "utilisateur non ajouté";
}
}
}
$rep->data = array('success' => $this->success, 'msg' => $this->msg);
return $rep;
}
示例5: savecreate
/**
* save data of a form in a new record
*/
function savecreate()
{
$form = jForms::get($this->form);
$form->initFromRequest();
$rep = $this->getResponse('redirect');
if ($form == null) {
$rep->action = 'default:index';
return $rep;
}
$evresp = array();
if ($form->check() && !jEvent::notify('jauthdbAdminCheckCreateForm', array('form' => $form))->inResponse('check', false, $evresp)) {
$props = jDao::createRecord($this->dao, $this->dbProfile)->getProperties();
$user = jAuth::createUserObject($form->getData('login'), $form->getData('password'));
$form->setData('password', $user->password);
$form->prepareObjectFromControls($user, $props);
$form->saveAllFiles($this->uploadsDirectory);
jAuth::saveNewUser($user);
jForms::destroy($this->form);
jMessage::add(jLocale::get('crud.message.create.ok', $user->login), 'notice');
$rep->action = 'default:view';
$rep->params['id'] = $user->login;
return $rep;
} else {
$rep->action = 'default:create';
return $rep;
}
}
示例6: saveAccount
/**
* Save the data for the services section.
* @return Redirect to the index.
*/
function saveAccount()
{
// Get lizmap services
$services = lizmap::getServices();
$rep = $this->getResponse('redirect');
$rep->action = 'view~default:index';
// Redirect if option not active
if (!$services->allowUserAccountRequests) {
return $rep;
}
// Redirect if already a logged user
if (jAuth::isConnected()) {
jMessage::add(jLocale::get("view~user.already.logged"));
return $rep;
}
// Get the form
$form = jForms::get('view~lizmap_user');
// token
$token = $this->param('__JFORMS_TOKEN__');
if (!$token) {
$rep->action = "view~user:createAccount";
return $rep;
}
// If the form is not defined, redirection
if (!$form) {
$rep->action = "view~user:createAccount";
return $rep;
}
// Set the other form data from the request data
$form->initFromRequest();
// Check the form
$ok = true;
if (!$form->check()) {
$ok = false;
}
// Check the honey pot. Redirect if filled (means robot)
$honey = $form->getData('name');
if ($honey and !empty($honey)) {
$rep->action = "view~user:createAccount";
return $rep;
}
if (!$ok) {
// Errors : redirection to the display action
$rep->action = 'view~user:editAccount';
return $rep;
}
// Save the data
$evresp = array();
if (!jEvent::notify('jauthdbAdminCheckCreateForm', array('form' => $form))->inResponse('check', false, $evresp)) {
// Sanitize some fields
$sanitize = array('login', 'firstname', 'lastname', 'organization', 'phonenumber', 'street', 'postcode', 'city', 'country', 'comment');
foreach ($sanitize as $field) {
$form->setData($field, filter_var($form->getData($field), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
}
// Add user to database via jAuth methods
try {
$props = jDao::createRecord('jauthdb~jelixuser', 'jauth')->getProperties();
$user = jAuth::createUserObject($form->getData('login'), $form->getData('password'));
$form->setData('password', $user->password);
$form->prepareObjectFromControls($user, $props);
jAuth::saveNewUser($user);
jMessage::add(jLocale::get("view~user.form.message.saved"));
$ok = true;
$rep->action = "view~user:validateAccount";
} catch (exception $e) {
$ok = false;
jMessage::add(jLocale::get("view~user.form.message.not.saved"));
$rep->action = "view~user:editAccount";
}
// Send email to the administrator
if ($ok) {
try {
$this->sendEmailToAdmin($user);
} catch (Exception $e) {
jLog::log('error while sending email to admin: ' . $e->getMessage());
}
}
}
return $rep;
}