Commit: 10f118e7189ed98a8269e2ec53b7c3594ef698bb
Author: Hannes Magnusson <[email protected]> Thu, 26 Dec 2013
23:05:47 -0800
Parents: 3c06b8fa87134b2032e56c8dd07b77c99721df9e
Branches: master
Link:
http://git.php.net/?p=web/master.git;a=commitdiff;h=10f118e7189ed98a8269e2ec53b7c3594ef698bb
Log:
Refactor approval/reject/delete mail templates
Changed paths:
A include/email-templates.inc
M include/functions.inc
M manage/users.php
diff --git a/include/email-templates.inc b/include/email-templates.inc
new file mode 100644
index 0000000..7570a19
--- /dev/null
+++ b/include/email-templates.inc
@@ -0,0 +1,64 @@
+<?php // vim: et ts=4 sw=4
+/* Mail Templates */
+
+function mt_approve_user($userinfo) {
+ $message =
+"Your VCS account ($userinfo[username]) was created.
+
+You should be able to log into the VCS server within the hour, and
+your $userinfo[username]@php.net forward to $userinfo[email] should
+be active within the next 24 hours.
+
+If you ever forget your password, you can reset it at:
+ https://master.php.net/forgot.php
+
+To change your password, or other information about you please login on:
+ https://master.php.net/manage/users.php?username=$userinfo[username]
+
+Welcome to the PHP development team! If you encounter any problems
+with your VCS account, feel free to send us a note at $mailtext.
+";
+ return $message;
+}
+
+function mt_remove_user($userinfo) {
+ $message =
+"Your VCS account ($userinfo[username]) was deleted.
+
+Feel free to send us a note at [email protected] to find out why this
+was done.";
+
+ return $message;
+}
+
+function mt_deny_user($userinfo) {
+ $message =
+"Your VCS account request ($userinfo[username]) was denied.
+
+The most likely reason is that you did not read the reasons for
+which VCS accounts are granted, and your request failed to meet
+the list of acceptable criteria.
+
+We urge you to make another appeal for a VCS account, but first
+it helps to write the appropriate list and:
+
+ * Introduce yourself
+ * Explain what you want to work on
+ * And show what work you've already done (patches)
+
+Choose a list that relates to your request:
+
+ * Internals: [email protected]
+ * Documentation: [email protected]
+ * PECL: [email protected]
+ * PEAR: [email protected]
+ * Other: [email protected]
+
+PHP accounts are granted to developers who have earned the trust
+of existing PHP developers through patches, and have demonstrated
+the ability to work with others.
+";
+
+ return $message;
+}
+
diff --git a/include/functions.inc b/include/functions.inc
index 947f19b..df3f535 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -324,3 +324,87 @@ function undo_magic_quotes() {
}
//
-----------------------------------------------------------------------------------
+//
+
+
+function find_group_address_from_notes_for($id) {
+ $res = db_query("SELECT note FROM users_note WHERE userid=$id LIMIT 1");
+ $row = mysql_fetch_assoc($res);
+ $cc = "";
+ if (preg_match("/\[group: (\w+)\]/", $row["note"], $matches)) {
+ switch($matches[1]) {
+ case "php":
+ $cc = "[email protected]";
+ break;
+ case "pear":
+ $cc = "[email protected]";
+ break;
+ case "pecl":
+ $cc = "[email protected]";
+ break;
+ case "doc":
+ $cc = "[email protected]";
+ break;
+ }
+ }
+ return $cc;
+}
+
+define("MT_USER_APPROVE_MAIL", "[email protected]");
+define("MT_USER_REMOVE_MAIL", "[email protected]");
+function user_approve($id) {
+ $res = db_query("UPDATE users SET cvsaccess=1, enable=1 WHERE userid=$id");
+ if ($res && mysql_affected_rows()) {
+ $cc = find_group_address_from_notes_for($id);
+ $mailtext = $cc ? $cc : EMAIL_DEFAULT_CC;
+ $userinfo = fetch_user($id);
+
+ $message = mt_approve_user($userinfo, $mailtext);
+ /* Notify the user */
+ mail($userinfo["email"], "VCS Account Request: $userinfo[username]",
$message, "From: PHP Group <[email protected]>", "[email protected]");
+
+ /* Notify the public records */
+ $to = MT_USER_APPROVE_MAIL . ($cc ? ",$cc" : "");
+ $subject = "Re: VCS Account Request: $userinfo[username]";
+ $message = "VCS Account Approved: $userinfo[username] approved by
{$_SESSION["username"]} \o/";
+ $headers = "From: PHP Group <[email protected]>\nIn-Reply-To:
<[email protected]>";
+ mail($to, $subject, $message, $headers, "[email protected]");
+ warn("record $id ($userinfo[username]) approved");
+ return true;
+ }
+ else {
+ warn("wasn't able to grant access to id $id.");
+ return false;
+ }
+}
+
+function user_remove($id) {
+ $userinfo = fetch_user($id);
+ $res = db_query("DELETE FROM users WHERE userid=$id");
+ if ($res && mysql_affected_rows()) {
+ $cc = find_group_address_from_notes_for($id);
+
+ $message = $userinfo['cvsaccess'] ? mt_remove_user($userinfo) :
mt_deny_user($userinfo);
+
+ /* Notify the user */
+ mail($userinfo['email'],"VCS Account Request:
$userinfo[username]",$message,"From: PHP Group <[email protected]>",
"[email protected]");
+
+ $to = MT_USER_REMOVE_MAIL . ($cc ? ",$cc" : "");
+ $subject = "Re: VCS Account Request: $userinfo[username]";
+ $message = $userinfo['cvsaccess']
+ ? "VCS Account Deleted: $userinfo[username] deleted by
{$_SESSION["username"]} /o\\"
+ : "VCS Account Rejected: $userinfo[username] rejected by
{$_SESSION["username"]} /o\\";
+
+ /* Notify public records */
+ mail($to, $subject, $message,"From: PHP Group
<[email protected]>\nIn-Reply-To: <[email protected]>",
"[email protected]");
+ db_query("DELETE FROM users_note WHERE userid=$id");
+ db_query("DELETE FROM users_profile WHERE userid=$id");
+ warn("record $id ($userinfo[username]) removed");
+ return true;
+ }
+ else {
+ warn("wasn't able to delete id $id.");
+ return false;
+ }
+}
+
diff --git a/manage/users.php b/manage/users.php
index c7a2552..08e8c77 100644
--- a/manage/users.php
+++ b/manage/users.php
@@ -6,29 +6,7 @@
require '../include/login.inc';
require '../include/email-validation.inc';
-
-function find_group_address_from_notes_for($id) {
- $res = db_query("SELECT note FROM users_note WHERE userid=$id LIMIT 1");
- $row = mysql_fetch_assoc($res);
- $cc = "";
- if (preg_match("/\[group: (\w+)\]/", $row["note"], $matches)) {
- switch($matches[1]) {
- case "php":
- $cc = "[email protected]";
- break;
- case "pear":
- $cc = "[email protected]";
- break;
- case "pecl":
- $cc = "[email protected]";
- break;
- case "doc":
- $cc = "[email protected]";
- break;
- }
- }
- return $cc;
-}
+require '../include/email-templates.inc';
define('PHP_SELF', hsc($_SERVER['PHP_SELF']));
$valid_vars =
array('search','username','id','in','unapproved','begin','max','order','full',
'action');
@@ -37,8 +15,6 @@ foreach($valid_vars as $k) {
}
if($id) $id = (int)$id;
-$mailto = "[email protected]";
-
head("user administration");
db_connect();
@@ -59,84 +35,16 @@ if ($id && $action) {
warn("you're not allowed to take actions on users.");
exit;
}
+
switch ($action) {
case 'approve':
- if (db_query("UPDATE users SET cvsaccess=1, enable=1 WHERE userid=$id")
- && mysql_affected_rows()) {
- $cc = find_group_address_from_notes_for($id);
- $userinfo = fetch_user($id);
- $mailtext = $cc ? $cc : $mailto;
- $message =
-"Your VCS account ($userinfo[username]) was created.
-
-You should be able to log into the VCS server within the hour, and
-your $userinfo[username]@php.net forward to $userinfo[email] should
-be active within the next 24 hours.
-
-If you ever forget your password, you can reset it at:
- https://master.php.net/forgot.php
-
-To change your password, or other information about you please login on:
- https://master.php.net/manage/users.php?username=$userinfo[username]
-
-Welcome to the PHP development team! If you encounter any problems
-with your VCS account, feel free to send us a note at $mailtext.
-";
- mail($userinfo['email'],"VCS Account Request:
$userinfo[username]",$message,"From: PHP Group <[email protected]>",
"[email protected]");
-
- mail($mailto . ($cc ? ",$cc" : ""),"Re: VCS Account Request:
$userinfo[username]","VCS Account Approved: $userinfo[username] approved by
{$_SESSION["username"]} \o/","From: PHP Group <[email protected]>\nIn-Reply-To:
<[email protected]>", "[email protected]");
- warn("record $id ($userinfo[username]) approved");
- }
- else {
- warn("wasn't able to grant access to id $id.");
- }
+ user_approve((int)$id);
break;
+
case 'remove':
- $userinfo = fetch_user($id);
- if (db_query("DELETE FROM users WHERE userid=$id")
- && mysql_affected_rows()) {
- $cc = find_group_address_from_notes_for($id);
- $message = $userinfo['cvsaccess'] ?
-"Your VCS account ($userinfo[username]) was deleted.
-
-Feel free to send us a note at [email protected] to find out why this
-was done."
-:
-"Your VCS account request ($userinfo[username]) was denied.
-
-The most likely reason is that you did not read the reasons for
-which VCS accounts are granted, and your request failed to meet
-the list of acceptable criteria.
-
-We urge you to make another appeal for a VCS account, but first
-it helps to write the appropriate list and:
-
- * Introduce yourself
- * Explain what you want to work on
- * And show what work you've already done (patches)
-
-Choose a list that relates to your request:
-
- * Internals: [email protected]
- * Documentation: [email protected]
- * PECL: [email protected]
- * PEAR: [email protected]
- * Other: [email protected]
-
-PHP accounts are granted to developers who have earned the trust
-of existing PHP developers through patches, and have demonstrated
-the ability to work with others.
-";
- mail($userinfo['email'],"VCS Account Request:
$userinfo[username]",$message,"From: PHP Group <[email protected]>",
"[email protected]");
- mail($mailto . ($cc ? ",$cc" : ""),"Re: VCS Account Request:
$userinfo[username]",$userinfo['cvsaccess'] ? "VCS Account Deleted:
$userinfo[username] deleted by {$_SESSION["username"]} /o\\" : "VCS Account
Rejected: $userinfo[username] rejected by {$_SESSION["username"]} /o\\","From:
PHP Group <[email protected]>\nIn-Reply-To: <[email protected]>",
"[email protected]");
- db_query("DELETE FROM users_note WHERE userid=$id");
- db_query("DELETE FROM users_profile WHERE userid=$id");
- warn("record $id ($userinfo[username]) removed");
- }
- else {
- warn("wasn't able to delete id $id.");
- }
+ user_remove((int)$id);
break;
+
default:
warn("that action ('$action') is not understood.");
}--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php