register.ctrl.php 3.0 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('user');
  8. load()->model('setting');
  9. load()->model('utility');
  10. load()->classs('oauth2/oauth2client');
  11. $dos = array('display', 'valid_mobile', 'register', 'check_username', 'get_extendfields', 'check_code', 'check_mobile_code', 'check_password_safe', 'check_failed_code');
  12. $do = in_array($do, $dos) ? $do : 'display';
  13. if (empty($_W['setting']['register']['open']) && empty($_W['setting']['copyright']['mobile_status'])) {
  14. itoast('本站暂未开启注册功能,请联系管理员!', '', '');
  15. }
  16. if (empty($_GPC['register_type'])) {
  17. $_GPC['register_type'] = !empty($_W['setting']['register']['open']) ? 'system' : 'mobile';
  18. }
  19. $register_type = safe_gpc_belong(safe_gpc_string($_GPC['register_type']), array('system', 'mobile'), 'system');
  20. $owner_uid = intval($_GPC['owner_uid']);
  21. $setting = $_W['setting']['register'];
  22. $user_type = empty($_GPC['type']) || $_GPC['type'] == USER_TYPE_COMMON ? USER_TYPE_COMMON : USER_TYPE_CLERK;
  23. if ($register_type == 'system') {
  24. $extendfields = OAuth2Client::create($register_type)->systemFields();
  25. } else {
  26. $setting_sms_sign = setting_load('site_sms_sign');
  27. $register_sign = !empty($setting_sms_sign['site_sms_sign']['register']) ? $setting_sms_sign['site_sms_sign']['register'] : '';
  28. }
  29. if ($do == 'valid_mobile' || $do == 'register' && $register_type == 'mobile') {
  30. $validate_mobile = OAuth2Client::create('mobile')->validateMobile();
  31. if (is_error($validate_mobile)) {
  32. iajax(-1, $validate_mobile['message']);
  33. }
  34. }
  35. if ($do == 'register') {
  36. if(checksubmit() || $_W['ispost'] && $_W['isajax']) {
  37. $register_user = OAuth2Client::create($register_type)->setUserType($user_type)->register();
  38. $redirect = url('user/login');
  39. if ($user_type == USER_TYPE_CLERK && !empty($_GPC['m'])) {
  40. if (empty($_GPC['redirect'])) {
  41. $redirect = url('module/permission/display', array('m' => $_GPC['m']));
  42. } else {
  43. $redirect = url('module/permission/post', array('m' => $_GPC['m']));
  44. }
  45. }
  46. if ($register_type == 'system') {
  47. if (is_error($register_user)) {
  48. itoast($register_user['message']);
  49. } else {
  50. itoast($register_user['message'], $redirect);
  51. }
  52. }
  53. if ($register_type == 'mobile') {
  54. if (is_error($register_user)) {
  55. iajax(-1, $register_user['message']);
  56. } else {
  57. iajax(0, $register_user['message'], $redirect);
  58. }
  59. }
  60. }
  61. }
  62. if ($do == 'check_username') {
  63. $member['username'] = safe_gpc_string($_GPC['username']);
  64. if (user_check(array('username' => $member['username']))) {
  65. iajax(-1, '非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  66. } else {
  67. iajax(0, '用户名未被注册');
  68. }
  69. }
  70. if ($do == 'check_code') {
  71. if (!checkcaptcha(intval($_GPC['code']))) {
  72. iajax(-1, '你输入的验证码不正确, 请重新输入.');
  73. } else {
  74. iajax(0, '验证码正确');
  75. }
  76. }
  77. template('user/register');