function initialize_page()
{
    // if there's more than one user, don't do anything.
    $count = MyActiveRecord::Count('Users');
    if ($count == 0) {
        $admin_user = MyActiveRecord::Create('Users', array('email' => '*****@*****.**', 'password' => sha1(SHA_SALT . 'hcd_admin'), 'is_admin' => 1));
        $admin_user->save();
    }
    redirect("/admin/");
}
Beispiel #2
0
function initialize_page()
{
    LoginRequired("/admin/login/", array("admin"));
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Add User" || $post_action == "Add and Send New User Email") {
        $email = $_POST['email'];
        $password = $_POST['password'];
        $possible_space = strrpos($password, " ");
        if (empty($email) || empty($password)) {
            setFlash("<h3>Please enter a username and/or password of at least 6 characters and no spaces</h3>");
        } else {
            if ($possible_space == true) {
                setFlash("<h3>No spaces are allowed in a password</h3>");
            } else {
                if (strlen(utf8_decode($password)) < 6) {
                    setFlash("<h3>A password should contain at least 6 characters and no spaces</h3>");
                } else {
                    $count = MyActiveRecord::Count('Users', "email = '{$email}'");
                    if ($count > 0) {
                        $duplicate = Users::FindByEmail($email);
                        setFlash("<h3>User already exists (see below)</h3>");
                        redirect("/admin/edit_user" . $duplicate->id);
                    } else {
                        $new_user = MyActiveRecord::Create('Users', $_POST);
                        $new_user->hash_password();
                        $new_user->is_admin = checkboxValue($_POST, 'is_admin');
                        $new_user->is_staff = $new_user->is_admin ? 0 : 1;
                        $new_user->save();
                        $success = "User added";
                        if ($post_action == "Add User and Send New User Email") {
                            $new_user->send_newuser_email($_POST['password']);
                            $success .= " / Email Notification Sent";
                        }
                        setFlash("<h3>" . $success . "</h3>");
                        redirect("/admin/list_users");
                    }
                }
            }
        }
    }
}
 /**
  * Validates the uniqueness of the value of a given field/key.
  * Adds error to object if field is not unique
  *
  * @param string  strKey  name of field/attribute/key
  * @param string  strMessage  Error message to record if value is not unique
  * @return  boolean true if field is unique, false if not
  */
 public function validate_uniqueness_of($strKey, $strMessage = null)
 {
     if (MyActiveRecord::Count(get_class($this), "{$strKey} = '{$this->{$strKey}}'") > 0) {
         $this->add_error($strKey, $strMessage ? $strMeassage : ucfirst($strKey) . ' is not unique');
         return false;
     } else {
         return true;
     }
 }