public function user_info($id_) { $args = func_get_args(); // func_get_args(): Can't be used as a function parameter before PHP 5.3.0 $res = $this->__call('user_info', $args); if ($res === null) { return null; } $user = new User($res); if (!$user->is_valid()) { return null; } if (!$user->hasAttribute('groups')) { $user->setAttribute('groups', array()); } return $user; }
$userDB = UserDB::getInstance(); if (!$userDB->isWriteable()) { die_error(_('User Database not writeable'), __FILE__, __LINE__); } if ($_REQUEST['action'] == 'add') { $minimun_attributes = array('login', 'displayname', 'password'); if (!isset($_REQUEST['login']) or !isset($_REQUEST['displayname']) or !isset($_REQUEST['password'])) { die_error(_("Unable to create user"), __FILE__, __LINE__); } $u = new User(); foreach ($minimun_attributes as $attributes) { if (isset($_REQUEST[$attributes])) { $u->setAttribute($attributes, $_REQUEST[$attributes]); } } if ($u->hasAttribute('password') && $u->getAttribute('password') === '') { popup_error(_('Unable to create user with an empty password')); redirect(); } $res = $userDB->add($u); if (!$res) { popup_error(sprintf(_("Unable to create user '%s'"), $_REQUEST['login'])); redirect(); } popup_info(sprintf(_("User '%s' successfully added"), $u->getAttribute('login'))); redirect('users.php'); } if ($_REQUEST['action'] == 'del') { if (isset($_REQUEST['checked_users']) && is_array($_REQUEST['checked_users'])) { foreach ($_REQUEST['checked_users'] as $user_login) { $sessions = Abstract_Session::getByUser($user_login);
public function actionRegister() { $data = $this->setData($data, $this->_getData, 'Error! No data is sent to server'); if (!isset($data->device)) { $this->sendResponse(null, 0, 'Device invalid'); } if (!isset($data->user)) { $this->sendResponse(null, 0, 'Account invalid'); } $flagSave = false; $device = new Device(); $user = new User(); $user->pk_s_id = '-1'; foreach ($data->user as $k => $v) { if ($user->hasAttribute($k)) { $user->{$k} = $v; } } if ($user->save()) { $user->pk_s_id = 'SV' . $user->id; if ($user->save()) { $flagSave = true; $device->s_user_id = $user->pk_s_id; foreach ($data->device as $k => $v) { if ($device->hasAttribute($k)) { $device->{$k} = $v; } } if ($device->save()) { $flagSave = true; } else { $flagSave = false; $user->delete(); } } } if ($flagSave == true) { $this->sendResponse(null, 1, 'success'); } else { $this->sendResponse(null, 0, 'fail'); } }
protected function generateUserFromRow($row_) { $u = new User(); foreach ($this->config['match'] as $attribut => $match_ldap) { if (isset($row_[$match_ldap])) { if (is_array($row_[$match_ldap])) { unset($row_[$match_ldap]['count']); if (count($row_[$match_ldap]) == 1) { $u->setAttribute($attribut, $row_[$match_ldap][0]); } else { $u->setAttribute($attribut, $row_[$match_ldap]); } } else { $u->setAttribute($attribut, $row_[$match_ldap]); } } } if ($u->hasAttribute('displayname') == false) { Logger::debug('main', 'UserDB::ldap::generateUserFromRow user ' . $u->getAttribute('login') . ' does not have a displayname, generate one'); $u->setAttribute('displayname', $u->getAttribute('login')); } return $u; }
/** * Creates a new item * * @access public * @return void */ public function actionCreate() { //$this->_checkAuth(); switch ($_GET['model']) { // Get an instance of the respective model case 'users': // {{{ $model = new User(); break; // }}} // }}} default: // {{{ $this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model'])); exit; // }}} } // Try to assign POST values to attributes foreach ($_POST as $var => $value) { // Does the model have this attribute? if ($model->hasAttribute($var)) { $model->{$var} = $value; } else { // No, raise an error $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model'])); } } // Try to save the model if ($model->save()) { // Saving was OK $this->_sendResponse(200, $this->_getObjectEncoded($_GET['model'], $model->attributes)); } else { // Errors occurred $msg = "<h1>Error</h1>"; $msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']); $msg .= "<ul>"; foreach ($model->errors as $attribute => $attr_errors) { $msg .= "<li>Attribute: {$attribute}</li>"; $msg .= "<ul>"; foreach ($attr_errors as $attr_error) { $msg .= "<li>{$attr_error}</li>"; } $msg .= "</ul>"; } $msg .= "</ul>"; $this->_sendResponse(500, $msg); } var_dump($_REQUEST); }