PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/register.php

http://malleo-cms.googlecode.com/
PHP | 211 lines | 160 code | 16 blank | 35 comment | 20 complexity | 1786919534b59c3ba544ae38511c5ce9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. |------------------------------------------------------------------------------------------------------------
  4. | Software: Malleo ( CMS )
  5. | Contact: SP - http://www.malleo-cms.com
  6. | Support: http://www.malleo-cms.com?module=forum
  7. | Documentation : Support: http://www.malleo-cms.com?module=wiki
  8. |------------------------------------------------------------------------------------------------------------
  9. | Author: Stephane RAJALU
  10. | Copyright (c) 2008-2009, Stephane RAJALU All Rights Reserved
  11. |------------------------------------------------------------------------------------------------------------
  12. | License: Distributed under the CECILL V2 License
  13. | This program is distributed in the hope that it will be useful - WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. | FITNESS FOR A PARTICULAR PURPOSE.
  16. |
  17. | Please read Licence_CeCILL_V2-en.txt
  18. | SVP lisez Licence_CeCILL_V2-fr.txt
  19. |------------------------------------------------------------------------------------------------------------
  20. */
  21. define('PROTECT',true);
  22. $root = './';
  23. require_once($root.'/chargement.php');
  24. $style_name=load_style();
  25. $lang=$erreur=array();
  26. load_lang('defaut');
  27. load_lang('register');
  28. // Chargement de la librairie Captcha
  29. $cryptinstall = $root.'librairies/crypt/cryptographp.fct.php';
  30. include_once($cryptinstall);
  31. if (isset($_POST['etape']) || isset($_GET['etape']))
  32. {
  33. $etape = (isset($_POST['etape']))?intval($_POST['etape']):intval($_GET['etape']);
  34. }else{
  35. $etape = 0;
  36. }
  37. $alerte = '';
  38. //
  39. // TRAITEMENT de la SAISIE
  40. switch($etape)
  41. {
  42. case '3':
  43. $email = nettoyage_mail($_GET['email']);
  44. $clef = preg_replace("/[^A-Za-z0-9]/i",'',$_GET['clef']);
  45. $sql = 'SELECT user_id FROM '.TABLE_USERS.'
  46. WHERE email=\''.$email.'\' AND clef=\''.$clef.'\'LIMIT 1';
  47. if (!$resultat = $c->sql_query($sql)) message_die(E_ERROR,29,__FILE__,__LINE__,$sql);
  48. if ($c->sql_numrows($resultat) > 0)
  49. {
  50. $row = $c->sql_fetchrow($resultat);
  51. $etape = 4;
  52. $sql = 'UPDATE '.TABLE_USERS.' SET actif=1,level=2 WHERE user_id='.$row['user_id'];
  53. if (!$resultat = $c->sql_query($sql)) message_die(E_ERROR,29,__FILE__,__LINE__,$sql);
  54. }else{
  55. $etape = 3;
  56. $alerte = $lang['L_ALERTE_MAIL_CLEF_NOK'];
  57. }
  58. break;
  59. case '2':
  60. // Nettoyage des saisies
  61. $pseudo = nettoyage_nom($_POST['pseudo']);
  62. $mail = nettoyage_mail($_POST['email']);
  63. $pass = nettoyage_pass($_POST['pass1']);
  64. $droits->charge_bannis();
  65. if (array_key_exists(0,$droits->liste_bannis)){
  66. if(array_key_exists(stripslashes($pseudo),$droits->liste_bannis[0])){
  67. message_die(E_WARNING,61,'','');
  68. }
  69. }
  70. $sql = 'SELECT user_id FROM '.TABLE_USERS.' WHERE pseudo = \''.$pseudo.'\' OR email=\''.$mail.'\' LIMIT 1';
  71. if (!$resultat = $c->sql_query($sql)) message_die(E_ERROR,29,__FILE__,__LINE__,$sql);
  72. if (empty($_POST['pseudo']) || empty($_POST['email'])
  73. || empty($_POST['pass1']) || empty($_POST['pass2']) || empty($_POST['code'])
  74. || empty($_POST['question'])){
  75. // au moins 1 champ obligatoire est resté vide
  76. $tpl->assign_vars(array(
  77. 'PSEUDO_SAISI' => $pseudo,
  78. 'MAIL' => $mail
  79. ));
  80. $alerte = $lang['L_REMPLIR_TOUT'];
  81. $etape = 2;
  82. }elseif(!chk_crypt($_POST['code'])){
  83. // Le code captcha saisi n'est pas bon
  84. $tpl->assign_vars(array(
  85. 'PSEUDO_SAISI' => $pseudo,
  86. 'MAIL' => $mail
  87. ));
  88. $alerte = $lang['L_CAPTCHA_INVALIDE'];
  89. $etape = 2;
  90. }elseif($_POST['question'] != $cf->config['register_question_reponse']){
  91. // Le code captcha saisi n'est pas bon
  92. $tpl->assign_vars(array(
  93. 'PSEUDO_SAISI' => $pseudo,
  94. 'MAIL' => $mail
  95. ));
  96. $alerte = $lang['L_REPONSE_QUESTION_INCORRECTE'];
  97. $etape = 2;
  98. }elseif($_POST['pass1'] != $_POST['pass2']){
  99. // les 2 mdps sont-ils bien identiques ?
  100. $tpl->assign_vars(array(
  101. 'PSEUDO_SAISI' => $pseudo,
  102. 'MAIL' => $mail
  103. ));
  104. $alerte = $lang['L_PSEUDOS_DIFFERENTS'];
  105. $etape = 2;
  106. }elseif ($c->sql_numrows($resultat) > 0)
  107. {
  108. // Le pseudo et l'adresse mail n'existent pas déj? ?
  109. $alerte = $lang['L_PSEUDOS_MAIL_EXISTENT_DEJA'];
  110. $etape = 2;
  111. // Si au moins 1 champs n'a pas été remplit on alerte le user
  112. }else{
  113. // On ajoute le compte en mode inactif
  114. require_once($root.'fonctions/fct_maths.php');
  115. $clef = generate_key(30);
  116. // On envoit le mail de vérification
  117. load_lang('emails');
  118. require_once($root.'class/class_mail.php');
  119. $email = new mail();
  120. $verifier = 'http://'.$cf->config['adresse_site'].$cf->config['path'].'register.php?etape=3&email='.$mail.'&clef='.$clef;
  121. $email->Subject = sprintf($lang['L_MAIL_REGISTER_SUJET'],$cf->config['nom_site']);
  122. $email->titre_message = $lang['L_MAIL_REGISTER_SUJET_MESSAGE'];
  123. $email->message_explain = sprintf($lang['L_MAIL_REGISTER_BODY_HTML'],$verifier,$verifier);
  124. $email->formate_html(sprintf($lang['L_MAIL_REGISTER_MESSAGE'], $pseudo, $pass));
  125. $email->AddAddress($mail,$pseudo);
  126. if($email->Send()) {
  127. $sql = 'INSERT INTO '.TABLE_USERS.'
  128. (pseudo, email, pass, date_register, level, clef, langue )
  129. VALUES
  130. (\''.$pseudo.'\',\''.$mail.'\',\''.md5($pass).'\','.time().',1,\''.$clef.'\',\''.$cf->config['default_langue'].'\')';
  131. if (!$resultat = $c->sql_query($sql))message_die(E_ERROR,30,__FILE__,__LINE__,$sql);
  132. // On passe ? l'étape suivante
  133. $etape = 3;
  134. }else{
  135. $alerte = $lang['L_EMAIL_NON_ENVOYE'];
  136. $etape = 2;
  137. }
  138. }
  139. break;
  140. case '1';
  141. // Si la checkbox a bien été cochée on affiche la seconde étape de l'enregistrement
  142. if ($_POST['validation'] == true) $etape = 2;
  143. break;
  144. }
  145. //
  146. // TRAITEMENT DE L'AFFICHAGE
  147. switch($etape)
  148. {
  149. case '4': // Retour ? la page o? le user se situait OU lien vers l'édition du profile
  150. $tpl->assign_block_vars('etape4', array());
  151. $tpl->assign_vars(array(
  152. 'ETAPE' => 4,
  153. 'S_CONNECTER' => formate_url('login.php')
  154. ));
  155. break;
  156. case '3':
  157. $tpl->assign_block_vars('etape3', array());
  158. $tpl->assign_vars(array(
  159. 'ETAPE' => 3,
  160. 'ALERTE' => $alerte
  161. ));
  162. break;
  163. case '2': // ENREGISTREMENT du login / mail / mdp
  164. $tpl->assign_block_vars('etape2', array());
  165. $tpl->assign_vars(array(
  166. 'ALERTE' => $alerte,
  167. 'L_QUESTION_BOTS' => $cf->config['register_question'],
  168. 'VALIDER' => $lang['VALIDER'],
  169. 'ETAPE' => 2
  170. ));
  171. break;
  172. case '1': // VALIDATION du réglement
  173. default :
  174. $tpl->assign_block_vars('etape1', array());
  175. $reglement = (file_exists(PATH_REGLEMENT))? @file_get_contents(PATH_REGLEMENT):$lang['REGLEMENT'];
  176. $reglement = preg_replace("/\n /",'<br />',$reglement);
  177. $tpl->assign_vars(array(
  178. 'ETAPE' => 1,
  179. 'REGLEMENT' => $reglement
  180. ));
  181. break;
  182. }
  183. include_once($root.'page_haut.php');
  184. $tpl->set_filenames(array(
  185. 'body' => $root .'html/register.html'
  186. ));
  187. $tpl->assign_vars(array(
  188. 'CAPTCHA' => dsp_crypt(0,1),
  189. 'IMAGE_OK' => $img['valide'] ,
  190. 'IMAGE_NOK' => $img['invalide']
  191. ));
  192. $tpl->pparse('body');
  193. include_once($root.'page_bas.php');
  194. $tpl->afficher_page();
  195. ?>