コード例 #1
0
ファイル: dashboard.php プロジェクト: JulioCF/cutenews-2.0
function dashboard_userman()
{
    list($section, $st, $delete) = GET('section, st, delete');
    list($user_name, $user_pass, $user_confirm, $user_nick, $user_email, $user_acl) = GET('user_name, user_pass, user_confirm, user_nick, user_email, user_acl');
    $per_page = 100;
    $section = intval($section);
    $st = intval($st);
    $grp = getoption('#grp');
    $is_edit = FALSE;
    //visability Edit btton
    if (request_type('POST')) {
        cn_dsi_check();
        // Do Delete
        if ($delete) {
            db_user_delete($user_name);
            cn_throw_message('User [' . cn_htmlspecialchars($user_name) . '] deleted');
            $user_name = $user_nick = $user_email = $user_acl = '';
        } else {
            $user_data = db_user_by_name($user_name);
            if (REQ('edit')) {
                if ($user_data === null) {
                    $is_edit = FALSE;
                    cn_throw_message("User not exists", 'e');
                }
            } else {
                // Check user
                if (!$user_name) {
                    cn_throw_message("Fill required field: username", 'e');
                }
                if (!$user_pass) {
                    cn_throw_message("Fill required field: password", 'e');
                }
                if ($user_data !== null) {
                    cn_throw_message("Username already exist", 'e');
                }
                if ($user_confirm != $user_pass) {
                    cn_throw_message('Confirm not match', 'e');
                }
                // Invalid email
                if (!check_email($user_email)) {
                    cn_throw_message("Email not valid", "e");
                } elseif (db_user_by($user_email, 'email')) {
                    cn_throw_message('Email already exists', 'e');
                }
            }
            // Must be correct all
            if (cn_get_message('e', 'c') == 0) {
                // Edit user [user exist]
                if (REQ('edit')) {
                    db_user_update($user_name, "email={$user_email}", "nick={$user_nick}", "acl={$user_acl}");
                    // Update exists (change password)
                    if ($user_pass) {
                        if ($user_confirm == $user_pass) {
                            db_user_update($user_name, 'pass='******'User password / user info updated');
                        } else {
                            cn_throw_message('Confirm not match', 'e');
                        }
                    } else {
                        cn_throw_message('User info updated');
                    }
                } else {
                    if ($user_id = db_user_add($user_name, $user_acl)) {
                        if (db_user_update($user_name, "email={$user_email}", "nick={$user_nick}", 'pass='******'t update user", 'e');
                        }
                    } else {
                        cn_throw_message("User not added: internal error", 'e');
                    }
                }
            }
        }
    }
    // ----
    $userlist = db_user_list();
    // Get users by ACL from index
    if ($section) {
        foreach ($userlist as $id => $dt) {
            if ($dt['acl'] != $section) {
                unset($userlist[$id]);
            }
        }
    }
    // Sort by latest & make pagination
    krsort($userlist);
    $userlist = array_slice($userlist, $st, $per_page, TRUE);
    // Fetch estimate user list
    foreach ($userlist as $id => $data) {
        $user = db_user_by($id);
        $userlist[$id] = $user;
    }
    // Retrieve info about user
    if ($user = db_user_by_name($user_name)) {
        $user_nick = isset($user['nick']) ? $user['nick'] : '';
        $user_email = isset($user['email']) ? $user['email'] : '';
        $user_acl = isset($user['acl']) ? $user['acl'] : '';
        $is_edit = TRUE;
    }
    // By default for section
    if (!$user_acl) {
        $user_acl = $section;
    }
    cn_assign('users, section, st, per_page, grp', $userlist, $section, $st, $per_page, $grp);
    cn_assign('user_name, user_nick, user_email, user_acl, is_edit', $user_name, $user_nick, $user_email, $user_acl, $is_edit);
    echoheader('-@dashboard/style.css', "Users manager");
    echo exec_tpl('dashboard/users');
    echofooter();
}
コード例 #2
0
ファイル: coreflat.php プロジェクト: JulioCF/cutenews-2.0
 function user_lookup($username)
 {
     $users = db_user_list();
     foreach ($users as $uid => $acl) {
         $user = db_user_by($uid);
         if (isset($user['name']) && $user['name'] == $username) {
             return $user;
         }
     }
     return null;
 }