Added UserLoginEvent
This commit is contained in:
		
							parent
							
								
									761834b6fa
								
							
						
					
					
						commit
						cf8ed3b134
					
				| @ -191,6 +191,8 @@ class CommandEvent extends Event | |||||||
|                     $user = User::by_name($args[++$i]); |                     $user = User::by_name($args[++$i]); | ||||||
|                     if (is_null($user)) { |                     if (is_null($user)) { | ||||||
|                         die("Unknown user"); |                         die("Unknown user"); | ||||||
|  |                     } else { | ||||||
|  |                         send_event(new UserLoginEvent($user)); | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case '-q': |                 case '-q': | ||||||
|  | |||||||
| @ -58,6 +58,7 @@ class DanbooruApi extends Extension | |||||||
|             } else { |             } else { | ||||||
|                 $user = User::by_id($config->get_int("anon_id", 0)); |                 $user = User::by_id($config->get_int("anon_id", 0)); | ||||||
|             } |             } | ||||||
|  |             send_event(new UserLoginEvent($user)); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -750,6 +750,7 @@ class OuroborosAPI extends Extension | |||||||
|             } else { |             } else { | ||||||
|                 $user = User::by_id($config->get_int("anon_id", 0)); |                 $user = User::by_id($config->get_int("anon_id", 0)); | ||||||
|             } |             } | ||||||
|  |             send_event(new UserLoginEvent($user)); | ||||||
|         } elseif (isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'session']) && |         } elseif (isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'session']) && | ||||||
|             isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'user']) |             isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'user']) | ||||||
|         ) { |         ) { | ||||||
| @ -762,6 +763,7 @@ class OuroborosAPI extends Extension | |||||||
|             } else { |             } else { | ||||||
|                 $user = User::by_id($config->get_int("anon_id", 0)); |                 $user = User::by_id($config->get_int("anon_id", 0)); | ||||||
|             } |             } | ||||||
|  |             send_event(new UserLoginEvent($user)); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,6 +27,12 @@ class UserPage extends Extension | |||||||
|         $config->set_default_bool("login_tac_bbcode", true); |         $config->set_default_bool("login_tac_bbcode", true); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function onUserLogin(UserLoginEvent $event) | ||||||
|  |     { | ||||||
|  |         global $user; | ||||||
|  |         $user = $event->user; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function onPageRequest(PageRequestEvent $event) |     public function onPageRequest(PageRequestEvent $event) | ||||||
|     { |     { | ||||||
|         global $config, $database, $page, $user; |         global $config, $database, $page, $user; | ||||||
| @ -347,7 +353,7 @@ class UserPage extends Extension | |||||||
| 
 | 
 | ||||||
|         $duser = User::by_name_and_pass($name, $pass); |         $duser = User::by_name_and_pass($name, $pass); | ||||||
|         if (!is_null($duser)) { |         if (!is_null($duser)) { | ||||||
|             $user = $duser; |             send_event(new UserLoginEvent($duser)); | ||||||
|             $this->set_login_cookie($duser->name, $pass); |             $this->set_login_cookie($duser->name, $pass); | ||||||
|             $page->set_mode(PageMode::REDIRECT); |             $page->set_mode(PageMode::REDIRECT); | ||||||
| 
 | 
 | ||||||
| @ -460,6 +466,8 @@ class UserPage extends Extension | |||||||
|         $uid = $database->get_last_insert_id('users_id_seq'); |         $uid = $database->get_last_insert_id('users_id_seq'); | ||||||
|         $user = User::by_name($event->username); |         $user = User::by_name($event->username); | ||||||
|         $user->set_password($event->password); |         $user->set_password($event->password); | ||||||
|  |         send_event(new UserLoginEvent($user)); | ||||||
|  | 
 | ||||||
|         log_info("user", "Created User #$uid ({$event->username})"); |         log_info("user", "Created User #$uid ({$event->username})"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,6 +6,10 @@ | |||||||
|  * Visibility: admin |  * Visibility: admin | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | /** @var $user_config Config */ | ||||||
|  | global $user_config; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // The user object doesn't exist until after database setup operations and the first wave of InitExtEvents,
 | // The user object doesn't exist until after database setup operations and the first wave of InitExtEvents,
 | ||||||
| // so we can't reliably access this data until then. This event is triggered by the system after all of that is done.
 | // so we can't reliably access this data until then. This event is triggered by the system after all of that is done.
 | ||||||
| class InitUserConfigEvent extends Event | class InitUserConfigEvent extends Event | ||||||
| @ -13,9 +17,10 @@ class InitUserConfigEvent extends Event | |||||||
|     public $user; |     public $user; | ||||||
|     public $user_config; |     public $user_config; | ||||||
| 
 | 
 | ||||||
|     public function __construct(User $user) |     public function __construct(User $user, Config $user_config) | ||||||
|     { |     { | ||||||
|         $this->user = $user; |         $this->user = $user; | ||||||
|  |         $this->user_config = $user_config; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -32,11 +37,12 @@ class UserConfig extends Extension | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function onInitUserConfig(InitUserConfigEvent $event) { |     public function onUserLogin(UserLoginEvent $event) | ||||||
|  |     { | ||||||
|         global $database, $user_config; |         global $database, $user_config; | ||||||
| 
 | 
 | ||||||
|         $user_config = new DatabaseConfig($database, "user_config", "user_id", $event->user->id); |         $user_config = new DatabaseConfig($database, "user_config", "user_id", $event->user->id); | ||||||
|         $event->user_config  = $user_config; |         send_event(new InitUserConfigEvent($event->user, $user_config)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private function install(): void |     private function install(): void | ||||||
|  | |||||||
| @ -92,7 +92,7 @@ try { | |||||||
| 
 | 
 | ||||||
|     // start the page generation waterfall
 |     // start the page generation waterfall
 | ||||||
|     $user = _get_user(); |     $user = _get_user(); | ||||||
|     send_event(new InitUserConfigEvent($user)); |     send_event(new UserLoginEvent($user)); | ||||||
|     if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { |     if (PHP_SAPI === 'cli' || PHP_SAPI == 'phpdbg') { | ||||||
|         send_event(new CommandEvent($argv)); |         send_event(new CommandEvent($argv)); | ||||||
|     } else { |     } else { | ||||||
|  | |||||||
| @ -133,7 +133,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase | |||||||
|         global $user; |         global $user; | ||||||
|         $user = User::by_name('demo'); |         $user = User::by_name('demo'); | ||||||
|         $this->assertNotNull($user); |         $this->assertNotNull($user); | ||||||
|         send_event(new InitUserConfigEvent($user)); |         send_event(new UserLoginEvent($user)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected function log_in_as_user() |     protected function log_in_as_user() | ||||||
| @ -141,7 +141,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase | |||||||
|         global $user; |         global $user; | ||||||
|         $user = User::by_name('test'); |         $user = User::by_name('test'); | ||||||
|         $this->assertNotNull($user); |         $this->assertNotNull($user); | ||||||
|         send_event(new InitUserConfigEvent($user)); |         send_event(new UserLoginEvent($user)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected function log_out() |     protected function log_out() | ||||||
| @ -149,7 +149,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase | |||||||
|         global $user, $config; |         global $user, $config; | ||||||
|         $user = User::by_id($config->get_int("anon_id", 0)); |         $user = User::by_id($config->get_int("anon_id", 0)); | ||||||
|         $this->assertNotNull($user); |         $this->assertNotNull($user); | ||||||
|         send_event(new InitUserConfigEvent($user)); |         send_event(new UserLoginEvent($user)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // post things
 |     // post things
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user