Ver código fonte

User e-mail address configuration

Brendan Abolivier 7 anos atrás
pai
commit
55d96a3bce
2 arquivos alterados com 40 adições e 3 exclusões
  1. 16
    3
      auth.php
  2. 24
    0
      config.html

+ 16
- 3
auth.php Ver arquivo

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

+ 24
- 0
config.html Ver arquivo

@@ -0,0 +1,24 @@
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>