예제 #1
0
/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useredit_POST(Web &$w)
{
    $w->pathMatch("id");
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory")));
    if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
        $error[] = "Passwords don't match";
    }
    $user = $w->Auth->getObject("User", $w->ctx('id'));
    if (!$user) {
        $errors[] = "User does not exist";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useredit/" . $w->ctx("id"));
    }
    $user->login = $_REQUEST['login'];
    $user->fill($_REQUEST);
    if ($_REQUEST['password']) {
        $user->setPassword($_REQUEST['password']);
    } else {
        $user->password = null;
    }
    $user->is_admin = isset($_REQUEST['is_admin']) ? 1 : 0;
    $user->is_active = isset($_REQUEST['is_active']) ? 1 : 0;
    $user->update();
    $contact = $user->getContact();
    if ($contact) {
        $contact->fill($_REQUEST);
        $contact->private_to_user_id = null;
        $contact->update();
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " updated.", "/admin/users");
}
예제 #2
0
/**
 * Handle User Edit form submission
 *
 * @param <type> $w
 */
function useradd_POST(Web &$w)
{
    $errors = $w->validate(array(array("login", ".+", "Login is mandatory"), array("password", ".+", "Password is mandatory"), array("password2", ".+", "Password2 is mandatory")));
    if ($_REQUEST['password2'] != $_REQUEST['password']) {
        $errors[] = "Passwords don't match";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/admin/useradd");
    }
    // first saving basic contact info
    $contact = new Contact($w);
    $contact->fill($_REQUEST);
    $contact->dt_created = time();
    $contact->private_to_user_id = null;
    $contact->insert();
    // now saving the user
    $user = new User($w);
    $user->login = $_REQUEST['login'];
    $user->setPassword($_REQUEST['password']);
    $user->is_active = !empty($_REQUEST['is_active']) ? $_REQUEST['is_active'] : 0;
    $user->is_admin = !empty($_REQUEST['is_admin']) ? $_REQUEST['is_admin'] : 0;
    $user->is_group = 0;
    $user->dt_created = time();
    $user->contact_id = $contact->id;
    $user->insert();
    $w->ctx("user", $user);
    // now saving the roles
    $roles = $w->Auth->getAllRoles();
    foreach ($roles as $r) {
        if (!empty($_REQUEST["check_" . $r])) {
            if ($_REQUEST["check_" . $r] == 1) {
                $user->addRole($r);
            }
        }
    }
    $w->callHook("admin", "account_changed", $user);
    $w->msg("User " . $user->login . " added", "/admin/users");
}
예제 #3
0
function profile_POST(Web &$w)
{
    $w->pathMatch("id");
    $errors = $w->validate(array(array("homephone", "^[0-9+\\- ]*\$", "Not a valid home phone number"), array("workphone", "^[0-9+\\- ]*\$", "Not a valid work phone number"), array("mobile", "^[0-9+\\- ]*\$", "Not a valid  mobile phone number"), array("priv_mobile", "^[0-9+\\- ]*\$", "Not a valid  mobile phone number"), array("fax", "^[0-9+\\- ]*\$", "Not a valid fax number")));
    if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
        $errors[] = "Passwords don't match";
    }
    $user = $w->Auth->user();
    if (!$user) {
        $errors[] = "Not Logged In";
    }
    if (sizeof($errors) != 0) {
        $w->error(implode("<br/>\n", $errors), "/auth/profile");
    }
    $user->fill($_REQUEST);
    // Filter out everything except the path so that users cant make redirect urls out of cmfive
    $parse_url = parse_url($user->redirect_url);
    $redirect_url = $parse_url["path"];
    // Menu link doesnt like a leading slash
    if ($redirect_url[0] == "/") {
        $redirect_url = substr($redirect_url, 1);
    }
    $user->redirect_url = $redirect_url;
    if ($_REQUEST['password']) {
        $user->setPassword($_REQUEST['password']);
    } else {
        $user->password = null;
    }
    $user->update();
    $contact = $user->getContact();
    if ($contact) {
        $contact->fill($_REQUEST);
        $contact->private_to_user_id = null;
        $contact->update();
    }
    $w->msg("Profile updated.");
}