user.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. /**
  3. * Class User
  4. *
  5. * @property int $id
  6. * @property string $email
  7. * @property int $old_id
  8. * @property int $referrer_id
  9. * @property string $password
  10. * @property bool $activated
  11. * @property int $level
  12. * @property int $score
  13. * @property string $title
  14. * @property string $first_name
  15. * @property string $last_name
  16. * @property string $gender
  17. * @property string $date_of_birth
  18. * @property string $locale
  19. * @property bool $reported
  20. * @property string $reported_comment
  21. * @property bool $can_claim
  22. * @property string $phone
  23. * @property string $verify_token
  24. * @property string $reset_token
  25. * @property bool $terms_accepted
  26. * @property bool $newsletter_consent
  27. * @property int $preferred_payment_method
  28. * @property string $bank_name
  29. * @property string $bank_sort_code
  30. * @property string $bank_account_number
  31. * @property string $paypal_email
  32. * @property string $dts_registered
  33. * @property string $dts_last_seen
  34. * @property string $dts_verified
  35. * @property string $dts_deleted
  36. * @property int $verifier_id
  37. * @property string $verifier_notes
  38. */
  39. class User extends Model {
  40. protected static $table = "user";
  41. protected static $id_field = "id";
  42. protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "locale", "reported", "reported_comment", "can_claim", "phone", "verify_token", "reset_token", "terms_accepted", "newsletter_consent", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
  43. // Constants
  44. const LEVEL_BANNED = 0;
  45. const LEVEL_REGISTERED = 1;
  46. const LEVEL_UNVERIFIED = 2;
  47. const LEVEL_DEACTIVATED = 4;
  48. const LEVEL_TESTER = 8;
  49. const LEVEL_VENUE = 16;
  50. const LEVEL_CUSTOMER = 32;
  51. const LEVEL_TESTER_MANAGER = 48;
  52. const LEVEL_ADMIN = 64;
  53. const LEVEL_SUPERADMIN = 128;
  54. const LEVELS = [
  55. 0 => "Banned",
  56. 1 => "Registered",
  57. 2 => "Unverified",
  58. 4 => "Deactivated",
  59. 8 => "Tester",
  60. 16 => "Venue",
  61. 32 => "Customer",
  62. 48 => "Tester Manager",
  63. 64 => "Admin",
  64. 128 => "Super Admin",
  65. ];
  66. const PAYMENT_METHOD_BANK_TRANSFER = 1;
  67. const PAYMENT_METHOD_PAYPAL = 2;
  68. const PAYMENT_METHODS = [
  69. 1 => "Bank Transfer",
  70. 2 => "PayPal",
  71. ];
  72. // Static methods
  73. /**
  74. * @return array
  75. */
  76. public static function titles(): array {
  77. return [
  78. "Miss" => MISS,
  79. "Mr" => MR,
  80. "Ms" => MS,
  81. "Dr" => DR
  82. ];
  83. }
  84. /**
  85. * @return array
  86. */
  87. public static function genders(): array {
  88. return [
  89. "Female" => FEMALE,
  90. "Male" => MALE,
  91. "Unspecified" => UNSPECIFIED
  92. ];
  93. }
  94. /**
  95. * @param string $password
  96. * @return bool
  97. */
  98. public static function validatePassword(string $password): bool {
  99. $lowercase = preg_match("/[a-z]/", $password);
  100. $uppercase = preg_match("/[A-Z]/", $password);
  101. $number = preg_match("/[0-9]/", $password);
  102. $special = preg_match("/[^0-9a-zA-Z]/", $password);
  103. $length = strlen($password) >= 6;
  104. return ($lowercase && $uppercase && $number && $special && $length);
  105. }
  106. // Object methods
  107. /**
  108. * @return bool
  109. */
  110. public function hasValidPaymentMethod(): bool {
  111. switch($this->preferred_payment_method) {
  112. case User::PAYMENT_METHOD_BANK_TRANSFER: {
  113. if(empty($this->bank_name)) return false;
  114. if(empty($this->bank_sort_code)) return false;
  115. if(empty($this->bank_account_number)) return false;
  116. break;
  117. }
  118. case User::PAYMENT_METHOD_PAYPAL: {
  119. if(empty($this->paypal_email)) return false;
  120. break;
  121. }
  122. }
  123. return true;
  124. }
  125. /**
  126. * @return bool
  127. * @throws Exception
  128. */
  129. public function sendActivationEmail() {
  130. $this->verify_token = bin2hex(random_bytes(16));
  131. $this->commit();
  132. // Content
  133. $name = htmlspecialchars($this->first_name);
  134. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/verify-email/" . $this->verify_token);
  135. // Build
  136. $builder = new EmailBuilder;
  137. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  138. $builder->addLeadParagraph(__("Thanks for registering!"));
  139. $builder->addParagraph(sprintf(__("Welcome to %s! Before you can log in, you will need to verify your email address. You can do so by tapping the following link:"), APP_NAME));
  140. $builder->addParagraph("<a href=\"$link\">$link</a>");
  141. $content = $builder->build();
  142. // Send
  143. $mail = new Email;
  144. $mail->setHtmlContent($content);
  145. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  146. $mail->addAddress($this->email, $this->getDisplayName());
  147. $mail->setSubject(__("Verify your email address"));
  148. $mail->send();
  149. return true;
  150. }
  151. /**
  152. * @return bool
  153. * @throws Exception
  154. */
  155. public function sendWelcomeEmail() {
  156. // Content
  157. $name = htmlspecialchars($this->first_name);
  158. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/account/submit-id");
  159. // Build
  160. $builder = new EmailBuilder;
  161. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  162. $builder->addLeadParagraph(__("Thanks for verifying your email address!"));
  163. $builder->addParagraph(sprintf(__("Welcome to %s! Before you can take part in tests, you will need to provide us with some ID. You can do so by tapping the following link:"), APP_NAME));
  164. $builder->addParagraph("<a href=\"$link\">$link</a>");
  165. $content = $builder->build();
  166. // Send
  167. $mail = new Email;
  168. $mail->setHtmlContent($content);
  169. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  170. $mail->addAddress($this->email, $this->getDisplayName());
  171. $mail->setSubject(sprintf(__("Welcome to %s"), APP_NAME));
  172. $mail->send();
  173. return true;
  174. }
  175. /**
  176. * @return bool
  177. * @throws Exception
  178. */
  179. public function sendIDPassEmail() {
  180. // Content
  181. $name = htmlspecialchars($this->first_name);
  182. // Build
  183. $builder = new EmailBuilder;
  184. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  185. $builder->addLeadParagraph(__("Your application has been successful!"));
  186. $builder->addParagraph(sprintf(__("Welcome to %s! In order to get you a test as soon as possible, we need one final confirmation. Please log in to your account and have a quick read of the documents that explain what we need you to do during a test."), APP_NAME));
  187. $builder->addParagraph(__("When you're ready to try a Practice test, in your account and select the \"Practice\" option."));
  188. $builder->addParagraph(__("1. As it is a Practice test, you can reset and start over as many times as you like because it doesn't count but lets you see what the real thing is like."));
  189. $builder->addParagraph(sprintf(__("2. Email us at %s and let us know that you're ready."), "contact@" . DOMAIN));
  190. $builder->addParagraph(__("3. We will allocate a test to you as soon as possible."));
  191. $builder->addParagraph(__("Remember to check your online account for when tests become available."));
  192. $builder->addParagraph(__("Keep an eye out for emails inviting you to accept a test via the email or log in to your account where you can see your available tests."));
  193. $builder->addParagraph(__("If you accept to do a test within the agreed period (usually 7 days) please click Accept to confirm that you would like to do the test within the agreed period."));
  194. $builder->addParagraph(__("If you can't make it (it's too far or you'll be away), please Reject the test or email us with other suitable dates."));
  195. $builder->addParagraph(__("After you click Accept, you will be given the option to Begin the test whenever you want. Just log in to your account and click Begin on the test."));
  196. $builder->addParagraph(sprintf(__("Once again welcome to %s - Accept, Begin, Complete and get paid for up to 8 minutes work!"), APP_NAME));
  197. $content = $builder->build();
  198. // Send
  199. $mail = new Email;
  200. $mail->setHtmlContent($content);
  201. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  202. $mail->addAddress($this->email, $this->getDisplayName());
  203. $mail->setSubject(__("ID accepted and verified"));
  204. $mail->send();
  205. return true;
  206. }
  207. /**
  208. * @param string $reason
  209. * @return bool
  210. * @throws Exception
  211. */
  212. public function sendIDFailEmail($reason = "No reason given.") {
  213. // Content
  214. $name = htmlspecialchars($this->first_name);
  215. $reason = htmlspecialchars($reason);
  216. // Build
  217. $builder = new EmailBuilder;
  218. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  219. $builder->addLeadParagraph(__("Thank you for submitting your ID details."));
  220. $builder->addParagraph(__("Unfortunately we could not verify and accept your documents and/or image."));
  221. $builder->addParagraph(sprintf(__("The reason for this is: %s"), $reason));
  222. $builder->addParagraph(__("Please log in again, resubmit and we will try again."));
  223. $builder->addParagraph(__("We look forward to welcoming you onboard soon!"));
  224. $content = $builder->build();
  225. // Send
  226. $mail = new Email;
  227. $mail->setHtmlContent($content);
  228. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  229. $mail->addAddress($this->email, $this->getDisplayName());
  230. $mail->setSubject(__("We could not verify your ID details"));
  231. $mail->send();
  232. return true;
  233. }
  234. /**
  235. * @return bool
  236. * @throws Exception
  237. */
  238. public function sendPasswordResetEmail() {
  239. $this->reset_token = bin2hex(random_bytes(16));
  240. $this->commit();
  241. // Content
  242. $name = htmlspecialchars($this->first_name);
  243. $link = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/reset-password/" . $this->reset_token);
  244. // Build
  245. $builder = new EmailBuilder;
  246. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  247. $builder->addLeadParagraph(__("A reset password request has been received."));
  248. $builder->addParagraph(__("To reset your password, please tap on the following link:"));
  249. $builder->addParagraph("<a href=\"$link\">$link</a>");
  250. $builder->addParagraph(sprintf(__("If you %sdid not%s request for your password to be reset, please ignore this email."), '<strong>', '</strong>'));
  251. $content = $builder->build();
  252. // Send
  253. $mail = new Email;
  254. $mail->setHtmlContent($content);
  255. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  256. $mail->addAddress($this->email, $this->getDisplayName());
  257. $mail->setSubject(__("Password reset instructions"));
  258. $mail->send();
  259. return true;
  260. }
  261. /**
  262. * @return bool
  263. * @throws Exception
  264. */
  265. public function sendDocumentationEmail(): bool {
  266. // Content
  267. $name = htmlspecialchars($this->first_name);
  268. // Build
  269. $builder = new EmailBuilder;
  270. $builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
  271. $builder->addLeadParagraph(__("Thanks for registering with us!"));
  272. $builder->addParagraph(__("The good news is that we have tests for you straight away."));
  273. $builder->addParagraph(__("We are testing if you are asked for ID in a pubs and also in amusement arcades before playing a slot machine. I have attached two documents with the test protocol for you to read and we will assign you the tests. Take a look at the protocol and let us know when you are ready."));
  274. $content = $builder->build();
  275. // Send
  276. $mail = new Email;
  277. $mail->setHtmlContent($content);
  278. $mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
  279. $mail->addAddress($this->email, $this->getDisplayName());
  280. $mail->addAttachment("public/files/testing_procedure_arcades.pdf", "Testing Procedure - Arcades.pdf");
  281. $mail->addAttachment("public/files/testing_procedure_pubs.pdf", "Testing Procedure - Pubs.pdf");
  282. $mail->setSubject(__("Documentation"));
  283. return $mail->send();
  284. }
  285. /**
  286. * @return bool
  287. */
  288. public function canAdmin() {
  289. return $this->isAdmin();
  290. }
  291. /**
  292. * @return User|null
  293. * @throws Exception
  294. */
  295. public function getReferrer(): ?User {
  296. return is_null($this->referrer_id) ? null : User::get($this->referrer_id);
  297. }
  298. public function getDirectory() {
  299. $directory = ROOT_DIR . "/files/users/" . $this->id;
  300. if(!file_exists($directory)) mkdir($directory, 0777, true);
  301. return $directory;
  302. }
  303. public function getLevelText() {
  304. return User::LEVELS[$this->level];
  305. }
  306. public function getLevelClass() {
  307. switch($this->level) {
  308. case User::LEVEL_BANNED: return "danger";
  309. case User::LEVEL_REGISTERED: return "secondary";
  310. case User::LEVEL_UNVERIFIED: return "warning";
  311. case User::LEVEL_DEACTIVATED: return "secondary";
  312. case User::LEVEL_TESTER: return "success";
  313. case User::LEVEL_VENUE: return "info";
  314. case User::LEVEL_CUSTOMER: return "info";
  315. case User::LEVEL_ADMIN: return "info";
  316. case User::LEVEL_SUPERADMIN: return "info";
  317. default:
  318. return "primary";
  319. }
  320. }
  321. public function isAdmin(): bool {
  322. return $this->level >= User::LEVEL_ADMIN;
  323. }
  324. public function isCustomer(): bool {
  325. return $this->level == User::LEVEL_CUSTOMER;
  326. }
  327. public function isTester(): bool {
  328. return $this->level == User::LEVEL_TESTER;
  329. }
  330. public function isDeactivated(): bool {
  331. return $this->level == User::LEVEL_DEACTIVATED;
  332. }
  333. public function getGenderText(): string {
  334. if($this->gender == "M") return MALE;
  335. if($this->gender == "F") return FEMALE;
  336. return "Unspecified";
  337. }
  338. /**
  339. * @return int|string
  340. * @throws Exception
  341. */
  342. public function getAge() {
  343. if(is_null($this->date_of_birth)) return __("N/A");
  344. $now = new DateTime("now");
  345. $dob = new DateTime($this->date_of_birth);
  346. return $dob->diff($now)->y;
  347. }
  348. public function getDisplayName() {
  349. if(empty($this->email)) return __("Deleted User");
  350. $parts = array_filter([$this->first_name, $this->last_name]);
  351. return implode(" ", $parts);
  352. }
  353. /**
  354. * @param $object
  355. * @return bool
  356. * @throws Exception
  357. */
  358. public function hasPermission($object): bool {
  359. if($this->canAccessLocations()) return true;
  360. $customers = $this->getCustomers();
  361. $customer_ids = array_column($customers, "id");
  362. if($object instanceof Customer) {
  363. return in_array($object->id, $customer_ids);
  364. }
  365. if($object instanceof Location) {
  366. return in_array($object->customer_id, $customer_ids);
  367. }
  368. if($object instanceof Project) {
  369. return in_array($object->customer_id, $customer_ids);
  370. }
  371. if($object instanceof Template) {
  372. return in_array($object->customer_id, $customer_ids);
  373. }
  374. return false;
  375. }
  376. /**
  377. * @return bool
  378. * @throws Exception
  379. */
  380. public function deactivate() {
  381. // Decline all pending tests
  382. $pending_tests = $this->getPendingTests();
  383. foreach($pending_tests as $test) {
  384. $test->decline();
  385. }
  386. // Set user level to Deactivated
  387. $this->level = User::LEVEL_DEACTIVATED;
  388. return $this->commit();
  389. }
  390. /**
  391. * @return bool
  392. * @throws Exception
  393. */
  394. public function softDelete(): bool {
  395. // Delete identification documents
  396. $this->deleteIDFiles();
  397. // Delete addresses
  398. $this->deleteAddresses();
  399. // Decline all pending tests
  400. $pending_tests = $this->getPendingTests();
  401. foreach($pending_tests as $test) {
  402. $test->decline();
  403. }
  404. // Delete personal information
  405. $this->email = null;
  406. $this->title = null;
  407. $this->first_name = null;
  408. $this->last_name = null;
  409. $this->phone = null;
  410. $this->bank_name = null;
  411. $this->bank_sort_code = null;
  412. $this->bank_account_number = null;
  413. $this->paypal_email = null;
  414. // Set deleted time
  415. $this->dts_deleted = Util::getDateTime();
  416. return $this->commit();
  417. }
  418. /**
  419. * @return bool
  420. * @throws Exception
  421. */
  422. public function deleteIDFiles(): bool {
  423. $files = UserFile::query([
  424. "user_id" => $this->id,
  425. "type" => [UserFile::TYPE_ID, UserFile::TYPE_PHOTO]
  426. ]);
  427. foreach($files as $file) {
  428. $path = $this->getDirectory() . "/" . $file->id . ".jpg";
  429. if(file_exists($path)) unlink($path);
  430. $file->delete();
  431. }
  432. return true;
  433. }
  434. /**
  435. * @return bool
  436. * @throws Exception
  437. */
  438. public function deleteAddresses(): bool {
  439. $addresses = $this->getAddresses();
  440. foreach($addresses as $address) {
  441. $address->delete();
  442. }
  443. return true;
  444. }
  445. /**
  446. * @return UserAddress[]
  447. * @throws Exception
  448. */
  449. public function getAddresses(): array {
  450. $addresses = UserAddress::query([
  451. "user_id" => $this->id,
  452. ], [
  453. "sort" => "name"
  454. ]);
  455. return $addresses;
  456. }
  457. /**
  458. * @return UserAddress|null
  459. * @throws Exception
  460. */
  461. public function getInvoiceAddress(): ?UserAddress {
  462. $addresses = UserAddress::query([
  463. "user_id" => $this->id,
  464. ]);
  465. foreach($addresses as $address) {
  466. if($address->invoice) return $address;
  467. }
  468. // If only one address in account, just return it
  469. if(count($addresses) == 1) return array_shift($addresses);
  470. return null;
  471. }
  472. /**
  473. * @return Customer[]
  474. * @throws Exception
  475. */
  476. public function getCustomers() {
  477. if($this->canAccessCustomers()) {
  478. return Customer::query([], ["sort" => "name"]);
  479. }
  480. if($this->isCustomer()) {
  481. $links = UserCustomer::query(["user_id" => $this->id]);
  482. return Customer::query([
  483. "id" => array_column($links, "customer_id")
  484. ], ["sort" => "name"]);
  485. }
  486. return [];
  487. }
  488. /**
  489. * @return Test[]
  490. * @throws Exception
  491. */
  492. public function getPendingTests(): array {
  493. return Test::query([
  494. "tester_id" => $this->id,
  495. "status" => [Test::STATUS_ASSIGNED, Test::STATUS_CONFIRMED, Test::STATUS_STARTED, Test::STATUS_PENDING_VERIFICATION],
  496. ], [
  497. "sort" => "dts_assigned",
  498. "order" => "desc"
  499. ]);
  500. }
  501. /**
  502. * @return Test[]
  503. * @throws Exception
  504. */
  505. public function getCompletedTests(): array {
  506. return Test::query([
  507. "tester_id" => $this->id,
  508. "status" => [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED],
  509. ], [
  510. "sort" => "dts_start",
  511. "order" => "desc"
  512. ]);
  513. }
  514. /**
  515. * @return User[]
  516. * @throws Exception
  517. */
  518. public function getReferrals(): array {
  519. return User::query([
  520. "referrer_id" => $this->id
  521. ]);
  522. }
  523. /**
  524. * @return string
  525. */
  526. public function getPreferredPaymentMethodText(): string {
  527. return User::PAYMENT_METHODS[$this->preferred_payment_method];
  528. }
  529. /**
  530. * @return string
  531. */
  532. public function getURL(): string {
  533. return "/account/users/{$this->id}";
  534. }
  535. public function isUnverified() {
  536. return $this->level == User::LEVEL_UNVERIFIED;
  537. }
  538. public function isRegistered() {
  539. return $this->level == User::LEVEL_REGISTERED;
  540. }
  541. public function isSuperAdmin(): bool {
  542. return $this->level == User::LEVEL_SUPERADMIN;
  543. }
  544. public function canAccessCustomers(): bool {
  545. return $this->level >= User::LEVEL_TESTER_MANAGER;
  546. }
  547. public function canAccessMapOverview(): bool {
  548. return $this->level >= User::LEVEL_TESTER_MANAGER;
  549. }
  550. public function canAccessUsers(): bool {
  551. return $this->level >= User::LEVEL_TESTER_MANAGER;
  552. }
  553. public function canAccessProjects(): bool {
  554. return $this->level >= User::LEVEL_TESTER_MANAGER;
  555. }
  556. public function canAccessTemplates(): bool {
  557. return $this->level >= User::LEVEL_ADMIN;
  558. }
  559. public function canAccessVenueTypes(): bool {
  560. return $this->level >= User::LEVEL_ADMIN;
  561. }
  562. public function canAccessInvoices(): bool {
  563. return $this->level >= User::LEVEL_ADMIN;
  564. }
  565. public function canAccessLog(): bool {
  566. return $this->level >= User::LEVEL_ADMIN;
  567. }
  568. public function canAccessLocations(): bool {
  569. return $this->level >= User::LEVEL_CUSTOMER;
  570. }
  571. public function canAccessReports(): bool {
  572. return $this->level >= User::LEVEL_CUSTOMER;
  573. }
  574. public function canAccessTestResults(): bool {
  575. return $this->level >= User::LEVEL_CUSTOMER;
  576. }
  577. public function canAccessTests(): bool {
  578. return $this->isTester() || $this->isAdmin();
  579. }
  580. public function canAccessPractice(): bool {
  581. return $this->isTester() || $this->isAdmin() || $this->isUnverified() || $this->isRegistered();
  582. }
  583. public function canAccessAddresses(): bool {
  584. return $this->level == User::LEVEL_TESTER;
  585. }
  586. public function canAccessCompletedTests(): bool {
  587. return $this->level == User::LEVEL_TESTER;
  588. }
  589. public function canSubmitId(): bool {
  590. return $this->level == User::LEVEL_REGISTERED;
  591. }
  592. public function canDeactivate(): bool {
  593. return $this->level == User::LEVEL_TESTER;
  594. }
  595. public function canReactivate(): bool {
  596. return $this->level == User::LEVEL_DEACTIVATED;
  597. }
  598. public function canAccessAdminTestsList(): bool {
  599. return $this->level >= User::LEVEL_TESTER_MANAGER;
  600. }
  601. public function canExportProjectCsv(): bool {
  602. return $this->isAdmin();
  603. }
  604. public function canVerifyTests(): bool {
  605. return $this->level >= User::LEVEL_TESTER_MANAGER;
  606. }
  607. public function canAccessTestResult(): bool {
  608. return $this->level >= User::LEVEL_VENUE;
  609. }
  610. public function canEditUsers(): bool {
  611. return $this->isAdmin();
  612. }
  613. }