source: extensions/Register_FluxBB/tags/2.1.3/main.inc.php @ 4289

Revision 4289, 5.8 KB checked in by Eric, 10 years ago (diff)

[Register_FluxBB] Merged from branch to tags/2.1.3 - Building release 2.1.3

  • Using sha1 hash instead of md5 for password hashing in FluxBB because FluxBB uses prior sha1 hash and md5 only in last sentence.
  • Escaping all characters in login names and be able to retreive them without slashes - FluxBB does not allow this so Piwigo's user names with escaped characters will not been escaped in FluxBB (ie : "it's" in Piwigo will be "It\'s" in FluxBB)
  • Code refactoring
  • Full HTML 4.0 for tpl
  • Property svn:eol-style set to LF
Line 
1<?php
2/*
3Plugin Name: Register FluxBB
4Version: 2.1.3
5Description: Link user registration from Piwigo to FluxBB forum (registration, password changing, deletion) - Original Nicco's NBC_LinkUser2PunBB plugin upgraded to Piwigo / Liez l'inscription des utilisateurs de Piwigo avec votre forum FluxBB - Portage du plugin NBC_LinkUser2PunBB de Nicco vers Piwigo
6Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=252
7Author: Eric
8Author URI: http://www.infernoweb.net
9*/
10
11/*
12--------------------------------------------------------------------------------
13  Author     : Eric
14    email    : lucifer@infernoweb.net
15    website  : http://www.infernoweb.net
16    PWG user : http://forum.phpwebgallery.net/profile.php?id=1106
17--------------------------------------------------------------------------------
18
19:: HISTORY
20
212.0.0b          - 23/11/08  - Initial release. Basic changes to be available for Piwigo 2.0RC4
22
232.0.1b          - 24/11/08  - Small bug correction on submit button display
24
252.0.2                   - 19/02/09      - Language pack correction
26
272.1.0                   - 25/04/09  - Admin panel with tabsheets
28                      - Radio buttons functionnalities corrections (now radio buttons show the configuration saved in database)
29                      - Language files (fr - en) improvement
30
312.1.1                   - 30/04/09      - Bug fixed on profile update
32
332.1.2                   - 22/08/09      - Compatibility bug fixed when used with DynamicRecentPeriod plugin
34
352.1.3     - 16/11/09  - Using sha1 hash instead of md5 for password hashing in FluxBB
36                      - Escaping all characters in login names and be able to retreive them without slashes - FluxBB does not allow this so Piwigo's user names with escaped characters will not been escaped in FluxBB (ie : "it's" in Piwigo will be "It\'s" in FluxBB)
37                      - Code refactoring
38                      - Full HTML 4.0 for tpl
39
40--------------------------------------------------------------------------------
41*/
42
43// pour faciliter le debug - make debug easier :o)
44//ini_set('error_reporting', E_ALL);
45//ini_set('display_errors', true);
46
47if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
48
49define('Register_FluxBB_DIR' , basename(dirname(__FILE__)));
50define('Register_FluxBB_PATH' , PHPWG_PLUGINS_PATH . Register_FluxBB_DIR . '/');
51include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
52
53/* plugin administration */
54add_event_handler('get_admin_plugin_menu_links', 'Register_FluxBB_admin_menu');
55
56function Register_FluxBB_admin_menu($menu)
57{
58  array_push($menu, array(
59    'NAME' => 'Register FluxBB',
60    'URL'  => get_admin_plugin_menu_link(Register_FluxBB_PATH.'admin/Register_FluxBB_admin.php')));
61  return $menu;
62}
63
64
65/* user creation*/
66add_event_handler('register_user', 'Register_FluxBB_Adduser');
67
68function Register_FluxBB_Adduser($register_user)
69{
70  global $conf;
71       
72  include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
73
74  // Warning : FluxBB uses Sha1 hash instead of md5 for Piwigo !
75  FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
76}
77
78
79/* user deletion */
80add_event_handler('delete_user', 'Register_FluxBB_Deluser');
81
82function Register_FluxBB_Deluser($user_id)
83{
84  include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
85
86  FluxBB_Deluser( FluxBB_Searchuser($user_id), true );
87}
88
89
90
91add_event_handler('init', 'Register_FluxBB_InitPage');
92 
93function Register_FluxBB_InitPage()
94{
95  global $conf, $user ;
96  include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
97
98/* user update */
99  if (script_basename() == 'profile')
100  {
101    if (isset($_POST['validate']))
102    {
103      $errors = array();
104
105      $int_pattern = '/^\d+$/';
106      if (empty($_POST['nb_image_line'])
107        or (!preg_match($int_pattern, $_POST['nb_image_line'])))
108      {
109        $errors[] = l10n('nb_image_line_error');
110      }
111   
112      if (empty($_POST['nb_line_page'])
113        or (!preg_match($int_pattern, $_POST['nb_line_page'])))
114      {
115        $errors[] = l10n('nb_line_page_error');
116      }
117   
118      if ($_POST['maxwidth'] != ''
119        and (!preg_match($int_pattern, $_POST['maxwidth'])
120        or $_POST['maxwidth'] < 50))
121      {
122        $errors[] = l10n('maxwidth_error');
123      }
124
125      if ($_POST['maxheight']
126        and (!preg_match($int_pattern, $_POST['maxheight'])
127        or $_POST['maxheight'] < 50))
128      {
129        $errors[] = l10n('maxheight_error');
130      }
131
132      if (isset($_POST['mail_address']))
133      {
134        $mail_error = validate_mail_address($user['id'],$_POST['mail_address']);
135        if (!empty($mail_error))
136        {
137          $errors[] = $mail_error;
138        }
139      }
140   
141      if (!empty($_POST['use_new_pwd']))
142      {
143        // password must be the same as its confirmation
144        if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
145        {
146          $errors[] = l10n('New password confirmation does not correspond');
147        }
148   
149        if ( !defined('IN_ADMIN') )
150        {// changing password requires old password
151          $query = '
152SELECT '.$conf['user_fields']['password'].' AS password
153FROM '.USERS_TABLE.'
154WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
155;';
156
157          list($current_password) = mysql_fetch_row(pwg_query($query));
158     
159          if ($conf['pass_convert']($_POST['password']) != $current_password)
160          {
161            $errors[] = l10n('Current password is wrong');
162          }
163        }
164      }
165   
166      if (count($errors) == 0)
167      {
168        include_once (Register_FluxBB_PATH.'include/functions_Register_FluxBB.inc.php');
169     
170        $query = '
171SELECT '.$conf['user_fields']['username'].' AS username
172FROM '.USERS_TABLE.'
173WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
174;';
175
176        list($username) = mysql_fetch_row(pwg_query($query));
177
178        FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']);
179      }
180    }
181  }
182}
183?>
Note: See TracBrowser for help on using the repository browser.