PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/activate.php

http://snowcms.googlecode.com/
PHP | 168 lines | 101 code | 18 blank | 49 comment | 21 complexity | 65a043c67479a14dd6af4ec212454525 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////
  3. // SnowCMS v2.0 //
  4. // By the SnowCMS Team //
  5. // www.snowcms.com //
  6. // Released under the Microsoft Reciprocal License //
  7. // www.opensource.org/licenses/ms-rl.html //
  8. ////////////////////////////////////////////////////////////////////////////
  9. // //
  10. // SnowCMS originally pawned by soren121 started in early 2008 //
  11. // //
  12. ////////////////////////////////////////////////////////////////////////////
  13. // //
  14. // SnowCMS v2.0 began in November 2009 //
  15. // //
  16. ////////////////////////////////////////////////////////////////////////////
  17. // File version: SnowCMS 2.0 //
  18. ////////////////////////////////////////////////////////////////////////////
  19. if(!defined('INSNOW'))
  20. {
  21. die('Nice try...');
  22. }
  23. // Title: Account activation
  24. if(!function_exists('activate_view'))
  25. {
  26. /*
  27. Function: activate_view
  28. Handles the activation of members who registered an account but were
  29. required to activate their account via email.
  30. Parameters:
  31. none
  32. Returns:
  33. void - Nothing is returned by this function.
  34. Note:
  35. This function is overloadable.
  36. */
  37. function activate_view()
  38. {
  39. global $api, $member, $settings, $theme;
  40. api()->run_hooks('activate_view');
  41. // Are you logged in? Then why would you need to activate another account?
  42. if(member()->is_logged())
  43. {
  44. redirect(baseurl());
  45. }
  46. // What is the registration type? Is it actually email?
  47. elseif(settings()->get('registration_type', 'int', 0) != 3)
  48. {
  49. theme()->set_title(l('An Error Occurred'));
  50. api()->context['error_title'] = l('Registration Error');
  51. api()->context['error_message'] = l('It appears that either registration is disabled or the administrator must manually activate your account.');
  52. theme()->render('error');
  53. exit;
  54. }
  55. // It should use a form in reality, but since this can be done through
  56. // a URL that wouldn't be the best solution. So we will hand make it,
  57. // in this case!
  58. if((!empty($_REQUEST['id']) || !empty($_REQUEST['member_name'])) && !empty($_REQUEST['code']) && $_REQUEST['code'] != 'admin_approval')
  59. {
  60. // We will be needing this. That's for sure :P
  61. $members = api()->load_class('Members');
  62. // Did you give is a name? We need to convert it to an ID.
  63. if(empty($_REQUEST['id']) && !empty($_REQUEST['member_name']))
  64. {
  65. $_REQUEST['id'] = (int)$members->name_to_id($_REQUEST['member_name']);
  66. }
  67. // Load up that member :)
  68. $members->load($_REQUEST['id']);
  69. $member_info = $members->get($_REQUEST['id']);
  70. if(!empty($member_info))
  71. {
  72. // Just because you got the right ID doesn't mean nothin' :P
  73. // Has this account already been activated?
  74. if($member_info['is_activated'] == 1)
  75. {
  76. api()->add_filter('activate_form_errors', create_function('$value', '
  77. $value[] = l(\'That account is already activated. If this is your account you can <a href="%s">log in</a>.\', baseurl(\'index.php?action=login\'));
  78. return $value;'));
  79. api()->run_hooks('activate_member_already_activated', array($member_info));
  80. $_REQUEST['name'] = $member_info['username'];
  81. }
  82. // Do the codes not match? Also make sure that this account wasn't
  83. // supposed to be activated by an administrator (in which case the
  84. // activation code is admin_approval).
  85. elseif($member_info['acode'] != $_REQUEST['code'] || strlen($member_info['acode']) == 0 || $member_info['acode'] == 'admin_approval')
  86. {
  87. api()->add_filter('activate_form_errors', create_function('$value', '
  88. $value[] = l(\'The supplied activation code is invalid.\');
  89. return $value;'));
  90. api()->run_hooks('activate_member_invalid_acode', array($member_info));
  91. $_REQUEST['name'] = $member_info['username'];
  92. }
  93. else
  94. {
  95. // Sweet! It's right ;D
  96. $members->update($_REQUEST['id'], array(
  97. 'member_acode' => '',
  98. 'member_activated' => 1,
  99. ));
  100. api()->add_filter('activate_form_messages', create_function('$value', '
  101. $value[] = l(\'Your account has been successfully activated. You may now <a href="%s">log in</a>.\', baseurl(\'index.php?action=login\'));
  102. return $value;'));
  103. api()->run_hooks('activate_member_success', array($member_info));
  104. $_REQUEST['name'] = '';
  105. $_REQUEST['code'] = '';
  106. }
  107. }
  108. else
  109. {
  110. // It appears that member does not exist... Interesting.
  111. api()->add_filter('activate_form_errors', create_function('$value', '
  112. $value[] = l(\'There is no account with that username or email address.\');
  113. return $value;'));
  114. api()->run_hooks('activate_member_nonexist');
  115. }
  116. }
  117. elseif(!empty($_POST['activate_form']))
  118. {
  119. api()->add_filter('activate_form_errors', create_function('$value', '
  120. if(empty($_REQUEST[\'member_name\']))
  121. {
  122. $value[] = l(\'Please enter a username or email address.\');
  123. }
  124. if(empty($_REQUEST[\'code\']))
  125. {
  126. $value[] = l(\'Please enter an activation code.\');
  127. }
  128. return $value;'));
  129. }
  130. theme()->set_title('Activate Your Account');
  131. // No indexing if you have anything extra set ;)
  132. if(isset($_GET['id']) || isset($_GET['code']))
  133. {
  134. theme()->add_meta(array('name' => 'robots', 'content' => 'noindex'));
  135. }
  136. theme()->render('activate_view');
  137. }
  138. }
  139. ?>