Skip to content

Commit a2d4b3f

Browse files
committed
Add verification token generator
1 parent c8ff176 commit a2d4b3f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libraries/User.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class User implements JsonSerializable {
4545
const OPTION_ACL_USER_MODIFY = 0x00200000;
4646
const OPTION_ACL_USER_DELETE = 0x00400000;
4747

48+
const VERIFICATION_TOKEN_TTL = 86400;
49+
4850
protected $created_datetime;
4951
protected $display_name;
5052
protected $email;
@@ -499,6 +501,23 @@ public function getUsername() {
499501
return $this->username;
500502
}
501503

504+
public function getVerificationToken() {
505+
$key = 'bnetdocs-userverify-' . $this->id;
506+
$value = Common::$cache->get($key);
507+
508+
if ($value === false) {
509+
$gmp = gmp_init(microtime(true)*10000);
510+
$gmp = gmp_mul($gmp, mt_rand());
511+
$gmp = gmp_mul($gmp, gmp_random_bits(64));
512+
513+
$value = hash('sha256', gmp_strval($gmp, 36));
514+
515+
Common::$cache->set($key, $value, self::VERIFICATION_TOKEN_TTL);
516+
}
517+
518+
return $value;
519+
}
520+
502521
public function getVerifiedDateTime() {
503522
if (is_null($this->verified_datetime)) {
504523
return $this->verified_datetime;
@@ -510,6 +529,11 @@ public function getVerifiedDateTime() {
510529
}
511530
}
512531

532+
public function invalidateVerificationToken() {
533+
$key = 'bnetdocs-userverify-' . $this->id;
534+
return Common::$cache->delete($key);
535+
}
536+
513537
public function isStaff() {
514538
return ($this->options_bitmask & (
515539
self::OPTION_ACL_DOCUMENT_CREATE |

0 commit comments

Comments
 (0)