handle configuration error without displaying paths in error message.
[squirrelmail.git] / plugins / change_password / backend / template.php
1 <?php
2 /**
3 * Change password backend template
4 *
5 * This is a template for a password changing mechanism. Currently,
6 * this contains two parts: the first is to register your function
7 * in the squirrelmail_plugin_hooks global, and the second is
8 * the function that does the actual changing.
9 *
10 * Replace the word template everywhere with a name for your backend.
11 *
12 * @version $Id$
13 * @package plugins
14 * @subpackage change_password
15 */
16
17 /**
18 * Config vars: here's room for config vars specific to your
19 * backend.
20 */
21
22 /**
23 * Define here the name of your password changing function.
24 */
25 global $squirrelmail_plugin_hooks;
26 $squirrelmail_plugin_hooks['change_password_dochange']['template'] =
27 'cpw_template_dochange';
28 $squirrelmail_plugin_hooks['change_password_init']['template'] =
29 'cpw_template_init';
30
31
32 /**
33 * Use this function to do any backend-specific initialization,
34 * e.g. checking requirements, before the password change form
35 * is displayed to the user.
36 */
37 function cpw_template_init()
38 {
39 global $color;
40
41 /**
42 * If SM_PATH isn't defined, define it. Required to include files.
43 * @ignore
44 */
45 if (!defined('SM_PATH')) {
46 define('SM_PATH','../../../');
47 }
48
49 // load error_box() function
50 include_once(SM_PATH . 'functions/display_messages.php');
51
52 // plugin is not configured. Handle error gracefully.
53 error_box(_("No valid backend defined."),$color);
54 // close html and stop script execution
55 echo "</body></html>\n";
56 exit();
57 }
58
59
60 /**
61 * This is the function that is specific to your backend. It takes
62 * the current password (as supplied by the user) and the desired
63 * new password. It will return an array of messages. If everything
64 * was successful, the array will be empty. Else, it will contain
65 * the errormessage(s).
66 * Constants to be used for these messages:
67 * CPW_CURRENT_NOMATCH -> "Your current password is not correct."
68 * CPW_INVALID_PW -> "Your new password contains invalid characters."
69 *
70 * @param array data The username/currentpw/newpw data.
71 * @return array Array of error messages.
72 */
73 function cpw_template_dochange($data)
74 {
75 // unfortunately, we can only pass one parameter to a hook function,
76 // so we have to pass it as an array.
77 $username = $data['username'];
78 $curpw = $data['curpw'];
79 $newpw = $data['newpw'];
80
81 $msgs = array();
82
83 // your code here to change the password for $username from
84 // $currentpw into $newpw.
85 user_error('No valid backend defined: this is just a template', E_USER_ERROR);
86
87 return $msgs;
88 }