user_openid.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2011 Robin Appelman icewind1991gmailc.om
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. require_once('class.openid.v3.php');
  23. /**
  24. * Class for user management in a SQL Database (e.g. MySQL, SQLite)
  25. */
  26. class OC_USER_OPENID extends OC_User_Backend {
  27. /**
  28. * @brief Check if the password is correct
  29. * @param $uid The username
  30. * @param $password The password
  31. * @returns true/false
  32. *
  33. * Check if the password is correct without logging in the user
  34. */
  35. public function checkPassword( $uid, $password ){
  36. // Get identity from user and redirect browser to OpenID Server
  37. $openid = new SimpleOpenID;
  38. $openid->SetIdentity($uid);
  39. $openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
  40. if ($openid->GetOpenIDServer()){
  41. $openid->SetApprovedURL('http://' . $_SERVER["HTTP_HOST"] . OC::$WEBROOT); // Send Response from OpenID server to this script
  42. $openid->Redirect(); // This will redirect user to OpenID Server
  43. exit;
  44. }else{
  45. return false;
  46. }
  47. exit;
  48. }
  49. /**
  50. * find the user that can be authenticated with an openid identity
  51. */
  52. public static function findUserForIdentity($identity){
  53. $query=OCP\DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?');
  54. $result=$query->execute(array('user_openid','identity',$identity))->fetchAll();
  55. if(count($result)>0){
  56. return $result[0]['userid'];
  57. }else{
  58. return false;
  59. }
  60. }
  61. }
  62. ?>