|
| 1 | +<?php |
| 2 | +/********************************************************************* |
| 3 | + profile.php |
| 4 | +
|
| 5 | + Manage client profile. This will allow a logged-in user to manage |
| 6 | + his/her own public (non-internal) information |
| 7 | +
|
| 8 | + |
| 9 | + |
| 10 | + Copyright (c) 2006-2013 osTicket |
| 11 | + http://www.osticket.com |
| 12 | +
|
| 13 | + Released under the GNU General Public License WITHOUT ANY WARRANTY. |
| 14 | + See LICENSE.TXT for details. |
| 15 | +
|
| 16 | + vim: expandtab sw=4 ts=4 sts=4: |
| 17 | + $Id: $ |
| 18 | +**********************************************************************/ |
| 19 | +require 'client.inc.php'; |
| 20 | + |
| 21 | +$inc = 'register.inc.php'; |
| 22 | + |
| 23 | +$errors = array(); |
| 24 | + |
| 25 | +if (!$cfg || !$cfg->isClientRegistrationEnabled()) { |
| 26 | + Http::redirect('index.php'); |
| 27 | +} |
| 28 | + |
| 29 | +elseif ($thisclient) { |
| 30 | + // Guest registering for an account |
| 31 | + if ($thisclient->isGuest()) { |
| 32 | + foreach ($thisclient->getForms() as $f) { |
| 33 | + if ($f->get('object_type') == 'U') { |
| 34 | + $user_form = $f; |
| 35 | + $user_form->getField('email')->configure('disabled', true); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + // Existing client (with an account) updating profile |
| 40 | + else { |
| 41 | + $user = User::lookup($thisclient->getId()); |
| 42 | + $content = Page::lookupByType('registration-thanks'); |
| 43 | + $inc = isset($_GET['confirmed']) |
| 44 | + ? 'register.confirmed.inc.php' : 'profile.inc.php'; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +if ($user && $_POST) { |
| 49 | + if ($acct = $thisclient->getAccount()) { |
| 50 | + $acct->update($_POST, $errors); |
| 51 | + } |
| 52 | + if (!$errors && $user->updateInfo($_POST, $errors)) |
| 53 | + Http::redirect('tickets.php'); |
| 54 | +} |
| 55 | + |
| 56 | +elseif ($_POST) { |
| 57 | + $user_form = UserForm::getUserForm()->getForm($_POST); |
| 58 | + if ($thisclient) { |
| 59 | + $user_form->getField('email')->configure('disabled', true); |
| 60 | + $user_form->getField('email')->value = $thisclient->getEmail(); |
| 61 | + } |
| 62 | + |
| 63 | + if (!$user_form->isValid(function($f) { return !$f->isVisibleToUsers(); })) |
| 64 | + $errors['err'] = __('Incomplete client information'); |
| 65 | + elseif (!$_POST['backend'] && !$_POST['passwd1']) |
| 66 | + $errors['passwd1'] = __('New password is required'); |
| 67 | + elseif (!$_POST['backend'] && $_POST['passwd2'] != $_POST['passwd1']) |
| 68 | + $errors['passwd1'] = __('Passwords do not match'); |
| 69 | + |
| 70 | + // XXX: The email will always be in use already if a guest is logged in |
| 71 | + // and is registering for an account. Instead, |
| 72 | + elseif (($addr = $user_form->getField('email')->getClean()) |
| 73 | + && ClientAccount::lookupByUsername($addr)) { |
| 74 | + $user_form->getField('email')->addError( |
| 75 | + sprintf(__('Email already registered. Would you like to %1$s sign in %2$s?'), |
| 76 | + '<a href="login.php?e='.urlencode($addr).'" style="color:inherit"><strong>', |
| 77 | + '</strong></a>')); |
| 78 | + $errors['err'] = __('Unable to register account. See messages below'); |
| 79 | + } |
| 80 | + // Users created from ClientCreateRequest |
| 81 | + elseif (isset($_POST['backend']) && !($user = User::fromVars($user_form->getClean()))) |
| 82 | + $errors['err'] = __('Unable to create local account. See messages below'); |
| 83 | + // Registration for existing users |
| 84 | + elseif (!$user && !$thisclient && !($user = User::fromVars($user_form->getClean()))) |
| 85 | + $errors['err'] = __('Unable to register account. See messages below'); |
| 86 | + // New users and users registering from a ticket access link |
| 87 | + elseif (!$user && !($user = $thisclient ?: User::fromForm($user_form))) |
| 88 | + $errors['err'] = __('Unable to register account. See messages below'); |
| 89 | + else { |
| 90 | + if (!($acct = ClientAccount::createForUser($user))) |
| 91 | + $errors['err'] = __('Unable to create new account.') |
| 92 | + .' '.__('Internal error occurred'); |
| 93 | + elseif (!$acct->update($_POST, $errors)) |
| 94 | + $errors['err'] = __('Errors configuring your profile. See messages below'); |
| 95 | + } |
| 96 | + |
| 97 | + if (!$errors) { |
| 98 | + switch ($_POST['do']) { |
| 99 | + case 'create': |
| 100 | + $content = Page::lookupByType('registration-confirm'); |
| 101 | + $inc = 'register.confirm.inc.php'; |
| 102 | + $acct->sendConfirmEmail(); |
| 103 | + break; |
| 104 | + case 'import': |
| 105 | + if ($bk = UserAuthenticationBackend::getBackend($_POST['backend'])) { |
| 106 | + $cl = new ClientSession(new EndUser($user)); |
| 107 | + if (!$bk->supportsInteractiveAuthentication()) |
| 108 | + $acct->set('backend', null); |
| 109 | + $acct->confirm(); |
| 110 | + if ($user = $bk->login($cl, $bk)) |
| 111 | + Http::redirect('tickets.php'); |
| 112 | + } |
| 113 | + break; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + if ($errors && $user && $user != $thisclient) |
| 118 | + $user->delete(); |
| 119 | +} |
| 120 | + |
| 121 | +include(CLIENTINC_DIR.'header.inc.php'); |
| 122 | +include(CLIENTINC_DIR.$inc); |
| 123 | +include(CLIENTINC_DIR.'footer.inc.php'); |
| 124 | + |
0 commit comments