Browse Source

User e-mail address configuration

Brendan Abolivier 8 years ago
parent
commit
55d96a3bce
2 changed files with 40 additions and 3 deletions
  1. 16
    3
      auth.php
  2. 24
    0
      config.html

+ 16
- 3
auth.php View File

46
  */
46
  */
47
 class auth_plugin_macaroons extends auth_plugin_base {
47
 class auth_plugin_macaroons extends auth_plugin_base {
48
 
48
 
49
+	/*
50
+	* The name of the component. Used by the configuration.
51
+	*/
52
+	const COMPONENT_NAME = 'auth_macaroons';
53
+
49
 	/**
54
 	/**
50
 	 * Constructor.
55
 	 * Constructor.
51
 	 */
56
 	 */
52
 	public function __construct() {
57
 	public function __construct() {
53
 		$this->authtype = 'macaroons';
58
 		$this->authtype = 'macaroons';
59
+		$this->config = get_config(self::COMPONENT_NAME);
54
 	}
60
 	}
55
 
61
 
56
 	/**
62
 	/**
65
 
71
 
66
 	function loginpage_hook() {
72
 	function loginpage_hook() {
67
 		global $DB, $login, $CFG;
73
 		global $DB, $login, $CFG;
68
-		$message = "";
74
+		$placeholders[0] = "/{{firstname}}/";
75
+		$placeholders[1] = "/{{lastname}}/";
69
 		if(!empty($_COOKIE['das-macaroon'])) {
76
 		if(!empty($_COOKIE['das-macaroon'])) {
70
 			try {
77
 			try {
71
 				$m = Macaroon::deserialize($_COOKIE['das-macaroon']);
78
 				$m = Macaroon::deserialize($_COOKIE['das-macaroon']);
84
 					if($user) {
91
 					if($user) {
85
 						$user->firstname = $name[0];
92
 						$user->firstname = $name[0];
86
 						$user->lastname = $name[1];
93
 						$user->lastname = $name[1];
87
-						$user->email = $login."@brendanabolivier.com";
94
+						$user->email = preg_replace($placeholders, $name, $this->config->email_config);
88
 						$DB->update_record('user', $user);
95
 						$DB->update_record('user', $user);
96
+						
89
 						complete_user_login($user);
97
 						complete_user_login($user);
90
 						redirect($CFG->wwwroot);
98
 						redirect($CFG->wwwroot);
91
 					}
99
 					}
188
 	 * a form for configuring this plugin.
196
 	 * a form for configuring this plugin.
189
 	 *
197
 	 *
190
 	 * @param array $page An object containing all the data for this page.
198
 	 * @param array $page An object containing all the data for this page.
199
+	 */
191
 	function config_form($config, $err, $user_fields) {
200
 	function config_form($config, $err, $user_fields) {
192
 		include "config.html";
201
 		include "config.html";
193
 	}
202
 	}
194
-	 */
195
 
203
 
196
 	/**
204
 	/**
197
 	 * Processes and stores configuration data for this authentication plugin.
205
 	 * Processes and stores configuration data for this authentication plugin.
198
 	 */
206
 	 */
199
 	function process_config($config) {
207
 	function process_config($config) {
208
+		if(!isset($config->email_config)) {
209
+			$config->email_config = '';
210
+		}
211
+
212
+		set_config('email_config', $config->email_config, self::COMPONENT_NAME);
200
 		return true;
213
 		return true;
201
 	}
214
 	}
202
 
215
 

+ 24
- 0
config.html View File

1
+<?php
2
+	if(!isset($config->email_config)) {
3
+		$config->email_config = '';
4
+	}
5
+?>
6
+<table cellspacing="0" cellpadding="5" border="0">
7
+    <tr>
8
+        <td colspan="3">
9
+            <h3>Macaroons configuration</h3>
10
+        </td>
11
+    </tr>
12
+    <tr>
13
+        <td align="right">
14
+            <label for="email_config">
15
+		E-mail template
16
+            </label>
17
+        </td>
18
+        <td>
19
+		<input name="email_config" id="email_config" type="text" size="50" value="<?php echo $config->email_config; ?>" />
20
+        </td>
21
+        <td>Template for emails. Available placeholders are {{firstname}} and {{lastname}}.<br />
22
+eg: {{firstname}}.{{lastname}}@company.tld</td>
23
+    </tr>
24
+</table>