diff --git a/create_user.php b/create_user.php index 2883b17..d28d0ff 100644 --- a/create_user.php +++ b/create_user.php @@ -12,6 +12,7 @@ $user = new User; $user -> name = $_GET['name']; $user -> pass = implode ( array_map (fn () => $chars[rand (0, strlen ($chars) - 1)], range (1, 8))); +$user -> inheritance_code = implode (array_map (fn () => rand (0, 9), range (1, 12))); echo [$user -> insert () -> id]; diff --git a/migrations/2023_07_13_122000_add_columns_to_users_table.sql b/migrations/2023_07_13_122000_add_columns_to_users_table.sql new file mode 100644 index 0000000..6bb15bc --- /dev/null +++ b/migrations/2023_07_13_122000_add_columns_to_users_table.sql @@ -0,0 +1,2 @@ +ALTER TABLE `users` ADD `inheritance_code` VARCHAR(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '引継ぎコード' AFTER `pass`, ADD `created_at` DATETIME NOT NULL AFTER `inheritance_code`, ADD `modified_at` DATETIME on update CURRENT_TIMESTAMP NOT NULL AFTER `created_at`, ADD `deleted_at` DATETIME NULL DEFAULT NULL AFTER `modified_at`; + diff --git a/modules/user.mod.php b/modules/user.mod.php index a5be820..8fd1789 100644 --- a/modules/user.mod.php +++ b/modules/user.mod.php @@ -6,6 +6,7 @@ User var $id; var $name; var $pass; + var $inheritance_code; public static function find ( @@ -28,6 +29,7 @@ User $self -> id = $id; $self -> name = $row['name']; $self -> pass = $row['pass']; + $self -> inheritance_code = $row['inheritance_code']; return $self; } @@ -38,8 +40,16 @@ User { $sql = " INSERT INTO - users (name, pass) - VALUES ('{$this -> name}', '{$this -> pass}')"; + users ( + name, + pass, + inheritance_code, + created_at) + VALUES + ('{$this -> name}', + '{$this -> pass}', + '{$this -> inheritance_code}', + NOW())"; $GLOBALS['__db_connection'] -> query ($sql) or die ("db_insert error $sql");