public static function get_logged_in_admin_user_name()
 {
     try {
         $alm = Admin_LoginManager::get_instance();
         return $alm->get_name();
     } catch (Exception $e) {
         return 'unknown';
     }
 }
 /**
  * @return
  *  HTMLTags_SimpleOLForm
  *  The form for editing the values of a user to be displayed in the
  *  admin section.
  */
 public function get_edit_user_form()
 {
     $user_row = $this->get_element();
     $edit_user_form = new HTMLTags_SimpleOLForm('edit_user');
     $redirect_script = Admin_AdminIncluderURLFactory::get_url('haddock', 'admin', 'manage-users', 'redirect-script');
     $action_href = clone $redirect_script;
     $action_href->set_get_variable('edit-user');
     $action_href->set_get_variable('user_id', $user_row->get_id());
     $edit_user_form->set_action($action_href);
     $edit_user_form->set_legend_text('Update user');
     /*
      * The user's name
      */
     $svm = Caching_SessionVarManager::get_instance();
     if ($svm->is_set('manage-users-form: name')) {
         $edit_user_form->add_input_name_with_value('name', $svm->get('manage-users-form: name'));
     } else {
         $edit_user_form->add_input_name_with_value('name', $user_row->get_name());
     }
     /*
      * The type of admin user.
      */
     $login_manager = Admin_LoginManager::get_instance();
     $user_types = $login_manager->get_user_types();
     $user_types_select = HTMLTags_SelectFactory::make_select_for_str_array($user_types);
     $user_types_select->set_attribute_str('id', 'type');
     $user_types_select->set_attribute_str('name', 'type');
     if ($svm->is_set('manage-users-form: type')) {
         $user_types_select->set_value($svm->get('manage-users-form: type'));
     } else {
         $user_types_select->set_value($user_row->get_type());
     }
     $edit_user_form->add_input_tag('type', $user_types_select);
     /*
      * The user's real name
      */
     if ($svm->is_set('manage-users-form: real_name')) {
         $edit_user_form->add_input_name_with_value('real_name', $svm->get('manage-users-form: real_name'));
     } else {
         $edit_user_form->add_input_name_with_value('real_name', $user_row->get_real_name());
     }
     /*
      * The user's email
      */
     if ($svm->is_set('manage-users-form: email')) {
         $edit_user_form->add_input_name_with_value('email', $svm->get('manage-users-form: email'));
     } else {
         $edit_user_form->add_input_name_with_value('email', $user_row->get_email());
     }
     $edit_user_form->set_submit_text('Update');
     $cancel_href = clone $redirect_script;
     $cancel_href->set_get_variable('cancel');
     $edit_user_form->set_cancel_location($cancel_href);
     return $edit_user_form;
 }
예제 #3
0
 public function get_log_in_state_div()
 {
     $log_in_state_div = new HTMLTags_Div();
     $log_in_state_div->set_attribute_str('id', 'log-in-state');
     $logged_in_as_p = new HTMLTags_P();
     $logged_in_as_p->set_attribute_str('id', 'logged_in_as');
     $alm = Admin_LoginManager::get_instance();
     $logged_in_as_p->append_str_to_content('<em>User:</em> ' . $alm->get_name());
     $logged_in_as_p->append_str_to_content('&nbsp;');
     $logged_in_as_p->append_str_to_content('<em>Type:</em> ' . $alm->get_type());
     $log_in_state_div->append($logged_in_as_p);
     $log_out_div = new HTMLTags_Div();
     $log_out_div->set_attribute_str('id', 'log_out');
     $log_out_div->append_tag_to_content($alm->get_log_out_a());
     $log_in_state_div->append($log_out_div);
     return $log_in_state_div;
 }
 /**
  * This where we check whether the user is logged in or not.
  *
  * This has been copied directly from Admin_RestrictedHTMLPage.
  *
  * Delegation refactoring, anyone?
  */
 public function send_http_headers()
 {
     parent::send_http_headers();
     /*
      * Make sure that the user is logged in.
      */
     $alm = Admin_LoginManager::get_instance();
     if (!$alm->is_logged_in()) {
         $_SESSION['admin-login-data']['desired-url'] = new HTMLTags_URL();
         $_SESSION['admin-login-data']['desired-url']->set_file('/hc/admin/navigation.html');
         $redirection_manager = new PublicHTML_RedirectionManager();
         $redirection_url = $redirection_manager->get_url();
         $redirection_url->set_file('/hc/admin/login.html');
         $location_header_line = 'Location: ' . $redirection_url->get_as_string();
         header($location_header_line);
         exit;
     }
 }
    public static function reset_user_password(Admin_UserEntry $user_entry)
    {
        $real_name = $user_entry->get_real_name();
        /*
         * Check that the user has an email address to send the
         * new password to.
         */
        if (strlen($user_entry->get_email()) == 0) {
            throw new Exception('Unable to reset the password of ' . $user_entry->get_real_name() . ' as no email address has been set!');
        }
        /*
         * Generate the new password.
         */
        $pwg = Security_PasswordGenerator::get_instance();
        $pw = $pwg->get_password();
        /*
         * Check that there is an admin for this site.
         */
        $from_email = '';
        /*
         * Compose an email.
         *
         * How can this be edited and overridden?
         */
        $email_title = 'New password for ' . $user_entry->get_real_name();
        $to_email = $user_entry->get_email();
        $email_body = <<<EML
Dear {$real_name},

Your password has been reset to '{$pw}'.
EML;
        if (mail($to_email, $from_email, $email_body, "From: {$from_email};\r\nReply-To: {$from_email}")) {
            $alm = Admin_LoginManager::get_instance();
            $alm->set_password($user_entry->get_name(), $pw);
        } else {
            throw new Exception("Unable to send a password reset email to {$to_email}!");
        }
    }
예제 #6
0
<?php

/**
 * Security restrictions for the admin-includer page.
 *
 * @copyright Clear Line Web Design, 2007-08-19
 */
$alm = Admin_LoginManager::get_instance();
if (!$alm->is_logged_in()) {
    $_SESSION['admin-login-data']['desired-url'] = new HTMLTags_URL();
    $_SESSION['admin-login-data']['desired-url']->set_file('/hc/admin/navigation.html');
    $redirection_manager = new PublicHTML_RedirectionManager();
    $redirection_url = $redirection_manager->get_url();
    $redirection_url->set_file('/hc/admin/login.html');
    $location_header_line = 'Location: ' . $redirection_url->get_as_string();
    header($location_header_line);
    exit;
}
예제 #7
0
<?php

/**
 * Security for the admin pages.
 *
 * @copyright Clear Line Web Design, 2007-08-06
 */
$admin_login_manager = Admin_LoginManager::get_instance();
if (!$admin_login_manager->is_logged_in()) {
    $page_manager = PublicHTML_PageManager::get_instance();
    unset($_SESSION['admin-login-data']);
    #$_SESSION['admin-login-data']['desired-url'] = $page_manager->get_script_uri();
    $script_uri = $page_manager->get_script_uri();
    $desired_uri = new HTMLTags_URL();
    $desired_uri->set_file('/');
    foreach (array_keys($_GET) as $key) {
        $desired_uri->set_get_variable($key, $_GET[$key]);
    }
    $suggv = $script_uri->get_get_variables();
    foreach (array_keys($suggv) as $key) {
        $desired_uri->set_get_variable($key, $suggv[$key]);
    }
    //$_SESSION['admin-login-data']['desired-url'] = '/';
    //
    //$first = TRUE;
    //foreach (array_keys($desired_get_vars) as $key) {
    //    if ($first) {
    //        $first = FALSE;
    //    } else {
    //        $_SESSION['admin-login-data']['desired-url'] = '&';
    //    }
 public function do_actions()
 {
     /*
      * Get the name, make sure that it is valid.
      */
     if (isset($args['name'])) {
         $name = $args['name'];
     } else {
         echo "Please enter the name: \n";
         $name = trim(fgets(STDIN));
     }
     #echo "$name\n"; exit;
     $admin_login_manager = Admin_LoginManager::get_instance();
     #print_r($admin_login_manager); exit;
     while (TRUE) {
         try {
             #echo "Reached the try block\n"; exit;
             if ($admin_login_manager->is_name_valid($name)) {
                 #echo "The name is valid.\n"; exit;
                 if ($admin_login_manager->is_name_available($name)) {
                     #echo "The name is acceptable\n."; exit;
                     if (!$silent) {
                         echo "{$name} is an acceptable new name.\n";
                     }
                     break;
                 } else {
                     echo "{$name} is not available.\n";
                 }
             }
         } catch (InputValidation_InvalidInputException $e) {
             echo $e->getMessage() . "\n";
         }
         echo "Please try another name: \n";
         $name = trim(fgets(STDIN));
     }
     #echo "$name\n"; exit;
     /*
      * Get the password.
      */
     if (isset($args['password'])) {
         $password = $args['password'];
     } else {
         echo "Please enter the password: \n";
         $password = trim(fgets(STDIN));
     }
     while (TRUE) {
         try {
             if ($admin_login_manager->is_password_valid($password)) {
                 if (!$silent) {
                     echo "{$password} is an acceptable new password.\n";
                 }
                 break;
             }
         } catch (InputValidation_InvalidInputException $e) {
             echo $e->getMessage() . "\n";
         }
         echo "Please try another password: \n";
         $password = trim(fgets(STDIN));
     }
     /*
      * Get the type of user.
      */
     $type = '';
     if (isset($args['type'])) {
         $type = $args['type'];
     }
     if (!$admin_login_manager->is_type_valid($type)) {
         if (strlen($type) > 0) {
             echo "Type not valid.\n";
         }
         $types = $admin_login_manager->get_user_types();
         $choice_str = join(' ', $types);
         $type = CLIScripts_InputReader::get_choice_from_string($choice_str);
         if ($type == NULL) {
             echo "Quitting!\n";
             exit;
         }
     }
     /*
      * Get the real name of the user.
      */
     $real_name = '';
     if (isset($args['real-name'])) {
         $real_name = $args['real-name'];
     } else {
         echo "Please enter the real name of the user.\n";
         $real_name = trim(fgets(STDIN));
     }
     /*
      * Get the email address of the user.
      */
     $email = '';
     $got_valid_email = FALSE;
     if (isset($args['email'])) {
         $email = $args['email'];
     }
     $validator = new InputValidation_EmailAddressValidator();
     if (strlen($email) > 0) {
         try {
             $validator->validate($email);
             $got_valid_email = TRUE;
         } catch (InputValidation_InvalidInputException $e) {
             echo $e->getMessage() . "\n";
             $got_valid_email = FALSE;
         }
     } else {
         $got_valid_email = FALSE;
     }
     if (!$got_valid_email) {
         $email = CLIScripts_InputReader::get_validated_input("Please enter a valid email address: \n", $validator);
     }
     if (!$silent) {
         echo "The name: {$name}\n";
         echo "The password: {$password}\n";
         echo "The type: {$type}\n";
         echo "Real name: {$real_name}\n";
         echo "Email: {$email}\n";
     }
     $admin_login_manager->add_new_user($name, $password, $type, $real_name, $email);
     if (!$silent) {
         echo "New user added.\n";
     }
 }
 public static function is_logged_id()
 {
     $alm = Admin_LoginManager::get_instance();
     return $alm->is_logged_in();
 }