Guest User

Untitled

a guest
Jan 12th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2. namespace Application\Authentication\Example;
  3.  
  4. use Concrete\Core\Authentication\AuthenticationTypeController;
  5. use Concrete\Core\Authentication\AuthenticationTypeFailureException;
  6. use Concrete\Core\User\User;
  7.  
  8. class Controller extends AuthenticationTypeController
  9. {
  10. public function getAuthenticationTypeIconHTML()
  11. {
  12. return "<i class='fa fa-bug'></i>";
  13. }
  14.  
  15. public function view()
  16. {
  17. // blank
  18. }
  19.  
  20. /**
  21. * @return string
  22. */
  23. public function getHandle()
  24. {
  25. return 'example';
  26. }
  27.  
  28. /**
  29. * Method used to verify the user and log them in.
  30. * Returning user will cause finishAuthentication to run, otherwise it's expected that the subclass manage completion.
  31. *
  32. * @throws AuthenticationTypeFailureException
  33. *
  34. * @return \User|null
  35. */
  36. public function authenticate()
  37. {
  38. $password = $this->post('password');
  39.  
  40. // If the password matches
  41. if ($password == 'foo') {
  42. $user = User::loginByUserID(1);
  43. } else {
  44. throw new \Exception('Invalid password.');
  45. }
  46.  
  47. return $user;
  48. }
  49.  
  50. /**
  51. * Method used to clean up.
  52. * This method must be defined, if it isn't needed, leave it blank.
  53. *
  54. * @param \User $u
  55. */
  56. public function deauthenticate(User $u)
  57. {
  58. // blank
  59. }
  60.  
  61. /**
  62. * Test user authentication status.
  63. *
  64. * @param \User $u
  65. *
  66. * @return bool Returns true if user is authenticated, false if not
  67. */
  68. public function isAuthenticated(User $u)
  69. {
  70. return $u->isLoggedIn();
  71. }
  72.  
  73. /**
  74. * Create a cookie hash to identify the user indefinitely.
  75. *
  76. * @param \User $u
  77. *
  78. * @return string Unique hash to be used to verify the users identity
  79. */
  80. public function buildHash(User $u)
  81. {
  82. return '';
  83. }
  84.  
  85. /**
  86. * Verify cookie hash to identify user.
  87. *
  88. * @param $u User object requesting verification.
  89. * @param string $hash
  90. *
  91. * @return bool returns true if the hash is valid, false if not
  92. */
  93. public function verifyHash(User $u, $hash)
  94. {
  95. return true;
  96. }
  97. }
Add Comment
Please, Sign In to add comment