From b7a9fa86b59ac082b3bf3a87bfc5f2a8412668e8 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Sat, 22 Mar 2014 22:53:09 -0500 Subject: [PATCH] Guests can register for accounts, if enabled --- account.php | 28 +++++++++++++++++++++++----- assets/default/css/theme.css | 1 + include/client/view.inc.php | 13 ++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/account.php b/account.php index acab3bed6..2e081c735 100644 --- a/account.php +++ b/account.php @@ -27,9 +27,18 @@ if (!$cfg || !$cfg->isClientRegistrationEnabled()) { } elseif ($thisclient) { - $inc = isset($_GET['confirmed']) - ? 'registration.confirmed.inc.php' : 'profile.inc.php'; - $user = User::lookup($thisclient->getId()); + // Guest registering for an account + if ($thisclient->isGuest()) { + foreach ($thisclient->getForms() as $f) + if ($f->get('type') == 'U') + $user_form = $f; + } + // Existing client (with an account) updating profile + else { + $user = User::lookup($thisclient->getId()); + $inc = isset($_GET['confirmed']) + ? 'registration.confirmed.inc.php' : 'profile.inc.php'; + } } if ($user && $_POST) { @@ -49,8 +58,17 @@ elseif ($_POST) { elseif ($_POST['passwd2'] != $_POST['passwd1']) $errors['passwd1'] = 'Passwords do not match'; - elseif (!($user=User::fromForm($user_form))) + // XXX: The email will always be in use already if a guest is logged in + // and is registering for an account. Instead, + elseif (!($user = $thisclient ?: User::fromForm($user_form))) $errors['err'] = 'Unable to register account. See messages below'; + elseif (($addr = $user_form->getField('email')->getClean()) + && ClientAccount::lookupByUsername($addr)) { + $user_form->getField('email')->addError( + 'Email already registered. Would you like to <a href="login.php?e=' + .urlencode($addr).'" style="color:inherit"><strong>sign in</strong></a>?'); + $errors['err'] = 'Unable to register account. See messages below'; + } else { if (!($acct = ClientAccount::createForUser($user))) $errors['err'] = 'Internal error. Unable to create new account'; @@ -66,7 +84,7 @@ elseif ($_POST) { } } - if ($errors && $user) + if ($errors && $user && $user != $thisclient) $user->delete(); } diff --git a/assets/default/css/theme.css b/assets/default/css/theme.css index 195460e49..d1934d792 100644 --- a/assets/default/css/theme.css +++ b/assets/default/css/theme.css @@ -219,6 +219,7 @@ h2 { border: 1px solid #a00; background: url('../images/icons/error.png') 10px 50% no-repeat #fff0f0; } +#msg_info { margin: 0; padding: 5px; margin-bottom: 10px; color: #3a87ad; border: 1px solid #bce8f1; background-color: #d9edf7; } .warning { background: #ffc; font-style: italic; diff --git a/include/client/view.inc.php b/include/client/view.inc.php index 469740f6c..0ff0dbdea 100644 --- a/include/client/view.inc.php +++ b/include/client/view.inc.php @@ -8,7 +8,18 @@ $dept = $ticket->getDept(); if(!$dept || !$dept->isPublic()) $dept = $cfg->getDefaultDept(); -?> +if ($thisclient && $thisclient->isGuest() + && $cfg->isClientRegistrationEnabled()) { ?> + +<div id="msg_info"> + <i class="icon-compass icon-2x pull-left"></i> + <strong>Looking for your other tickets?</strong></br> + <a href="account.php?do=create">Register for an account</a> + or <a href="login.php">sign in</a> + for the best experience on our help desk.</div> + +<?php } ?> + <table width="800" cellpadding="1" cellspacing="0" border="0" id="ticketInfo"> <tr> <td colspan="2" width="100%"> -- GitLab