summaryrefslogtreecommitdiff
path: root/htdocs
diff options
context:
space:
mode:
Diffstat (limited to 'htdocs')
-rw-r--r--htdocs/moderate/users/editor.php12
-rw-r--r--htdocs/src/User.inc.php31
2 files changed, 43 insertions, 0 deletions
diff --git a/htdocs/moderate/users/editor.php b/htdocs/moderate/users/editor.php
index c44928f..54befc7 100644
--- a/htdocs/moderate/users/editor.php
+++ b/htdocs/moderate/users/editor.php
@@ -58,6 +58,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$notify = isset($_POST['notify']) and $_POST['notify'] == '1';
$user->setNotify($notify);
+ // Send new password
+ if (isset($_POST['newpass']) and $_POST['newpass'] == '1') {
+ $user->sendNewPassword();
+ }
+
// Save the user
if ($error == '') {
if ($user->save()) {
@@ -98,6 +103,13 @@ Administrator</label></p>
<input type="checkbox" name="notify" value="1" <?= $user->getNotify() ? 'checked="checked"' : '' ?> />
Notify of posts</label></p>
+<?php
+ if (isset($_GET['id'])) {
+ echo "<p><label><input type=\"checkbox\" name=\"newpass\" value=\"1\" />"
+ . "Send new password</label></p>";
+ }
+?>
+
<p>
<input type="submit" class="bigbutton" value="Save" />
<a href="index.php" class="bigbutton">Cancel</a>
diff --git a/htdocs/src/User.inc.php b/htdocs/src/User.inc.php
index 0333520..6ff367e 100644
--- a/htdocs/src/User.inc.php
+++ b/htdocs/src/User.inc.php
@@ -11,6 +11,8 @@
require_once "base.inc.php";
class User {
+ const GENERATED_PASSSWORD_LENGTH = 12;
+
private $info;
private $indatabase;
@@ -82,6 +84,7 @@ class User {
if ($ret) {
$this->info['id'] = $ret;
$this->indatabase = true;
+ $this->sendNewPassword();
}
return true;
@@ -151,6 +154,34 @@ class User {
public function setAdmin($value) {
$this->info['admin'] = $value ? 1 : 0;
}
+
+ public function sendNewPassword() {
+ $password = $this->generatePassword();
+ $url = buildUrl('moderate/');
+
+ $email = new Email($this->getEmail());
+ $email->setSubject('Your ' . $GLOBALS['CONFIG']['sitetitle'] . ' Moderation Account');
+ $email->appendMessage('Your ' . $GLOBALS['CONFIG']['sitetitle']
+ . " moderation account password is $password\n\n"
+ . "You can access the moderation page at $url.\n");
+
+ $email->send();
+ }
+
+ public function generatePassword() {
+ $chars = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
+ $i = 0;
+ $password = "";
+ while ($i <= self::GENERATED_PASSSWORD_LENGTH) {
+ $password .= $chars{mt_rand(0, strlen($chars)-1)};
+ $i++;
+ }
+
+ $this->userinfo['password'] = sha1($password);
+
+ return $password;
+ }
+
}
?>