Skip to content

Commit

Permalink
Add verification token generator
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Aug 23, 2019
1 parent c8ff176 commit a2d4b3f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/libraries/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class User implements JsonSerializable {
const OPTION_ACL_USER_MODIFY = 0x00200000;
const OPTION_ACL_USER_DELETE = 0x00400000;

const VERIFICATION_TOKEN_TTL = 86400;

protected $created_datetime;
protected $display_name;
protected $email;
Expand Down Expand Up @@ -499,6 +501,23 @@ public function getUsername() {
return $this->username;
}

public function getVerificationToken() {
$key = 'bnetdocs-userverify-' . $this->id;
$value = Common::$cache->get($key);

if ($value === false) {
$gmp = gmp_init(microtime(true)*10000);
$gmp = gmp_mul($gmp, mt_rand());
$gmp = gmp_mul($gmp, gmp_random_bits(64));

$value = hash('sha256', gmp_strval($gmp, 36));

Common::$cache->set($key, $value, self::VERIFICATION_TOKEN_TTL);
}

return $value;
}

public function getVerifiedDateTime() {
if (is_null($this->verified_datetime)) {
return $this->verified_datetime;
Expand All @@ -510,6 +529,11 @@ public function getVerifiedDateTime() {
}
}

public function invalidateVerificationToken() {
$key = 'bnetdocs-userverify-' . $this->id;
return Common::$cache->delete($key);
}

public function isStaff() {
return ($this->options_bitmask & (
self::OPTION_ACL_DOCUMENT_CREATE |
Expand Down

0 comments on commit a2d4b3f

Please sign in to comment.