From 07bae0479948c184fae4fd5a57a19d4a699b2000 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Tue, 7 Oct 2014 10:44:34 -0500
Subject: [PATCH] users: Error message setting username to an email

Since users can already log in via their email address, offer a friendly
error message when agents configure the user name to be an email address.
---
 include/class.user.php                        | 10 +++++-----
 include/staff/templates/user-account.tmpl.php |  9 +++++++--
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/include/class.user.php b/include/class.user.php
index 1a7317fba..f6470db78 100644
--- a/include/class.user.php
+++ b/include/class.user.php
@@ -957,15 +957,15 @@ class UserAccount extends UserAccountModel {
                 $errors['passwd2'] = __('Passwords do not match');
         }
 
+        // Make sure the username is not an email.
+        if ($vars['username'] && Validator::is_email($vars['username']))
+            $errors['username'] =
+                __('Users can always sign in with their email address');
+
         if ($errors) return false;
 
         $this->set('timezone_id', $vars['timezone_id']);
         $this->set('dst', isset($vars['dst']) ? 1 : 0);
-
-        // Make sure the username is not an email.
-        if ($vars['username'] && Validator::is_email($vars['username']))
-             $vars['username'] = '';
-
         $this->set('username', $vars['username']);
 
         if ($vars['passwd1']) {
diff --git a/include/staff/templates/user-account.tmpl.php b/include/staff/templates/user-account.tmpl.php
index 95509afc6..6a1b0e4a5 100644
--- a/include/staff/templates/user-account.tmpl.php
+++ b/include/staff/templates/user-account.tmpl.php
@@ -104,8 +104,13 @@ if ($info['error']) {
                     <?php echo __('Username'); ?>:
                 </td>
                 <td>
-                    <input type="text" size="35" name="username" value="<?php echo $info['username'] ?: $user->getEmail(); ?>">
-                    &nbsp;<span class="error">&nbsp;<?php echo $errors['username']; ?></span>
+                    <input type="text" size="35" name="username" value="<?php echo $info['username']; ?>">
+                    <i class="help-tip icon-question-sign" data-title="<?php
+                        echo __("Login via email"); ?>"
+                    data-content="<?php echo sprintf('%s: %s',
+                        __('Users can always sign in with their email address'),
+                        $user->getEmail()); ?>"></i>
+                    <div class="error">&nbsp;<?php echo $errors['username']; ?></div>
                 </td>
             </tr>
             <tr>
-- 
GitLab