Exemplo n.º 1
0
function registration_on_create(&$api)
{
    include dirname(__FILE__) . '/registration_controller.class.php';
    $registration = new RegistrationController($api);
    $user = init_user_from_post_data();
    if ($_POST['cancel']) {
        $api->refer_to(cfg('site_url'));
    }
    // Check the data for completeness.
    $err = $user->check_complete();
    if ($err) {
        $registration->add_hint(new \hint\Error($err));
    }
    if ($_POST['password'] !== $_POST['password2']) {
        $registration->add_hint(new \hint\Error(_('Error: Passwords do not match.')));
    }
    if ($registration->has_errors()) {
        return $registration->show($user);
    }
    // Make sure that the name is available.
    if (!$api->userdb()->username_is_available($user->get_name())) {
        $err = _('The entered username is not available.');
        $registration->add_hint(new \hint\Error($err));
    }
    // Make sure that the email address is available.
    if ($api->userdb()->get_user_from_mail($user->get_mail())) {
        $err = _('The given email address already exists in our database.');
        $registration->add_hint(new \hint\Error($err));
    }
    if ($registration->has_errors()) {
        return $registration->show($user);
    }
    // Create the user.
    $user->set_group_id(cfg('default_group_id'));
    if (!$api->userdb()->save_user($user)) {
        $registration->add_hint(new \hint\Error(_('Failed to save the user.')));
        return $registration->show($user);
    }
    // Done.
    registration_mail_send($api, $user);
}
Exemplo n.º 2
0
 function _password_mail_submit()
 {
     $this->_import_login();
     $controller = new LoginController($this->api);
     $user = init_user_from_post_data();
     // Make sure that the email address is valid.
     $err = $user->check_mail();
     if ($err) {
         $controller->add_hint(new \hint\Error($err));
         return $controller->show_password_forgotten($user);
     }
     // Find the user with the given mail address.
     $userdb = $this->get_userdb();
     $user = $userdb->get_user_from_mail($user->get_mail());
     if (!$user) {
         $user = init_user_from_post_data();
         $msg = _('The given email address was not found.');
         $controller->add_hint(new \hint\Error($msg));
         return $controller->show_password_forgotten($user);
     }
     // Send the mail.
     if (!$user->is_confirmed()) {
         $url = new FreechURL(cfg('site_url'));
         $url->set_var('action', 'account_reconfirm');
         $url->set_var('username', $user->get_name());
         $this->_refer_to($url->get_string());
     } elseif ($user->is_active()) {
         $this->_send_password_reset_mail($user);
     } elseif ($user->is_locked()) {
         $controller->add_hint(new \hint\Error(_('Your account is locked.')));
         return $controller->show_password_forgotten($user);
     } else {
         die('Invalid user status');
     }
     // Done.
     $controller->show_password_mail_sent($user);
 }