-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from chesslablab/issue/370-Update-the-ELO-of-…
…the-players Issue/370 update the elo of the players
- Loading branch information
Showing
10 changed files
with
246 additions
and
109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace ChessServer\Command\Data; | ||
|
||
use ChessServer\Command\AbstractCommand; | ||
use ChessServer\Command\Db; | ||
use ChessServer\Socket\AbstractSocket; | ||
use Firebase\JWT\JWT; | ||
use Firebase\JWT\Key; | ||
|
||
class TotpRefreshCommand extends AbstractCommand | ||
{ | ||
public function __construct(Db $db) | ||
{ | ||
parent::__construct($db); | ||
|
||
$this->name = '/totp_refresh'; | ||
$this->description = 'Refresh the TOTP access token.'; | ||
$this->params = [ | ||
'params' => '<string>', | ||
]; | ||
} | ||
|
||
public function validate(array $argv) | ||
{ | ||
return count($argv) - 1 === count($this->params); | ||
} | ||
|
||
public function run(AbstractSocket $socket, array $argv, int $id) | ||
{ | ||
$params = json_decode(stripslashes($argv[1]), true); | ||
|
||
if (isset($params['access_token'])) { | ||
$decoded = JWT::decode($params['access_token'], new Key($_ENV['JWT_SECRET'], 'HS256')); | ||
$sql = "SELECT * FROM users WHERE username = :username"; | ||
$values[] = [ | ||
'param' => ":username", | ||
'value' => $decoded->username, | ||
'type' => \PDO::PARAM_STR, | ||
]; | ||
$arr = $this->db->query($sql, $values)->fetch(\PDO::FETCH_ASSOC); | ||
$payload = [ | ||
'iss' => $_ENV['JWT_ISS'], | ||
'iat' => time(), | ||
'exp' => time() + 3600, // one hour by default | ||
'username' => $arr['username'], | ||
'elo' => $arr['elo'], | ||
]; | ||
return $socket->getClientStorage()->sendToOne($id, [ | ||
$this->name => [ | ||
'access_token' => JWT::encode($payload, $_ENV['JWT_SECRET'], 'HS256'), | ||
], | ||
]); | ||
} | ||
|
||
return $socket->getClientStorage()->sendToOne($id, [ | ||
$this->name => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters