Drupal investigation

TestUsers.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use \yii\db\ActiveRecord;
  5. use \yii\web\IdentityInterface;
  6. /**
  7. * This is the model class for table "testUsers".
  8. *
  9. * @property integer $id
  10. * @property string $username
  11. * @property string $forename
  12. * @property string $surname
  13. * @property string $email
  14. * @property string $lang
  15. * @property string $phone
  16. * @property string $accessToken
  17. * @property string $authKey
  18. * @property string $password
  19. */
  20. class TestUsers extends ActiveRecord implements IdentityInterface
  21. {
  22. /**
  23. * @inheritdoc
  24. */
  25. public static function tableName()
  26. {
  27. return 'testUsers';
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['username', 'accessToken', 'authKey', 'password'], 'required'],
  36. [['username', 'forename', 'surname', 'email', 'phone'], 'string', 'max' => 32],
  37. [['accessToken', 'authKey', 'password'], 'string', 'max' => 100],
  38. [['lang'], 'string', 'max' => 10],
  39. ];
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => Yii::t('app', 'ID'),
  48. 'username' => Yii::t('app', 'Username'),
  49. 'forename' => Yii::t('app', 'Forename'),
  50. 'surname' => Yii::t('app', 'Surname'),
  51. 'email' => Yii::t('app', 'Email'),
  52. 'phone' => Yii::t('app', 'Phone'),
  53. 'lang' => Yii::t('app', 'Language'),
  54. 'accessToken' => Yii::t('app', 'Access Token'),
  55. 'authKey' => Yii::t('app', 'Auth Key'),
  56. 'password' => Yii::t('app', 'Password'),
  57. ];
  58. }
  59. /**
  60. * @return string
  61. */
  62. public function getAuthKey()
  63. {
  64. return $this->authKey;
  65. }
  66. /**
  67. * @return int
  68. */
  69. public function getId()
  70. {
  71. return $this->id;
  72. }
  73. public function validateAuthKey($authKey){
  74. return $this->authKey === $authKey;
  75. }
  76. public static function findIdentity($id){
  77. return self::findOne($id);
  78. }
  79. public static function findIdentityByAccessToken($token, $type = null){
  80. //throw new \yii\base\NotSupportedException();
  81. return self::findOne(['access_token' => $token]);
  82. }
  83. public static function findByUsername($username){
  84. return self::findOne(['username'=>$username]);
  85. }
  86. public function validatePassword($password){
  87. return $this->password === $password;
  88. }
  89. /**
  90. * @param string $phone
  91. */
  92. public function setPhone($phone)
  93. {
  94. $this->phone = $phone;
  95. }
  96. public function setEmail($email)
  97. {
  98. $this->email = $email;
  99. }
  100. /**
  101. * @return string
  102. */
  103. public function getEmail()
  104. {
  105. return $this->email;
  106. }
  107. /**
  108. * @return string
  109. */
  110. public function getPhone()
  111. {
  112. return $this->phone;
  113. }
  114. }