2009-10-30 20:19:57 +00:00
|
|
|
<?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 {
|
2009-11-03 22:45:52 +00:00
|
|
|
private static $_states;
|
|
|
|
|
|
|
|
static function format_registration_state($state) {
|
|
|
|
if (empty(self::$_state)) {
|
|
|
|
self::$_states = array(t("Unconfirmed"), t("Confirmed"), t("Activated"));
|
|
|
|
}
|
|
|
|
return self::$_states[$state];
|
|
|
|
}
|
|
|
|
|
|
|
|
static function check_user_name($user_name) {
|
|
|
|
if (identity::lookup_user_by_name($user_name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$user = ORM::factory("pending_user")
|
|
|
|
->where("name", $user_name)
|
|
|
|
->find();
|
|
|
|
return $user->loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function send_user_created_confirmation($user) {
|
2009-10-30 20:19:57 +00:00
|
|
|
$message = new View("register_welcome.html");
|
|
|
|
$message->user = $user;
|
2009-11-03 22:45:52 +00:00
|
|
|
$message->site_url = url::abs_site("register/first/{$user->hash}");
|
2009-10-30 20:19:57 +00:00
|
|
|
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;
|
2009-11-03 22:45:52 +00:00
|
|
|
$user->request_date = time();
|
|
|
|
|
2009-10-30 20:19:57 +00:00
|
|
|
if (!$email_verification) {
|
2009-11-03 22:45:52 +00:00
|
|
|
$user->state = 1;
|
2009-10-30 20:19:57 +00:00
|
|
|
}
|
|
|
|
$user->hash = md5(rand());
|
|
|
|
$user->save();
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
2009-11-03 22:45:52 +00:00
|
|
|
static function create_new_user($id) {
|
|
|
|
$user = ORM::factory("pending_user", $id);
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
identity::add_user_to_group($new_user, module::get_var("registration", "default_group"));
|
|
|
|
|
|
|
|
$user->hash = md5(rand());
|
|
|
|
$user->state = 2;
|
|
|
|
$user->save();
|
|
|
|
self::send_user_created_confirmation($user, $password);
|
|
|
|
|
|
|
|
return $new_user;
|
|
|
|
}
|
|
|
|
|
2009-10-30 20:19:57 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|