Permalink
Browse files

Removed showModuleErrors unifying error showing, added ERR.group to s…

…implify message-field connections.
  • Loading branch information...
sergeychernyshev committed Nov 15, 2014
1 parent 7635fc4 commit 7286c8e1a09540ca009f834a7b3ac111839719fa
View
@@ -110,7 +110,7 @@
$template_info['module']['title'] = $module->getTitle();
$template_info['module_forms'][$id] = $module->renderEditUserForm(
- $template_info, "?module=$id", array_key_exists($id, $errors) ? $errors[$id] : array(), $user, $_POST
+ $template_info, "?module=$id", $errors, $user, $_POST
);
}
}
View
@@ -263,7 +263,7 @@ public function sendConfirmationEmail() {
*
* @throws InputValidationException
*
- * @todo ACtually implement checking if email is real
+ * @todo Actually implement checking if email is real
*/
public function processEditUser($user, $data) {
$errors = array();
@@ -32,7 +32,7 @@
}
catch(InputValidationException $ex)
{
- $template_info['errors'] = $ex->getErrors();
+ $template_info['errors']['usernamepass'] = $ex->getErrors();
}
}
View
@@ -4,11 +4,13 @@
"version": "0.1.0",
"devDependencies": {
"webdriverio": "~2.3.0",
- "phantomjs": ">=1.8"
+ "phantomjs": ">=1.8",
+ "chai": "~1.10.0",
+ "chai-webdriver": "~0.9.4",
+ "selenium-webdriver": "~2.44.0"
},
"repository": {
"type": "git",
"url": "git@github.com:StartupAPI/users.git"
}
}
-
@@ -12,7 +12,7 @@
<form class="form" action="" method="POST">
<div class="row">
- <div class="form-group col-sm-8 col-md-6 col-lg-4">
+ <div class="form-group col-sm-8 col-md-6 col-lg-4{{ ERR.group('edit-account', 'name', errors) }}">
<label class="control-label" for="startupapi-admin-account-edit-name">Account Name</label>
<input class="form-control"
@@ -1,6 +1,7 @@
{% extends 'page_with_sidebar.html.twig' %}
-{% block content %}
+{% import 'error_messages.html.twig' as ERR %}
+{% block content %}
{% if not current_module %}
<div class="page-header">
<h1>Profile Information</h1>
@@ -9,18 +10,15 @@
{{ ERR.showErrors('profile-info', errors) }}
<form class="form-horizontal" role="form" action="" method="POST">
- <div class="form-group{% if 'name' in errors['profile-info']|keys %} has-error" title="{{ errors['profile-info']['name']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group('profile-info', 'name', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-profile-info-name">Name</label>
<div class="col-sm-8 col-md-7 col-lg-5">
<input id="startupapi-profile-info-name" class="form-control" name="name" type="text" value="{% if 'name' in data|keys %}{{ data.name }}{% else %}{{AUTH.current_user.name}}{% endif %}"/>
</div>
</div>
<div class="form-group
- has-feedback{% if 'email' in errors['profile-info']|keys %}
- has-error"
- title="{{ errors['profile-info']['email']|join("\n")}}{% endif %}
- ">
+ has-feedback{{ ERR.group('profile-info', 'email', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-profile-info-email">Email</label>
<div class="col-sm-8 col-md-7 col-lg-5">
<input id="startupapi-profile-info-email" class="form-control" name="email" type="email" placeholder="john@example.com" value="{% if 'email' in data|keys %}{{ data.email }}{% else %}{{AUTH.current_user.email}}{% endif %}"/>
@@ -17,21 +17,4 @@
{% endif %}
{% endmacro %}
-{% macro showModuleErrors(id, errors) %}
- {% if errors|length > 0 %}
- <div class="alert alert-danger" style="margin-top: 15px">
- <h4>Snap!</h4>
- <ul>
- {% for field, errorset in errors %}
- {% for error in errorset %}
- <li>
- <label style="cursor: pointer" for="startupapi-{{id}}-{{field}}">
- {{error}}
- </label>
- </li>
- {% endfor %}
- {% endfor %}
- </ul>
- </div>
- {% endif %}
-{% endmacro %}
+{% macro group(id, field, errors) %}{% if field in errors[id]|keys %} has-error" title="{{ errors[id][field]|join("\n")}}{% endif %}{% endmacro %}
@@ -3,20 +3,20 @@
<h1>Update your name and email</h1>
</div>
-{{ ERR.showModuleErrors(module.id, errors) }}
+{{ ERR.showErrors(slug, errors) }}
<form class="form-horizontal" action="{{action}}" method="POST">
- <div class="form-group{% if 'name' in errors|keys %} has-error" title="{{ errors['name']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'name', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-{{slug}}-name">Name</label>
<div class="col-sm-8 col-md-7 col-lg-5">
- <input class="form-control" id="startupapi-{{slug}}-name" name="name" type="text" value="{% if 'name' in data|keys %}{{ data.name }}{% else %}{{AUTH.current_user.name}}{% endif %}"/>
+ <input class="form-control" required id="startupapi-{{slug}}-name" name="name" type="text" value="{% if 'name' in data|keys %}{{ data.name }}{% else %}{{AUTH.current_user.name}}{% endif %}"/>
</div>
</div>
- <div class="form-group{% if 'email' in errors|keys %} has-error" title="{{ errors['email']|join("\n")}} ?>{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'email', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-{{slug}}-email">Email</label>
<div class="col-sm-8 col-md-7 col-lg-5">
- <input class="form-control" id="startupapi-{{slug}}-email" name="email" type="email" value="{% if 'email' in data|keys %}{{ data.email }}{% else %}{{AUTH.current_user.email}}{% endif %}"/>
+ <input class="form-control" required id="startupapi-{{slug}}-email" name="email" type="email" value="{% if 'email' in data|keys %}{{ data.email }}{% else %}{{AUTH.current_user.email}}{% endif %}"/>
{% if AUTH.current_user.email and not AUTH.current_user.is_email_verified %}
<div class="has-warning">
<p class="help-block">
@@ -16,14 +16,14 @@
<fieldset>
<legend>Enter confirmation code to login</legend>
- <div class="form-group{% if errors['emaillogin']['email'] %} has-error" title="{{errors['emaillogin']['email']|join('\n')}}{% endif %}">
+ <div class="form-group{{ ERR.group('emaillogin', 'email', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-{{slug}}-email">Email</label>
<div class="col-sm-8 col-md-7 col-lg-5">
<input class="form-control" id="startupapi-{{slug}}-email" name="email" type="email" placeholder="john@example.com"{% if email %} value="{{email}}"{% endif %}/>
</div>
</div>
- <div class="form-group{% if errors['emaillogin']['code'] %} has-error" title="{{errors['emaillogin']['code']|join('\n')}}{% endif %}">
+ <div class="form-group{{ ERR.group('emaillogin', 'code', errors) }}">
<label class="col-sm-1 control-label" for="startupapi-{{slug}}-code">Code</label>
<div class="col-sm-8 col-md-7 col-lg-5">
<input class="form-control" id="startupapi-{{slug}}-code" name="code" type="text"{% if code %} value="{{code}}"{% endif %}/>
@@ -3,10 +3,10 @@
<h1>Update your username and password</h1>
</div>
-{{ ERR.showModuleErrors(module.id, errors) }}
+{{ ERR.showErrors(slug, errors) }}
<form class="form-horizontal" action="{{action}}" method="POST"role="form">
- <div class="form-group{% if 'username' in errors|keys %} has-error" title="{{ errors['username']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'username', errors) }}">
<label class="col-sm-4 col-md-3 control-label" for="startupapi-{{slug}}-username">Username</label>
<div class="col-sm-7 col-md-6 col-lg-4">
{% if AUTH.current_user.username %}
@@ -18,15 +18,15 @@
</div>
{% if AUTH.current_user.username %}
- <div class="form-group{% if 'currentpass' in errors|keys %} has-error" title="{{ errors['currentpass']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'currentpass', errors) }}">
<label class="col-sm-4 col-md-3 control-label" for="startupapi-{{slug}}-currentpass">Current password</label>
<div class="col-sm-7 col-md-6 col-lg-4">
<input class="form-control" required id="startupapi-{{slug}}-currentpass" name="currentpass" type="password" autocomplete="off"/>
</div>
</div>
{% endif %}
- <div class="form-group{% if 'pass' in errors|keys %} has-error" title="{{ errors['pass']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'pass', errors) }}">
<label class="col-sm-4 col-md-3 control-label" for="startupapi-{{slug}}-pass">
{% if AUTH.current_user.username %}
New
@@ -40,7 +40,7 @@
</div>
</div>
- <div class="form-group{% if 'repeatpass' in errors|keys %} has-error" title="{{ errors['repeatpass']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'repeatpass', errors) }}">
<label class="col-sm-4 col-md-3 control-label" for="startupapi-{{slug}}-repeatpass">Repeat new password</label>
<div class="col-sm-7 col-md-6 col-lg-4">
<input class="form-control"{% if AUTH.current_user.username %} required{%endif%} id="startupapi-{{slug}}-repeatpass" name="repeatpass" type="password" autocomplete="off"/>
@@ -8,20 +8,20 @@
<h1>Password reset</h1>
</div>
- {{ ERR.showModuleErrors(slug, errors) }}
+ {{ ERR.showErrors(slug, errors) }}
<form class="form-horizontal" id="startupapi-passwordreset-form" action="" method="POST">
- <p>Please enter new password</p>
- <div class="form-group{% if 'pass' in errors|keys %} has-error" title="{{ errors['pass']|join("\n")}}{% endif %}">
+ <p>Please update your password</p>
+ <div class="form-group{{ ERR.group(slug, 'pass', errors) }}">
<label class="col-sm-3 col-md-3 col-lg-2 control-label" for="startupapi-{{slug}}-pass">New password</label>
<div class="col-sm-7 col-md-6 col-lg-4">
- <input class="form-control" id="startupapi-{{slug}}-pass"name="pass" type="password" size="25" autocomplete="off"/>
+ <input class="form-control" required id="startupapi-{{slug}}-pass"name="pass" type="password" size="25" autocomplete="off"/>
</div>
</div>
- <div class="form-group{% if 'repeatpass' in errors|keys %} has-error" title="{{ errors['repeatpass']|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'repeatpass', errors) }}">
<label class="col-sm-3 col-md-3 col-lg-2 control-label" for="startupapi-{{slug}}-repeatpass">Repeat new password</label>
<div class="col-sm-7 col-md-6 col-lg-4">
- <input class="form-control" id="startupapi-{{slug}}-repeatpass" name="repeatpass" type="password" size="25" autocomplete="off"/>
+ <input class="form-control" required id="startupapi-{{slug}}-repeatpass" name="repeatpass" type="password" size="25" autocomplete="off"/>
</div>
</div>
<div class="form-group">
@@ -7,7 +7,7 @@
<div class="page-header">
<h1>Verification code sent</h1>
</div>
- <p>Verification code was sent to <span class="startupapi-email-to-verify">{{email}}</span></p>
+ <p>Verification code was sent to <b>{{email}}</b></p>
<p><a class="btn btn-primary" href="{{UserConfig.USERSROOTURL}}/verify_email.php">Click here when you receive it</a></p>
{% else %}
<div class="page-header">
@@ -19,7 +19,7 @@
<h1>Please verify your email address</h1>
</div>
<form class="form col-sm-11 col-md-8" action="" method="GET">
- {{ ERR.showModuleErrors(slug, errors) }}
+ {{ ERR.showErrors(slug, errors) }}
<p>
Confirmation code was sent to
@@ -32,10 +32,10 @@
Please enter it below and click verify button.
</p>
- <div class="form-group{% if 'code' in errors|keys %} has-error" title="{{errors.code|join("\n")}}{% endif %}">
+ <div class="form-group{{ ERR.group(slug, 'code', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-code">Confirmation Code</label>
<div class="input-group">
- <input class="form-control" id="startupapi-{{slug}}-code" name="code" type="text" autocomplete="off"/>
+ <input class="form-control" required id="startupapi-{{slug}}-code" name="code" type="text" autocomplete="off"/>
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Verify</button>
</span>
@@ -17,22 +17,5 @@
</div>
{% endif %}
{% endmacro %}
-{% macro showModuleErrors(id, errors) %}
- {% if id in errors|keys and errors|length > 0 %}
- <div class="alert alert-block alert-error fade-in">
- <h4 style="margin-bottom: 0.5em">Snap!</h4>
- <ul>
- {% for field, errorset in errors %}
- {% for error in errorset %}
- <li>
- <label style="cursor: pointer" for="startupapi-{{id}}-edit-{{field}}">
- {{error}}
- </label>
- </li>
- {% endfor %}
- {% endfor %}
- </ul>
- </div>
- {% endif %}
-{% endmacro %}
+{% macro group(id, field, errors) %}{% if field in errors[id]|keys %} error" title="{{ errors[id][field]|join("\n")}}{% endif %}{% endmacro %}
@@ -1,15 +1,16 @@
+{% import 'error_messages.html.twig' as ERR %}
<form class="form-horizontal" action="{{action}}" method="POST">
<fieldset>
<legend>Update your name and email</legend>
- <div class="control-group{% if 'name' in errors|keys %} error" title="{{ errors['name']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'name', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-name">Name</label>
<div class="controls">
<input class="input-xlarge" id="startupapi-{{slug}}-edit-name" name="name" type="text" value="{% if 'name' in data|keys %}{{ data.name }}{% else %}{{AUTH.current_user.name}}{% endif %}"/>
</div>
</div>
- <div class="control-group{% if 'email' in errors|keys %} error" title="{{ errors['email']|join("\n")}} ?>{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'email', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-email">Email</label>
<div class="controls">
<input class="input-xlarge" id="startupapi-{{slug}}-edit-email" name="email" type="email" value="{% if 'email' in data|keys %}{{ data.email }}{% else %}{{AUTH.current_user.email}}{% endif %}"/>
@@ -1,7 +1,8 @@
+{% import 'error_messages.html.twig' as ERR %}
<form class="form-horizontal" action="{{action}}" method="POST">
<fieldset>
<legend>Update your username and password</legend>
- <div class="control-group{% if 'username' in errors|keys %} error" title="{{ errors['username']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'username', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-username">Username</label>
<div class="controls">
{% if AUTH.current_user.username %}
@@ -15,14 +16,14 @@
<legend>Change password</legend>
{% if AUTH.current_user.username %}
- <div class="control-group{% if 'currentpass' in errors|keys %} error" title="{{ errors['currentpass']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'currentpass', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-currentpass">Current password</label>
<div class="controls">
<input id="startupapi-{{slug}}-edit-currentpass" name="currentpass" type="password" autocomplete="off"/>
</div>
</div>
{% endif %}
- <div class="control-group{% if 'pass' in errors|keys %} error" title="{{ errors['pass']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'pass', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-pass">
{% if AUTH.current_user.username %}
New
@@ -35,7 +36,7 @@
<input id="startupapi-{{slug}}-edit-pass" name="pass" type="password" autocomplete="off"/>
</div>
</div>
- <div class="control-group{% if 'repeatpass' in errors|keys %} error" title="{{ errors['repeatpass']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'repeatpass', errors) }}">
<label class="control-label" for="startupapi-{{slug}}-edit-repeatpass">Repeat new password</label>
<div class="controls">
<input id="startupapi-{{slug}}-edit-repeatpass" name="repeatpass" type="password" autocomplete="off"/>
@@ -7,7 +7,7 @@
{% if email %}
<div id="startupapi-sendverificationcode-success">
<h3>Verification code sent</h3>
- <p>Verification code was sent to <span class="startupapi-email-to-verify">{{email}}</span></p>
+ <p>Verification code was sent to <b>{{email}}</b></p>
<a class="btn btn-primary" href="{{UserConfig.USERSROOTURL}}/verify_email.php">Click here when you receive it</a>
</div>
{% else %}
@@ -13,8 +13,6 @@
</div>
{% else %}
<div>
- {{ ERR.showModuleErrors(slug, errors) }}
-
<h3>Please verify your email address</h3>
<p>
Confirmation code was sent to
@@ -28,12 +26,14 @@
Please enter it below and click verify button.
</p>
+ {{ ERR.showErrors(slug, errors) }}
+
<form class="form well" action="" method="GET">
<fieldset>
- <div class="control-group{% if 'code' in errors|keys %} error" title="{{errors['code']|join("\n")}}{% endif %}">
+ <div class="control-group{{ ERR.group(slug, 'code', errors) }}">
<label class="control-label" for="startupapi-code">Confirmation Code</label>
<div class="controls">
- <input id="startupapi-code" name="code" type="text" autocomplete="off"/>
+ <input id="startupapi-{{slug}}-edit-code" required name="code" type="text" autocomplete="off"/><br>
<a id="startupapi-{{slug}}-resend" href="{{UserConfig.USERSROOTURL}}/send_email_verification_code.php">I never got the code, please resend</a>
</div>
</div>
View
@@ -9,17 +9,17 @@
$email = is_null($user) ? null : $user->getEmail();
$template_info = StartupAPI::getTemplateInfo();
+$template_info['slug'] = 'verify_email';
if (array_key_exists('code', $_GET)) {
if (User::verifyEmailLinkCode($_GET['code'], $user)) {
$template_info['verification_complete'] = true;
} else {
- $template_info['errors']['code'][] = 'Invalid code';
+ $template_info['errors'][$template_info['slug']]['code'][] = 'Invalid code';
}
}
$template_info['email'] = $email;
-$template_info['slug'] = 'verify_email';
$template_info['return'] = User::getReturn();
User::clearReturn();

0 comments on commit 7286c8e

Please sign in to comment.