示例#1
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $config, $page, $user;
     $this->show_user_info();
     if ($event->page_matches("user_admin")) {
         if ($event->get_arg(0) == "login") {
             if (isset($_POST['user']) && isset($_POST['pass'])) {
                 $this->page_login($_POST['user'], $_POST['pass']);
             } else {
                 $this->theme->display_login_page($page);
             }
         } else {
             if ($event->get_arg(0) == "recover") {
                 $this->page_recover($_POST['username']);
             } else {
                 if ($event->get_arg(0) == "create") {
                     $this->page_create();
                 } else {
                     if ($event->get_arg(0) == "list") {
                         // select users.id,name,joindate,admin,
                         // (select count(*) from images where images.owner_id=users.id) as images,
                         // (select count(*) from comments where comments.owner_id=users.id) as comments from users;
                         // select users.id,name,joindate,admin,image_count,comment_count
                         // from users
                         // join (select owner_id,count(*) as image_count from images group by owner_id) as _images on _images.owner_id=users.id
                         // join (select owner_id,count(*) as comment_count from comments group by owner_id) as _comments on _comments.owner_id=users.id;
                         $this->theme->display_user_list($page, User::by_list(0), $user);
                     } else {
                         if ($event->get_arg(0) == "logout") {
                             $this->page_logout();
                         }
                     }
                 }
             }
         }
         if (!$user->check_auth_token()) {
             return;
         } else {
             if ($event->get_arg(0) == "change_name") {
                 $input = validate_input(array('id' => 'user_id,exists', 'name' => 'user_name'));
                 $duser = User::by_id($input['id']);
                 $this->change_name_wrapper($duser, $input['name']);
             } else {
                 if ($event->get_arg(0) == "change_pass") {
                     $input = validate_input(array('id' => 'user_id,exists', 'pass1' => 'password', 'pass2' => 'password'));
                     $duser = User::by_id($input['id']);
                     $this->change_password_wrapper($duser, $input['pass1'], $input['pass2']);
                 } else {
                     if ($event->get_arg(0) == "change_email") {
                         $input = validate_input(array('id' => 'user_id,exists', 'address' => 'email'));
                         $duser = User::by_id($input['id']);
                         $this->change_email_wrapper($duser, $input['address']);
                     } else {
                         if ($event->get_arg(0) == "change_class") {
                             $input = validate_input(array('id' => 'user_id,exists', 'class' => 'user_class'));
                             $duser = User::by_id($input['id']);
                             $this->change_class_wrapper($duser, $input['class']);
                         } else {
                             if ($event->get_arg(0) == "delete_user") {
                                 $this->delete_user($page, isset($_POST["with_images"]), isset($_POST["with_comments"]));
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($event->page_matches("user")) {
         $display_user = $event->count_args() == 0 ? $user : User::by_name($event->get_arg(0));
         if ($event->count_args() == 0 && $user->is_anonymous()) {
             $this->theme->display_error(401, "Not Logged In", "You aren't logged in. First do that, then you can see your stats.");
         } else {
             if (!is_null($display_user) && $display_user->id != $config->get_int("anon_id")) {
                 $e = new UserPageBuildingEvent($display_user);
                 send_event($e);
                 $this->display_stats($e);
             } else {
                 $this->theme->display_error(404, "No Such User", "If you typed the ID by hand, try again; if you came from a link on this " . "site, it might be bug report time...");
             }
         }
     }
 }