Less abrupt link errors.
This commit is contained in:
parent
3fde4fab90
commit
dd69e0a0ea
2 changed files with 39 additions and 6 deletions
|
@ -40,7 +40,30 @@ class ClientsRoutes {
|
|||
}
|
||||
}
|
||||
|
||||
public function getClients() {
|
||||
private const CLIENTS_ERRORS = [
|
||||
'link' => [
|
||||
'already' => 'You already have a linked Minecraft username, unlink the other one first.',
|
||||
'format' => 'The Link Code you entered was is not in the correct format, check your input!',
|
||||
'code' => 'The Link Code you entered is not valid, make sure you typed it correctly!',
|
||||
],
|
||||
];
|
||||
|
||||
public function getClients($response, $request) {
|
||||
$errorCode = (string)$request->getParam('error');
|
||||
if($errorCode !== '') {
|
||||
$errorCode = explode(':', $errorCode, 2);
|
||||
if(count($errorCode) === 2
|
||||
&& array_key_exists($errorCode[0], self::CLIENTS_ERRORS)
|
||||
&& array_key_exists($errorCode[1], self::CLIENTS_ERRORS[$errorCode[0]]))
|
||||
$this->templating->addVars([
|
||||
'error' => [
|
||||
'section' => $errorCode[0],
|
||||
'code' => $errorCode[1],
|
||||
'message' => self::CLIENTS_ERRORS[$errorCode[0]][$errorCode[1]],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$linkInfo = $this->accountLinks->getLink(userInfo: $this->authInfo->user_id);
|
||||
$clients = $this->authorisations->getAuthorisations($linkInfo);
|
||||
|
@ -55,20 +78,25 @@ class ClientsRoutes {
|
|||
}
|
||||
|
||||
public function postLink($response, $request) {
|
||||
if($this->accountLinks->checkHasLink($this->authInfo->user_id))
|
||||
return 403;
|
||||
if($this->accountLinks->checkHasLink($this->authInfo->user_id)) {
|
||||
$response->redirect('/clients?error=link:already');
|
||||
return;
|
||||
}
|
||||
|
||||
$body = $request->getContent();
|
||||
$code = (string)$body->getParam('code');
|
||||
if(strlen($code) !== 10)
|
||||
return 400;
|
||||
if(strlen($code) !== 10) {
|
||||
$response->redirect('/clients?error=link:format');
|
||||
return;
|
||||
}
|
||||
|
||||
$code = strtr(strtoupper($code), '0189', 'OIBG');
|
||||
|
||||
try {
|
||||
$verifyInfo = $this->verifications->getVerification(code: $code);
|
||||
} catch(RuntimeException $ex) {
|
||||
return 404;
|
||||
$response->redirect('/clients?error=link:code');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->verifications->deleteVerification($verifyInfo);
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
<div class="section acclink">
|
||||
<h2>Link a Minecraft account</h2>
|
||||
<p>This will associate a Minecraft username with your Flashii ID. You may only have one linked at a time. In order to obtain a link code, connect to one of the Minecraft servers.</p>
|
||||
|
||||
{% if error is defined and error.section == 'link' %}
|
||||
<p style="color: red;">{{ error.message }}</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="/clients/link">
|
||||
<input type="hidden" name="csrfp" value="{{ csrfp }}">
|
||||
<label>
|
||||
|
|
Loading…
Reference in a new issue