thirdlogin.ctrl.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('setting');
  8. load()->classs('oauth2/oauth2client');
  9. $dos = array('display', 'save_setting');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. $types = OAuth2Client::supportLoginType();
  12. $type = safe_gpc_string($_GPC['type']);
  13. $type = !empty($type) && in_array($type, $types) ? $type : 'qq';
  14. $thirdlogin = $_W['setting']['thirdlogin'];
  15. $copyright = $_W['setting']['copyright'];
  16. if ($do == 'save_setting') {
  17. $is_copyright = false;
  18. switch ($_GPC['key']) {
  19. case 'qqauthstate':
  20. $thirdlogin['qq']['authstate'] = intval($_GPC['value']);
  21. break;
  22. case 'qqappid':
  23. $thirdlogin['qq']['appid'] = safe_gpc_string($_GPC['value']);
  24. break;
  25. case 'qqappsecret':
  26. $thirdlogin['qq']['appsecret'] = safe_gpc_string($_GPC['value']);
  27. break;
  28. case 'wechatauthstate':
  29. $thirdlogin['wechat']['authstate'] = intval($_GPC['value']);
  30. break;
  31. case 'wechatappid':
  32. $thirdlogin['wechat']['appid'] = safe_gpc_string($_GPC['value']);
  33. break;
  34. case 'wechatappsecret':
  35. $thirdlogin['wechat']['appsecret'] = safe_gpc_string($_GPC['value']);
  36. break;
  37. case 'bind':
  38. $copyright['bind'] = safe_gpc_string($_GPC['value']);
  39. $copyright['bind'] = $copyright['bind'] == 'null' ? '' : $copyright['bind'];
  40. $is_copyright = true;
  41. break;
  42. case 'oauth_bind':
  43. $copyright['oauth_bind'] = intval($_GPC['value']);
  44. $is_copyright = true;
  45. break;
  46. }
  47. if ($is_copyright) {
  48. setting_save($copyright, 'copyright');
  49. } else {
  50. setting_save($thirdlogin, 'thirdlogin');
  51. }
  52. itoast('更新设置成功!', referer(), 'success');
  53. }
  54. if ($do == 'display') {
  55. if (empty($thirdlogin)) {
  56. foreach ($types as $login_type) {
  57. $thirdlogin[$login_type]['appid'] = '';
  58. $thirdlogin[$login_type]['appsecret'] = '';
  59. $thirdlogin[$login_type]['authstate'] = '';
  60. }
  61. setting_save($thirdlogin, 'thirdlogin');
  62. }
  63. $thirdlogin['bind'] = $copyright['bind'];
  64. $thirdlogin['oauth_bind'] = $copyright['oauth_bind'];
  65. $siteroot_parse_array = parse_url($_W['siteroot']);
  66. $binds = array(array('name' => '无', 'id' => 'null'));
  67. foreach (OAuth2Client::supportBindTypeInfo() as $info) {
  68. $binds[] = array('name' => $info['title'], 'id' => $info['type']);
  69. }
  70. $bind = array();
  71. foreach ($binds as $item) {
  72. if ($item['id'] == $thirdlogin['bind']) {
  73. $bind = $item;
  74. break;
  75. }
  76. }
  77. if (empty($bind)) {
  78. $bind = array('name' => '无', 'id' => 'null');
  79. }
  80. }
  81. template('system/thirdlogin');