|
1 |
| -<?php |
2 |
| - |
| 1 | +<?php /* vim: set colorcolumn= expandtab shiftwidth=2 softtabstop=2 tabstop=4 smarttab: */ |
3 | 2 | namespace BNETDocs\Templates\User;
|
4 |
| - |
5 | 3 | use \CarlBennett\MVC\Libraries\Common;
|
6 | 4 | use \CarlBennett\MVC\Libraries\Pair;
|
7 |
| - |
8 |
| -$title = "Create Account"; |
9 |
| -$description = "This form allows an individual to create an account on BNETDocs."; |
| 5 | +$title = 'Create Account'; |
| 6 | +$description = 'This form allows a user to create an account on the site.'; |
10 | 7 | $this->opengraph->attach(new Pair("url", "/user/register"));
|
11 |
| - |
12 |
| -switch ($this->getContext()->error) { |
13 |
| - case null: |
14 |
| - $af = "email"; |
15 |
| - $message = null; |
16 |
| - break; |
17 |
| - case "ALREADY_LOGGED_IN": |
18 |
| - $af = null; |
19 |
| - $message = "You are already logged in, you must log out first."; |
20 |
| - break; |
21 |
| - case "INVALID_CAPTCHA": |
22 |
| - $af = ""; |
23 |
| - $message = "The captcha code did not successfully verify, try again."; |
24 |
| - break; |
25 |
| - case "NONMATCHING_PASSWORD": |
26 |
| - $af = "pw1"; |
27 |
| - $message = "The password does not match its confirmation."; |
28 |
| - break; |
29 |
| - case "INVALID_EMAIL": |
30 |
| - $af = "email"; |
31 |
| - $message = "The email address is invalid."; |
32 |
| - break; |
33 |
| - case "EMAIL_NOT_ALLOWED": |
34 |
| - $af = "email"; |
35 |
| - $message = "The email address is not allowed, use a different one."; |
36 |
| - break; |
37 |
| - case "PASSWORD_CONTAINS_EMAIL": |
38 |
| - $af = "pw1"; |
39 |
| - $message = "The password contains the email address, " |
40 |
| - . "use a better password."; |
41 |
| - break; |
42 |
| - case "PASSWORD_CONTAINS_USERNAME": |
43 |
| - $af = "pw1"; |
44 |
| - $message = "The password contains the username, use a better password."; |
45 |
| - break; |
46 |
| - case "USERNAME_TOO_LONG": |
47 |
| - $af = "username"; |
48 |
| - $message = "The username is too long, choose a different username."; |
49 |
| - break; |
50 |
| - case "USERNAME_TOO_SHORT": |
51 |
| - $af = "username"; |
52 |
| - $message = "The username is too short, choose a different username."; |
53 |
| - break; |
54 |
| - case "PASSWORD_TOO_LONG": |
55 |
| - $af = "pw1"; |
56 |
| - $message = "The password is too long, shorten it."; |
57 |
| - break; |
58 |
| - case "PASSWORD_TOO_SHORT": |
59 |
| - $af = "pw1"; |
60 |
| - $message = "The password is too short, use a better password."; |
61 |
| - break; |
62 |
| - case "PASSWORD_BLACKLIST": |
63 |
| - $af = "pw1"; |
64 |
| - $message = $this->getContext()->error_extra; |
65 |
| - if (empty($message)) $message = "The password is blacklisted."; |
66 |
| - break; |
67 |
| - case "COUNTRY_DENIED": |
68 |
| - $af = null; |
69 |
| - $message = $this->getContext()->error_extra; |
70 |
| - if (empty($message)) $message = "Your country is blacklisted."; |
71 |
| - break; |
72 |
| - case "REGISTER_DISABLED": |
73 |
| - $af = null; |
74 |
| - $message = "Creating accounts is currently administratively disabled."; |
75 |
| - break; |
76 |
| - case "EMAIL_ALREADY_USED": |
77 |
| - $af = "email"; |
78 |
| - $message = "The email address is already in use, use another."; |
79 |
| - break; |
80 |
| - case "USERNAME_TAKEN": |
81 |
| - $af = "username"; |
82 |
| - $message = "That username is taken, try another."; |
83 |
| - break; |
84 |
| - case "EMAIL_FAILURE": |
85 |
| - $af = "email"; |
86 |
| - $message = "Your account was created, but the email failed to send."; |
87 |
| - break; |
88 |
| - case "INTERNAL_ERROR": |
89 |
| - $af = null; |
90 |
| - $message = "An internal error occurred while processing your request. " |
91 |
| - . "Our staff have been notified of the issue. Try again later."; |
92 |
| - break; |
93 |
| - default: |
94 |
| - $af = null; |
95 |
| - $message = $this->getContext()->error; |
| 8 | +$error = $this->getContext()->error; |
| 9 | +$error_extra = $this->getContext()->error_extra; |
| 10 | +switch ($error) |
| 11 | +{ |
| 12 | + case null: $af = 'email'; $message = null; break; |
| 13 | + case 'ALREADY_LOGGED_IN': $af = null; $message = 'You are already logged in, you must log out first.'; break; |
| 14 | + case 'INVALID_CAPTCHA': $af = ''; $message = 'The captcha code did not successfully verify, try again.'; break; |
| 15 | + case 'NONMATCHING_PASSWORD': $af = 'pw1'; $message = 'The password does not match its confirmation.'; break; |
| 16 | + case 'INVALID_EMAIL': $af = 'email'; $message = 'The email address is invalid.'; break; |
| 17 | + case 'EMAIL_NOT_ALLOWED': $af = 'email'; $message = 'The email address is not allowed, use a different one.'; break; |
| 18 | + case 'PASSWORD_CONTAINS_EMAIL': $af = 'pw1'; $message = 'The password contains the email address, use a better password.'; break; |
| 19 | + case 'PASSWORD_CONTAINS_USERNAME': $af = 'pw1'; $message = 'The password contains the username, use a better password.'; break; |
| 20 | + case 'USERNAME_TOO_LONG': $af = 'username'; $message = 'The username is too long, choose a different username.'; break; |
| 21 | + case 'USERNAME_TOO_SHORT': $af = 'username'; $message = 'The username is too short, choose a different username.'; break; |
| 22 | + case 'PASSWORD_TOO_LONG': $af = 'pw1'; $message = 'The password is too long, shorten it.'; break; |
| 23 | + case 'PASSWORD_TOO_SHORT': $af = 'pw1'; $message = 'The password is too short, use a better password.'; break; |
| 24 | + case 'PASSWORD_BLACKLIST': $af = 'pw1'; $message = $error_extra; if (empty($message)) $message = 'The password is blacklisted.'; break; |
| 25 | + case 'COUNTRY_DENIED': $af = null; $message = $error_extra; if (empty($message)) $message = 'Your country is blacklisted.'; break; |
| 26 | + case 'REGISTER_DISABLED': $af = null; $message = 'Creating accounts is currently administratively disabled.'; break; |
| 27 | + case 'EMAIL_ALREADY_USED': $af = 'email'; $message = 'The email address is already in use, use another.'; break; |
| 28 | + case 'USERNAME_TAKEN': $af = 'username'; $message = 'That username is taken, try another.'; break; |
| 29 | + case 'EMAIL_FAILURE': $af = 'email'; $message = 'Your account was created, but the email failed to send.'; break; |
| 30 | + case 'INTERNAL_ERROR': $af = null; $message = 'An internal error occurred while processing your request. Our staff have been notified of the issue. Try again later.'; break; |
| 31 | + default: $af = null; $message = $error; |
96 | 32 | }
|
97 |
| - |
98 |
| -$register_disabled = ($this->getContext()->error == 'REGISTER_DISABLED'); |
99 |
| - |
100 |
| -$safe_email = htmlentities($this->getContext()->email , ENT_HTML5, "UTF-8"); |
101 |
| -$safe_username = htmlentities($this->getContext()->username, ENT_HTML5, "UTF-8"); |
102 |
| - |
103 |
| -require("./header.inc.phtml"); |
104 |
| -?> |
105 |
| - <article> |
106 |
| -<?php if ($this->getContext()->error !== false) { ?> |
107 |
| - <script async defer="defer" src="https://www.google.com/recaptcha/api.js"><![CDATA[]]></script> |
108 |
| - <header<?=($register_disabled ? ' class="red"' : '')?>>Create Account</header> |
109 |
| -<?php if (!empty($message)) { ?> |
110 |
| - <section class="red"> |
111 |
| - <p><?php echo $message; ?></p> |
112 |
| - </section> |
113 |
| -<?php } ?> |
114 |
| -<?php if (!$register_disabled) { ?> |
115 |
| - <form method="POST" action="?"> |
116 |
| - <section> |
117 |
| - <table><tbody><tr> |
118 |
| - <td> |
119 |
| - <label for="email">Email address:</label><br/> |
120 |
| - <input type="email" name="email" id="email" tabindex="1" |
121 |
| - value="<?php echo $safe_email; ?>" required<?php if ($af == "email") { ?> autofocus="autofocus"<?php } ?>/> |
122 |
| - </td><td> |
123 |
| - <label for="username">Username:</label><br/> |
124 |
| - <input type="text" name="username" id="username" tabindex="2" maxlength="<?php echo $this->getContext()->username_max_len; ?>" |
125 |
| - value="<?php echo $safe_username; ?>" required<?php if ($af == "username") { ?> autofocus="autofocus"<?php } ?>/> |
126 |
| - </td></tr><tr><td> |
127 |
| - <label for="pw1">Password:</label><br/> |
128 |
| - <input type="password" name="pw1" id="pw1" tabindex="3" |
129 |
| - value="" required<?php if ($af == "pw1") { ?> autofocus="autofocus"<?php } ?>/> |
130 |
| - </td><td> |
131 |
| - <label for="pw2">Confirm password:</label><br/> |
132 |
| - <input type="password" name="pw2" id="pw2" tabindex="4" |
133 |
| - value="" required<?php if ($af == "pw2") { ?> autofocus="autofocus"<?php } ?>/> |
134 |
| - </td></tr><tr><td colspan="2"> |
135 |
| - <div class="g-recaptcha" data-theme="dark" data-sitekey="<?php echo $this->getContext()->recaptcha->site_key; ?>"></div> |
136 |
| - </td></tr><tr><td colspan="2" style="padding-top:16px;"> |
137 |
| - <input type="submit" value="Register" tabindex="5"/> |
138 |
| - </td> |
139 |
| - </tr></tbody></table> |
140 |
| - </section> |
141 |
| - </form> |
142 |
| -<?php } ?> |
143 |
| -<?php } else { ?> |
144 |
| - <header class="green">Account Created</header> |
145 |
| - <section class="green"> |
146 |
| - <p>You have successfully created an account!</p> |
147 |
| - <p>Use the navigation to the left to move to another page.</p> |
148 |
| - </section> |
149 |
| -<?php } ?> |
150 |
| - </article> |
151 |
| -<?php require("./footer.inc.phtml"); ?> |
| 33 | +$register_disabled = ($error == 'REGISTER_DISABLED'); |
| 34 | +$email = htmlentities($this->getContext()->email, ENT_HTML5, 'UTF-8'); |
| 35 | +$username = htmlentities($this->getContext()->username, ENT_HTML5, 'UTF-8'); |
| 36 | +require('./header.inc.phtml'); ?> |
| 37 | +<div class="container"> |
| 38 | + <script async defer="defer" src="https://www.google.com/recaptcha/api.js"><![CDATA[]]></script> |
| 39 | + <div class="card mx-auto mb-3" style="width:22rem;"> |
| 40 | + <h4 class="card-header text-center<?=($register_disabled ? ' text-danger' : '')?>"><?=$title?></h4> |
| 41 | + <div class="card-body"> |
| 42 | + <p><?=$description?></p> |
| 43 | + <p>Be sure to review our <a href="/privacy">privacy notice</a>.</p> |
| 44 | +<? if ($error !== false) { |
| 45 | + if (!empty($message)) { ?> |
| 46 | + <div class="alert alert-danger"><p class="mb-0"><?=$message?></p></div> |
| 47 | +<? } |
| 48 | + if (!$register_disabled) { ?> |
| 49 | + <form method="POST" action="?"> |
| 50 | + <div class="form-group"> |
| 51 | + <label class="font-weight-bold" for="email">Email address:</label> |
| 52 | + <input class="bg-dark border border-primary form-control text-light" type="email" name="email" id="email" placeholder="Enter the email address here" tabindex="1" value="<?=$email?>" required<?=($af == 'email' ? ' autofocus="autofocus"' : '')?>/> |
| 53 | + </div><div class="form-group"> |
| 54 | + <label class="font-weight-bold" for="username">Username:</label> |
| 55 | + <input class="bg-dark border border-primary form-control text-light" type="text" name="username" id="username" placeholder="Enter the username here" tabindex="2" maxlength="<?=$this->getContext()->username_max_len?>" value="<?=$username?>" required<?=($af == 'email' ? ' autofocus="autofocus"' : '')?>/> |
| 56 | + </div><div class="form-group"> |
| 57 | + <label class="font-weight-bold" for="pw1">Password:</label> |
| 58 | + <input class="bg-dark border border-primary form-control text-light" type="password" name="pw1" id="pw1" placeholder="Enter the password here" tabindex="3" |
| 59 | + value="" required<? if ($af == "pw1") { ?> autofocus="autofocus"<? } ?>/> |
| 60 | + </div><div class="form-group"> |
| 61 | + <label class="font-weight-bold" for="pw2">Confirm password:</label> |
| 62 | + <input class="bg-dark border border-primary form-control text-light" type="password" name="pw2" id="pw2" placeholder="Confirm the password here" tabindex="4" |
| 63 | + value="" required<? if ($af == "pw2") { ?> autofocus="autofocus"<? } ?>/> |
| 64 | + </div> |
| 65 | + <div class="form-group"> |
| 66 | + <div class="g-recaptcha" data-theme="dark" data-sitekey="<? echo $this->getContext()->recaptcha->site_key; ?>"></div> |
| 67 | + </div> |
| 68 | + <div class="form-group"> |
| 69 | + <input class="btn btn-success" type="submit" value="Register" tabindex="5"/> |
| 70 | + </div> |
| 71 | + </form> |
| 72 | +<? } |
| 73 | + } else { ?> |
| 74 | + <h1 class="text-success">Account Created</h1> |
| 75 | + <div class="alert alert-success"><p class="mb-0">You have successfully created an account!</p></div> |
| 76 | +<? } ?> |
| 77 | +</div> |
| 78 | +<? require('./footer.inc.phtml'); ?> |
0 commit comments