diff options
-rw-r--r-- | actions/login.php | 2 | ||||
-rw-r--r-- | actions/logout.php | 2 | ||||
-rw-r--r-- | actions/register.php | 28 | ||||
-rw-r--r-- | engine/lib/entities.php | 6 | ||||
-rw-r--r-- | engine/lib/users.php | 32 | ||||
-rw-r--r-- | languages/en.php | 4 | ||||
-rw-r--r-- | views/default/login.php | 5 |
7 files changed, 73 insertions, 6 deletions
diff --git a/actions/login.php b/actions/login.php index dbc84bab5..e79799a30 100644 --- a/actions/login.php +++ b/actions/login.php @@ -1,7 +1,7 @@ <?php
/**
- * Elgg login action page
+ * Elgg login action
*
* @package Elgg
* @subpackage Core
diff --git a/actions/logout.php b/actions/logout.php index 99ef5abf6..2bcb538de 100644 --- a/actions/logout.php +++ b/actions/logout.php @@ -1,7 +1,7 @@ <?php
/**
- * Elgg logout action page
+ * Elgg logout action
*
* @package Elgg
* @subpackage Core
diff --git a/actions/register.php b/actions/register.php new file mode 100644 index 000000000..2e8c5b414 --- /dev/null +++ b/actions/register.php @@ -0,0 +1,28 @@ +<?php
+
+ /**
+ * Elgg registration action
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+
+ // Get variables
+ $username = get_input($username);
+ $password = get_input($password);
+ $password2 = get_input($password2);
+ $email = get_input($email);
+ $name = get_input($name);
+
+ // For now, just try and register the user
+ if (register_user($username, $password, $name, $email)) {
+ system_message(sprintf(elgg_echo("registerok"),$CONFIG->sitename));
+ } else {
+ system_message(elgg_echo("registerbad"));
+ }
+
+?>
\ No newline at end of file diff --git a/engine/lib/entities.php b/engine/lib/entities.php index fb161bbd1..66f421a6d 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -488,8 +488,10 @@ $access_id = (int)$access_id; $time = time(); - if ($type=="") throw new InvalidParameterException("Entity type must be set."); - if ($owner_guid==0) throw new InvalidParameterException("owner_guid must not be 0"); + if ($type=="") throw new InvalidParameterException("Entity type must be set.");
+
+ // Erased by Ben: sometimes we need unauthenticated users to create things! (eg users on registration) + // if ($owner_guid==0) throw new InvalidParameterException("owner_guid must not be 0"); return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $access_id, $time, $time)"); } diff --git a/engine/lib/users.php b/engine/lib/users.php index e8e6554f9..2c2465ced 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -457,4 +457,36 @@ return false;
} +
+ function register_user(string $username, string $password, string $name, string $email) {
+
+ // Load the configuration
+ global $CONFIG;
+
+ // A little sanity checking
+ if (empty($username)
+ || empty($password)
+ || empty($name)
+ || empty($email))
+ return false;
+
+ // Check to see if $username exists already
+ if ($user = get_user_by_username($username)) {
+ return false;
+ }
+
+ // Otherwise ...
+ $user = new ElggUser();
+ $user->username = $username;
+ $user->password = md5($password);
+ $user->email = $email;
+ $user->name = $name;
+ return $user->save();
+
+ }
+
+ //register actions *************************************************************
+
+ register_action("register",true);
+
?>
\ No newline at end of file diff --git a/languages/en.php b/languages/en.php index 23f398c93..49ac9c647 100644 --- a/languages/en.php +++ b/languages/en.php @@ -46,6 +46,10 @@ 'account' => "Account",
+ 'register' => "Register",
+ 'registerok' => "You have successfully registered for %s.",
+ 'registerbad' => "Your registration was unsuccessful. The username may already exist, or your passwords might not match.",
+
/**
* Welcome
*/
diff --git a/views/default/login.php b/views/default/login.php index ab096d41f..c17f87b33 100644 --- a/views/default/login.php +++ b/views/default/login.php @@ -15,9 +15,10 @@ <div id="login-box">
<form action="<?php echo $vars['url']; ?>action/login" method="POST">
- <label><?php echo elgg_echo('username'); ?><br /><input name="username" type="text" class="general-textarea" /></label>
+ <p><label><?php echo elgg_echo('username'); ?><br /><input name="username" type="text" class="general-textarea" /></label>
<br />
<label><?php echo elgg_echo('password'); ?><br /><input name="password" type="password" class="general-textarea" /></label><br />
- <input type="submit" name="submit" value="<?php echo elgg_echo('login'); ?>" />
+ <input type="submit" name="submit" value="<?php echo elgg_echo('login'); ?>" /></p>
+ <p><a href="<?php echo $vars['url']; ?>register.php"><?php echo elgg_echo('register'); ?></a></p>
</form>
</div>
\ No newline at end of file |