source: extensions/LCAS/trunk/main.inc.php @ 9206

Last change on this file since 9206 was 9206, checked in by LucMorizur, 13 years ago

Proper generation of 'username is already used' "error" message at username creation

File size: 2.9 KB
Line 
1<?php
2/*
3Plugin Name: LCAS
4Version: 2.1.0
5Description: Allow to disable login/register name to be sensible to the case/accents
6Plugin URI: http://fr.piwigo.org/forum/viewtopic.php?pid=158563
7Author: Eric, LucMorizur, Whiler
8Author URI: http://www.infernoweb.net, http://blogs.wittwer.fr/whiler/
9*/
10
11/* History:  LCAS_PATH.'Changelog.txt.php' */
12
13/*
14 ***** TODO List *****
15See project bugtracker: http://piwigo.org/bugs/my_view_page.php
16*/
17
18if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
19if (!defined('LCAS_DIR')) define('LCAS_DIR' , basename(dirname(__FILE__)));
20if (!defined('LCAS_PATH')) define('LCAS_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
21
22include_once (LCAS_PATH.'include/constants.php');
23include_once (LCAS_PATH.'include/functions.inc.php');
24
25load_language('plugin.lang', LCAS_PATH);
26
27$t = pwg_db_fetch_row(pwg_query('
28  SELECT `value`
29  FROM `'.CONFIG_TABLE.'`
30  WHERE `param` = "LoginCaseAccentsSensitivity"
31  LIMIT 1;
32'));
33
34$conf['LoginCaseAccentsSensitivity'] = $t[0];
35
36/* Plugin admin */
37add_event_handler('get_admin_plugin_menu_links', 'LCAS_admin_menu');
38
39function LCAS_admin_menu($menu)
40{
41// +-----------------------------------------------------------------------+
42// |                      Getting plugin name                              |
43// +-----------------------------------------------------------------------+
44  $plugin =  LCAS_PluginInfos(LCAS_PATH);
45  $name = $plugin['name'];
46 
47  array_push($menu,
48    array(
49      'NAME' => $name,
50      'URL'  => get_admin_plugin_menu_link(LCAS_PATH.'/admin/LCAS_admin.php')
51    )
52  );
53
54  return $menu;
55}
56
57// Check users identification
58add_event_handler('init', 'LCAS_InitPage');
59 
60function LCAS_InitPage()
61{
62  global $conf;
63
64  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
65 
66  // Set $conf['insensitive_case_logon'] to false, as LCAS takes completely
67  // in charge everything around the case and the accents
68  $conf['insensitive_case_logon'] = false;
69 
70/* User identification */
71  if (script_basename() == 'identification')
72  {
73    if (isset($_POST['username']) and isset($conf_LCAS[1]))
74    {
75      $new_username = LCAS_SearchCaseUsername($_POST['username'],$conf_LCAS[1]);
76      $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username;
77    }
78  }
79}
80
81// Check users registration
82// Returns error
83add_event_handler('register_user_check', 'LCAS_RegistrationCheck');
84
85function LCAS_RegistrationCheck($errors)
86{
87  global $conf, $lang;
88 
89  $conf_LCAS= unserialize($conf['LoginCaseAccentsSensitivity']);
90 
91  load_language('plugin.lang', LCAS_PATH);
92
93  if (isset($conf_LCAS[1]))
94   $NewPostLogin = LCAS_SearchCaseUsername($_POST['login'], $conf_LCAS[1]);
95 
96  if (isset($NewPostLogin) and get_userid($NewPostLogin))
97   $errors[] = $lang['LCAS_error'][intval($conf_LCAS[1])];
98 
99  return $errors;
100}
101?>
Note: See TracBrowser for help on using the repository browser.