Browse Source

引継ぎコード追加

main
みてるぞ 1 year ago
parent
commit
c451fff119
3 changed files with 15 additions and 2 deletions
  1. +1
    -0
      create_user.php
  2. +2
    -0
      migrations/2023_07_13_122000_add_columns_to_users_table.sql
  3. +12
    -2
      modules/user.mod.php

+ 1
- 0
create_user.php View File

@@ -12,6 +12,7 @@ $user = new User;
$user -> name = $_GET['name']; $user -> name = $_GET['name'];
$user -> pass = implode ( $user -> pass = implode (
array_map (fn () => $chars[rand (0, strlen ($chars) - 1)], range (1, 8))); 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]; echo [$user -> insert () -> id];



+ 2
- 0
migrations/2023_07_13_122000_add_columns_to_users_table.sql View File

@@ -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`;


+ 12
- 2
modules/user.mod.php View File

@@ -6,6 +6,7 @@ User
var $id; var $id;
var $name; var $name;
var $pass; var $pass;
var $inheritance_code;


public static function public static function
find ( find (
@@ -28,6 +29,7 @@ User
$self -> id = $id; $self -> id = $id;
$self -> name = $row['name']; $self -> name = $row['name'];
$self -> pass = $row['pass']; $self -> pass = $row['pass'];
$self -> inheritance_code = $row['inheritance_code'];


return $self; return $self;
} }
@@ -38,8 +40,16 @@ User
{ {
$sql = " $sql = "
INSERT INTO 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) $GLOBALS['__db_connection'] -> query ($sql)
or die ("db_insert error $sql"); or die ("db_insert error $sql");




Loading…
Cancel
Save