/interface/owner/setting/account/openid/index.php

https://github.com/hinablue/TextCube · PHP · 115 lines · 93 code · 18 blank · 4 comment · 15 complexity · 5373e705104af084fc4eb7581d082573 MD5 · raw file

  1. <?php
  2. /// Copyright (c) 2004-2016, Needlworks / Tatter Network Foundation
  3. /// All rights reserved. Licensed under the GPL.
  4. /// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT)
  5. define('OPENID_REGISTERS', 10); /* check also ../index.php */
  6. /* ID Provider로부터 Redirect되어 연결이 되므로 GET 방식으로 구현되었습니다 */
  7. $IV = array(
  8. 'GET' => array(
  9. 'openid_identifier' => array('string', 'default'=>''),
  10. 'mode' => array('string'),
  11. 'authenticated' => array('string', 'default'=>null)
  12. )
  13. );
  14. require ROOT . '/library/preprocessor.php';
  15. global $openid_list;
  16. $openid_list = array();
  17. for( $i=0; $i<OPENID_REGISTERS; $i++ )
  18. {
  19. $openid = Setting::getUserSetting( "openid." . $i ,null,true);
  20. if( !empty($openid) ) {
  21. array_push( $openid_list, $openid );
  22. }
  23. }
  24. function loginOpenIDforAdding($claimedOpenID)
  25. {
  26. $context = Model_Context::getInstance();
  27. header( "Location: ".$context->getProperty('uri.blog')."/login/openid?action=try_auth" .
  28. "&authenticate_only=1&openid_identifier=" . urlencode($claimedOpenID) .
  29. "&requestURI=" . urlencode( $context->getProperty('uri.blog') . "/owner/setting/account/openid" . "?mode=add&authenticate_only=1&openid_identifier=" . urlencode($claimedOpenID) ) );
  30. }
  31. function exitWithError($msg)
  32. {
  33. $context = Model_Context::getInstance();
  34. echo "<html><head><script type=\"text/javascript\">//<![CDATA[".CRLF
  35. ."alert('$msg'); document.location.href='" . $context->getProperty('uri.blog') . "/owner/setting/account'; //]]></script></head></html>";
  36. exit;
  37. }
  38. function addOpenID()
  39. {
  40. global $openid_list;
  41. $context = Model_Context::getInstance();
  42. if( empty( $_GET['openid_identifier'] ) || strstr( $_GET['openid_identifier'], "." ) === false ) {
  43. exitWithError( _t('오픈아이디를 입력하지 않았거나, 도메인 없는 오픈아이디를 입력하였습니다.') );
  44. }
  45. $currentOpenID = Acl::getIdentity( 'openid_temp' );
  46. $fc = new OpenIDConsumer;
  47. $claimedOpenID = $fc->fetch( $_GET['openid_identifier'] );
  48. if( in_array( $claimedOpenID, $openid_list ) ) {
  49. exitWithError( _t('이미 연결된 오픈아이디 입니다') . " : " . $claimedOpenID );
  50. }
  51. if( $_GET['authenticated'] === "0" ) {
  52. header( "Location: ".$context->getProperty('uri.blog')."/owner/setting/account" );
  53. exit(0);
  54. }
  55. if( empty($currentOpenID) || $claimedOpenID != $currentOpenID ) {
  56. loginOpenIDforAdding($claimedOpenID);
  57. return;
  58. }
  59. if( !in_array( $currentOpenID, $openid_list ) ) {
  60. for( $i=0; $i<OPENID_REGISTERS; $i++ )
  61. {
  62. $openid = Setting::getUserSetting( "openid." . $i , null, true);
  63. if( empty($openid) ) {
  64. Setting::setUserSetting( "openid." . $i, $currentOpenID , true);
  65. break;
  66. }
  67. }
  68. }
  69. echo "<html><head><script type=\"text/javascript\">//<![CDATA[".CRLF
  70. ."alert('" . _t('연결하였습니다.') . " : " . $currentOpenID . "'); document.location.href='" . $context->getProperty('uri.blog') . "/owner/setting/account'; //]]></script></head></html>";
  71. }
  72. function deleteOpenID($openidForDel)
  73. {
  74. $context = Model_Context::getInstance();
  75. for( $i=0; $i<OPENID_REGISTERS; $i++ )
  76. {
  77. $openid = Setting::getUserSetting( "openid." . $i , null, true);
  78. if( $openid == $openidForDel ) {
  79. Setting::removeUserSetting( "openid." . $i, true);
  80. break;
  81. }
  82. }
  83. echo "<html><head><script type=\"text/javascript\">//<![CDATA[".CRLF
  84. ."alert('" . _t('삭제되었습니다.') . "'); document.location.href='" . $context->getProperty('uri.blog') . "/owner/setting/account'; //]]></script></head></html>";
  85. }
  86. switch( $_GET['mode'] ) {
  87. case 'del':
  88. deleteOpenID($_GET['openid_identifier']);
  89. break;
  90. case 'add':
  91. default:
  92. importlib('model.common.plugin');
  93. activatePlugin( 'CL_OpenID' );
  94. addOpenID();
  95. break;
  96. }
  97. ?>