User.php 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace fphammerle\yii2\auth\clientcert\tests\models;
  3. class User extends \yii\db\ActiveRecord
  4. implements \yii\web\IdentityInterface
  5. {
  6. public static function tableName()
  7. {
  8. return 'user';
  9. }
  10. public function __construct($username = null)
  11. {
  12. $this->username = $username;
  13. }
  14. public static function findIdentity($id)
  15. {
  16. return static::findOne(['id' => $id]);
  17. }
  18. public static function findIdentityByAccessToken($token, $type = null)
  19. {
  20. throw new NotSupportedException();
  21. }
  22. public function getId()
  23. {
  24. return $this->primaryKey;
  25. }
  26. public function getAuthKey()
  27. {
  28. return sprintf('auth-key-%d', $this->id);
  29. }
  30. public function validateAuthKey($authKey)
  31. {
  32. return $this->getAuthKey() === $authKey;
  33. }
  34. }