switch (strtolower($_REQUEST['do'])) { case 'update': if (!$user) { $errors['err'] = 'Unknown or invalid user.'; } elseif (($acct = $user->getAccount()) && !$acct->update($_POST, $errors)) { $errors['err'] = 'Unable to update user account information'; } elseif ($user->updateInfo($_POST, $errors)) { $msg = 'User updated successfully'; $_REQUEST['a'] = null; } elseif (!$errors['err']) { $errors['err'] = 'Unable to update user profile. Correct any error(s) below and try again!'; } break; case 'create': $form = UserForm::getUserForm()->getForm($_POST); if ($user = User::fromForm($form)) { $msg = Format::htmlchars($user->getName()) . ' added successfully'; $_REQUEST['a'] = null; } elseif (!$errors['err']) { $errors['err'] = 'Unable to add user. Correct any error(s) below and try again.'; } break; case 'confirmlink': if (!$user || !$user->getAccount()) { $errors['err'] = 'Unknown or invalid user account'; } elseif ($user->getAccount()->isConfirmed()) { $errors['err'] = 'Account is already confirmed'; } elseif ($user->getAccount()->sendConfirmEmail()) { $msg = 'Account activation email sent to ' . $user->getEmail(); } else { $errors['err'] = 'Unable to send account activation email - try again!';
if (!$user_form->isValid(function ($f) { return !$f->get('private'); })) { $errors['err'] = __('Incomplete client information'); } elseif (!$_POST['backend'] && !$_POST['passwd1']) { $errors['passwd1'] = __('New password is required'); } elseif (!$_POST['backend'] && $_POST['passwd2'] != $_POST['passwd1']) { $errors['passwd1'] = __('Passwords do not match'); } elseif (($addr = $user_form->getField('email')->getClean()) && ClientAccount::lookupByUsername($addr)) { $user_form->getField('email')->addError(sprintf(__('Email already registered. Would you like to %1$s sign in %2$s?'), '<a href="login.php?e=' . urlencode($addr) . '" style="color:inherit"><strong>', '</strong></a>')); $errors['err'] = __('Unable to register account. See messages below'); } elseif (isset($_POST['backend']) && !($user = User::fromVars($user_form->getClean()))) { $errors['err'] = __('Unable to create local account. See messages below'); } elseif (!$user && !$thisclient && !($user = User::fromVars($user_form->getClean()))) { $errors['err'] = __('Unable to register account. See messages below'); } elseif (!$user && !($user = $thisclient ?: User::fromForm($user_form))) { $errors['err'] = __('Unable to register account. See messages below'); } else { if (!($acct = ClientAccount::createForUser($user))) { $errors['err'] = __('Internal error. Unable to create new account'); } elseif (!$acct->update($_POST, $errors)) { $errors['err'] = __('Errors configuring your profile. See messages below'); } } if (!$errors) { switch ($_POST['do']) { case 'create': $content = Page::lookup(Page::getIdByType('registration-confirm')); $inc = 'register.confirm.inc.php'; $acct->sendConfirmEmail(); break;
function addCollaborator($tid, $uid = 0) { global $thisstaff; if (!($ticket = Ticket::lookup($tid)) || !$ticket->checkStaffAccess($thisstaff)) { Http::response(404, 'No such ticket'); } $user = $uid ? User::lookup($uid) : null; //If not a post then assume new collaborator form if (!$_POST) { return self::_addcollaborator($ticket, $user); } $user = $form = null; if (isset($_POST['id']) && $_POST['id']) { //Existing user/ $user = User::lookup($_POST['id']); } else { //We're creating a new user! $form = UserForm::getUserForm()->getForm($_POST); $user = User::fromForm($form); } $errors = $info = array(); if ($user) { if ($user->getId() == $ticket->getOwnerId()) { $errors['err'] = sprintf('Ticket owner, %s, is a collaborator by default!', Format::htmlchars($user->getName())); } elseif ($c = $ticket->addCollaborator($user, array('isactive' => 1), $errors)) { $note = Format::htmlchars(sprintf('%s <%s> added as a collaborator', Format::htmlchars($c->getName()), $c->getEmail())); $ticket->logNote('New Collaborator Added', $note, $thisstaff, false); $info = array('msg' => sprintf('%s added as a collaborator', Format::htmlchars($c->getName()))); return self::_collaborators($ticket, $info); } } if ($errors && $errors['err']) { $info += array('error' => $errors['err']); } else { $info += array('error' => 'Unable to add collaborator - try again'); } return self::_addcollaborator($ticket, $user, $form, $info); }
function addUser() { $info = array(); if (!AuthenticationBackend::getSearchDirectories()) { $info['lookup'] = 'local'; } if ($_POST) { $info['title'] = 'Add New Customer'; $form = UserForm::getUserForm()->getForm($_POST); if ($user = User::fromForm($form)) { Http::response(201, $user->to_json()); } $info['error'] = 'Error adding customer - try again!'; } return self::_lookupform($form, $info); }
function addUser($id, $userId = 0, $remote = false) { global $thisstaff; if (!$thisstaff) { Http::response(403, 'Login Required'); } elseif (!($org = Organization::lookup($id))) { Http::response(404, 'Unknown organization'); } $info = array(); $info['title'] = __('Add User'); $info['action'] = '#orgs/' . $org->getId() . '/add-user'; $info['onselect'] = 'ajax.php/orgs/' . $org->getId() . '/add-user/'; $info['lookup'] = false; if (AuthenticationBackend::getSearchDirectories()) { $info['lookup'] = 'remote'; } if ($_POST) { if ($_POST['id']) { //Existing useer if (!($user = User::lookup($_POST['id']))) { $info['error'] = __('Unknown user selected'); } elseif ($user->getOrgId() == $org->getId()) { $info['error'] = sprintf('%s already belongs to the organization', Format::htmlchars($user->getName())); } } else { //Creating new user $form = UserForm::getUserForm()->getForm($_POST); if (!($user = User::fromForm($form))) { $info['error'] = __('Error adding user - try again!'); } } if (!$info['error'] && $user && $user->setOrganization($org)) { Http::response(201, $user->to_json()); } elseif (!$info['error']) { $info['error'] = __('Unable to add user to the organization - try again'); } } elseif ($remote && $userId) { list($bk, $userId) = explode(':', $userId, 2); if (!($backend = AuthenticationBackend::getSearchDirectoryBackend($bk)) || !($user_info = $backend->lookup($userId))) { Http::response(404, 'User not found'); } $form = UserForm::getUserForm()->getForm($user_info); } elseif ($userId) { //Selected local user $user = User::lookup($userId); } if ($user && $user->getOrgId()) { if ($user->getOrgId() == $org->getId()) { $info['warn'] = __('User already belongs to this organization!'); } else { $info['warn'] = __("Are you sure you want to change the user's organization?"); } } ob_start(); include STAFFINC_DIR . 'templates/user-lookup.tmpl.php'; $resp = ob_get_contents(); ob_end_clean(); return $resp; }