1
0

Change the ui per thumbs suggestion

Move the admin menu under the Settings dropdown
Implement:
* Vistors can create accounts but administrator approval is required
* Email confirmations can be used or not used with above
* Welcome email is sent when the user is created
* Random password is generated when the user created and this is included in the welcome email.
This commit is contained in:
Tim Almdal 2009-10-30 13:19:57 -07:00
parent 496820034c
commit 0bdd2c2730
9 changed files with 202 additions and 83 deletions

View File

@ -32,8 +32,7 @@ class Admin_register_Controller extends Admin_Controller {
Kohana::log("alert", Kohana::debug($post));
module::set_var("registration", "policy", $post->policy);
module::set_var("registration", "default_group", $post->group);
module::set_var("registration", "email_admin", !empty($post->email_admin));
module::set_var("registration", "email_user", !empty($post->email_user));
module::set_var("registration", "email_verification", !empty($post->email_verification));
message::success(t("Registration defaults have been updated."));
@ -52,24 +51,27 @@ class Admin_register_Controller extends Admin_Controller {
$post = new Validation($_POST);
$post->add_rules("activate_users", "required");
if ($post->validate()) {
$names = array();
foreach ($post->activate as $id) {
$user = ORM::factory("pending_user", $id);
Kohana::log("alert", Kohana::debug($user->as_array()));
$new_user = identity::create_user($user->name, $user->full_name, $user->password);
$password = md5(rand());
$new_user = identity::create_user($user->name, $user->full_name, $password);
$new_user->email = $user->email;
$new_user->url = $user->url;
$new_user->admin = false;
$new_user->guest = false;
$new_user->save();
// @todo add the user to the default group... requires new api method (add_user_to_group)
identity::add_user_to_group($new_user, module::get_var("registration", "default_group"));
identity::add_user_to_group($new_user, module::get_var("registration", "default_group"));
register::send_user_created_confirmation($new_user, $password);
$names[] = $user->name;
$user->delete();
}
message::success(t("Activate users."));
message::success(t("Activated %users.", implode(", ", $names)));
$count = Database::instance()
->query("select count(id) as pending_count from {pending_users}")
@ -80,7 +82,6 @@ class Admin_register_Controller extends Admin_Controller {
url::redirect("admin/register");
}
Kohana::log("alert", Kohana::debug($post));
list ($form, $errors) = $this->_get_form();
arr::overwrite($form, $post->as_array());
arr::overwrite($errors, $post->errors());
@ -91,12 +92,16 @@ class Admin_register_Controller extends Admin_Controller {
$v = new Admin_View("admin.html");
$v->content = new View("admin_register.html");
$v->content->action = "admin/register/update";
$v->content->policy_list = array("admin" => t("Activation by administrator"),
"email" => t("Use confirmation emails"),
"immediate" => t("Accept without confirmation"));
$v->content->policy_list =
array("admin_only" => t("Only site administrators can create new user accounts."),
"vistor" =>
t("Visitors can create accounts and no administrator approval is required."),
"admin_approval" =>
t("Visitors can create accounts but administrator approval is required."));
$admin = identity::admin_user();
$v->content->no_admin = empty($admin->email) ? "disabled" : "";
if (empty($admin->email)) {
unset($v->content->policy_list["email"]);
module::set_var("registration", "email_verification", false);
}
$v->content->group_list = array();
@ -110,7 +115,6 @@ class Admin_register_Controller extends Admin_Controller {
$v->content->group_list =
array("" => t("Choose the default group")) + $v->content->group_list;
}
$v->content->no_admin = empty($admin->email);
$v->content->hidden = array("csrf" => access::csrf_token());
$v->content->pending = ORM::factory("pending_user")->find_all();
$v->content->activate = "admin/register/activate";
@ -122,8 +126,7 @@ class Admin_register_Controller extends Admin_Controller {
private function _get_form() {
$form = array("policy" => module::get_var("registration", "policy"),
"default_group" => module::get_var("registration", "default_group"),
"email_admin" => module::get_var("registration", "email_admin"),
"email_user" => module::get_var("registration", "email_user"));
"email_verification" => module::get_var("registration", "email_verification"));
$errors = array_fill_keys(array_keys($form), "");
return array($form, $errors);

View File

@ -27,7 +27,6 @@ class register_Controller extends Controller {
$form = $this->_get_form();
$valid = $form->validate();
// @todo create a user event "user_exists" which checks for name clashes
$name = $form->register_user->inputs["name"]->value;
$user_exists_data = (object)array("name" => $name);
module::event("check_username_exists", $user_exists_data);
@ -36,26 +35,23 @@ class register_Controller extends Controller {
$valid = false;
}
if ($valid) {
switch (module::get_var("registration", "policy")) {
case "immediate":
message::success(t("Your registration request has been processed"));
break;
case "admin":
$this->_create_pending_request($form);
message::success(t("Your registration request is awaiting administrator approval"));
$pending_user = register::create_pending_request($form);
$policy = module::get_var("registration", "policy");
if ($policy == "visitor" && $pending_user->confirmed) {
// @todo create and logon
// set the form to the one similiar to the admin logon
} else if (empty($pending_user->confirmed) &&
($policy == "admin_approval" || $policy == "visitor")) {
register::send_confirmation($pending_user);
} else {
site_status::warning(
t("There are pending user registration. <a href=\"%url\">Review now!</a>",
array("url" => html::mark_clean(url::site("admin/register")))),
"pending_user_registrations");
break;
case "email":
message::success(t("A confirmation email has been sent to the email address you provided."));
break;
message::success(t("Your registration request is awaiting administrator approval"));
}
print json_encode(
array("result" => "success"));
print json_encode(array("result" => "success"));
} else {
print json_encode(
array("result" => "error",
@ -63,16 +59,29 @@ class register_Controller extends Controller {
}
}
private function _create_pending_request($form) {
$user = ORM::factory("pending_user");
$user->name = $form->register_user->inputs["name"]->value;
$user->full_name = $form->register_user->inputs["full_name"]->value;
// @todo call identity to hash the password
$user->password = $form->register_user->inputs["password"]->value;
$user->email = $form->register_user->inputs["email"]->value;
$user->url = $form->register_user->inputs["url"]->value;
$user->hash = md5(rand());
$user->save();
public function confirm($hash) {
$pending_user = ORM::factory("pending_user")
->where("hash", $hash)
->find();
if ($pending_user->loaded) {
// @todo add a request date to the pending user table and check that it hasn't expired
$policy = module::get_var("registration", "policy");
$pending_user->confirmed = true;
$pending_user->save();
if ($policy == "vistor") {
// @todo create and logon
// set the form to the one similiar to the admin logon
} else {
site_status::warning(
t("There are pending user registration. <a href=\"%url\">Review now!</a>",
array("url" => html::mark_clean(url::site("admin/register")))),
"pending_user_registrations");
message::success(t("Your registration request is awaiting administrator approval"));
}
} else {
message::error(t("Your registration request is no longer valid, Please re-register."));
}
url::redirect(item::root()->abs_url());
}
private function _get_form() {
@ -84,12 +93,8 @@ class register_Controller extends Controller {
->error_messages("in_use", t("There is already a user with that username"));
$group->input("full_name")->label(t("Full Name"))->id("g-fullname")
->rules("length[0, 255]");
$group->password("password")->label(t("Password"))->id("g-password")
->rules("required|length[{$minimum_length}, 40]");
$group->password("password2")->label(t("Confirm Password"))->id("g-password2")
->matches($group->password);
$group->input("email")->label(t("Email"))->id("g-email")
->rules("valid_email|length[1,255]");
->rules("required|valid_email|length[1,255]");
$group->input("email2")->label(t("Confirm email"))->id("g-email2")
->matches($group->email);
$group->input("url")->label(t("URL"))->id("g-url")

View File

@ -0,0 +1,60 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class register_Core {
static function send_user_created_confirmation($user, $password) {
$message = new View("register_welcome.html");
$message->user = $user;
$message->password = $password;
self::_sendemail($user->email, t("Your userid has been created"), $message);
}
static function send_confirmation($user) {
$message = new View("confirm_registration.html");
$message->confirm_url = url::abs_site("register/confirm/{$user->hash}");
$message->user = $user;
self::_sendemail($user->email, t("User registration confirmation"), $message);
}
static function create_pending_request($form) {
$email_verification = module::get_var("registration", "email_verification");
$user = ORM::factory("pending_user");
$user->name = $form->register_user->inputs["name"]->value;
$user->full_name = $form->register_user->inputs["full_name"]->value;
$user->email = $form->register_user->inputs["email"]->value;
$user->url = $form->register_user->inputs["url"]->value;
if (!$email_verification) {
$user->confirmed = true;
}
$user->hash = md5(rand());
$user->save();
return $user;
}
private static function _sendemail($email, $subject, $message) {
Sendmail::factory()
->to($email)
->subject($subject)
->header("Mime-Version", "1.0")
->header("Content-type", "text/html; charset=iso-8859-1")
->message($message->render())
->send();
}
}

View File

@ -18,17 +18,18 @@
*/
class register_event {
static function admin_menu($menu, $theme) {
$menu->get("identity_menu")
$menu->get("settings_menu")
->append( Menu::factory("link")
->id("register_users")
->label(t("Self registration"))
->label(t("User registration"))
->url(url::site("admin/register")));
return $menu;
}
static function site_menu($menu, $theme) {
if (identity::active_user()->guest) {
if (identity::active_user()->guest &&
module::get_var("registration", "policy") != "admin_only") {
$menu->append( Menu::factory("dialog")
->id("register_users")
->label(t("Register"))

View File

@ -23,8 +23,8 @@ class register_installer {
$db->query("CREATE TABLE IF NOT EXISTS {pending_users} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`confirmed` boolean NOT NULL DEFAULT false,
`full_name` varchar(255) NOT NULL,
`password` varchar(64) NOT NULL,
`email` varchar(64) default NULL,
`hash` char(32) default NULL,
`url` varchar(255) default NULL,
@ -33,10 +33,9 @@ class register_installer {
UNIQUE KEY(`name`))
DEFAULT CHARSET=utf8;");
module::set_var("registration", "policy", "admin");
module::set_var("registration", "policy", "admin_only");
module::set_var("registration", "default_group", "");
module::set_var("registration", "email_admin", true);
module::set_var("registration", "email_user", true);
module::set_var("registration", "email_verification", true);
module::set_version("register", 1);
}

View File

@ -1,3 +1,3 @@
name = Self Registration
description = "Allow anonymous users to register as users."
name = User Registration
description = "Allow guests to register as users."
version = 1

View File

@ -1,55 +1,70 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<style>
#g-registration-admin li input[type=radio],
#g-registration-admin li input[type=checkbox] {
float: left;
margin-right: .5em;
}
#g-registration-admin li label {
float: left;
}
#g-registration-admin li h3 {
clear: both;
}
</style>
<script type="text/javascript">
$("#g-active-pending-users").ready(function() {
$
});
</script>
<div id="g-admin-register">
<div id="g-registration-admin" style="float: left">
<div id="g-registration-admin">
<h2><?= t("Registration adminstration") ?></h2>
<?= form::open($action, array("method" => "post"), $hidden) ?>
<ul>
<?= form::open_fieldset() ?>
<ul>
<li>
<h3><?= t("Confirmation policy") ?></h3>
<p><?= t("The Gallery3 can accept new user registrations instantly, require the user to click a confirmation link in an email that is sent by the module, or require account activation by a site administrator.") ?><p/>
<?= form::label("policy", t("Choose policy")) ?>
<?= form::dropdown(array("name" => "policy"), $policy_list, $form["policy"]) ?>
</li>
<? foreach ($policy_list as $policy => $text): ?>
<li>
<?= form::radio("policy", $policy, $policy == $form["policy"]) ?>
<?= form::label("policy", $text) ?>
</li>
<? endforeach ?>
<li>
<?= form::checkbox("email_verification", "true", !empty($form["email_verification"]), $no_admin) ?>
<?= form::label("email_verification", t("Require e-mail verification when a visitor creates an account")) ?>
</li>
<li>
<h3><?= t("Default group") ?></h3>
</li>
<li>
<h3><?= t("Default Group") ?></h3>
<?= form::label("group", t("Set default group")) ?>
<?= form::dropdown(array("name" => "group"), $group_list, $form["default_group"]) ?>
</li>
<li>
<h3><?= t("Send email policy") ?></h3>
</li>
<li>
<? if (empty($no_admin)): ?>
<?= form::label("email_admin", t("Email administrator for all new registrations")) ?>
<?= form::checkbox("email_admin", "true", !empty($form["email_admin"])) ?>
</li>
<li>
<?= form::label("email_user", t("Send confirmation email on account activation")) ?>
<?= form::checkbox("email_user", "true", !empty($form["email_user"])) ?>
<? else: ?>
<span <? if (!empty($errors["email_admin"])): ?> class="g-error"<? endif ?>>
<?= form::hidden(array("name" => "email_admin", "value" => "")) ?>
<?= form::hidden(array("name" => "email_user", "value" => "")) ?>
<p class="g-error"><?= t("Unable to set email policies as the administrator email has not been set.") ?></p>
</span>
<?endif ?>
</li>
<li>
<li>
<?= form::submit(array("id" => "g-registration-admin", "name" => "save", "class" => "submit", "style" => "clear:both!important"), t("Update")) ?>
</li>
</ul>
<?= form::close_fieldset() ?>
<?= form::close() ?>
</div>
<? if (count($pending)): ?>
<div id="g-activate-pending-users" style="float: left; margin-top: .5em">
<h2><?= t("Pending account activations") ?></h2>
<div id="g-activate-pending-users" style="margin-top: .5em">
<?= form::open($activate, array("method" => "post"), $hidden) ?>
<ul>
<?= form::open_fieldset() ?>
<ul>
<li>
<h3><?= t("Pending account activations") ?></h3>
</li>
<li>
<table>
<thead>
<tr>
<td><?= t("Activate") ?></td>
<td><?= t("Confirmed") ?></td>
<td><?= t("User name") ?></td>
<td><?= t("Full name") ?></td>
<td><?= t("Email") ?></td>
@ -58,6 +73,7 @@
<? foreach ($pending as $user): ?>
<tr>
<td><?= form::checkbox("activate[]", $user->id) ?>
<td><?= form::checkbox("confirmed[$user->id]", "checked", $user->confirmed, "disabled") ?></td>
<td><?= t($user->name) ?></td>
<td><?= t($user->full_name) ?></td>
<td><?= t($user->email) ?></td>
@ -69,6 +85,7 @@
<?= form::submit(array("id" => "g-registration-activate", "name" => "activate_users", "class" => "submit", "style" => "clear:both!important"), t("Activate")) ?>
</li>
</ul>
<?= form::close_fieldset() ?>
<?= form::close() ?>
</div>
<? endif ?>

View File

@ -0,0 +1,17 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
<head>
<title><?= t("User registration confirmation") ?> </title>
</head>
<body>
<h2><?= t("User registration confirmation") ?> </h2>
<p>
<?= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?>
</p>
<p>
<?= t("We received a request to to create a user with this email. If you made this request, you can confirm it by <a href=\"%confirm_url\">clicking this link</a>. If you didn't request this password reset, it's ok to ignore this mail.",
array("site_url" => html::mark_clean(url::base(false, "http")),
"confirm_url" => $confirm_url)) ?>
</p>
</body>
</html>

View File

@ -0,0 +1,17 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
<head>
<title><?= t("Welcome to Gallery3") ?> </title>
</head>
<body>
<h2><?= t("Welcome") ?> </h2>
<p>
<?= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?>
</p>
<p>
<?= t("The user account you requested as been created.<br/>The password to your account is %password. We suggest you change it on your next visit. <br/>You can access the site by <a href=\"%site_url\">clicking this link</a>.",
array("site_url" => html::mark_clean(url::base(false, "http")),
"password" => $password)) ?>
</p>
</body>
</html>