Продолжение переписывания
This commit is contained in:
@@ -9,6 +9,30 @@ require_once("index.php");
|
||||
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
/*
|
||||
* FUNCTION
|
||||
* Create new user account
|
||||
*/
|
||||
function User_Create (string $login, string $password, ?string $email = null, ?string $invite_id = null, ?string $avatar_path = null): ReturnT {
|
||||
$salt = Utils_GenerateRandomString(8);
|
||||
$pwd_hash = hash("sha256", $password . $salt, true);
|
||||
|
||||
// TODO: process invite
|
||||
|
||||
$s = $db->prepare("INSERT INTO users (login,email,password_hash,salt,avatar_path,role,invite_id) VALUES (?,?,?,?,?,?,?)");
|
||||
$role = "newbie"; // TODO: make decision from config
|
||||
$s->bind_param("sssssss", $login, $email, $pwd_hash, $salt, $avatar_path, $role, $invite_id);
|
||||
|
||||
if ($s->execute() === false)
|
||||
return new ReturnT(err_code: E_DBE_INSERTFAIL, err_desc: "cant insert record to users DB");
|
||||
|
||||
return new ReturnT(data: true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Methods
|
||||
|
||||
/*
|
||||
@@ -77,22 +101,7 @@ function User_Create_Method (array $req): ReturnT {
|
||||
|
||||
// Actions
|
||||
|
||||
$result = null;
|
||||
|
||||
$salt = Utils_GenerateRandomString(8);
|
||||
$pwd_hash = hash("sha256", $password . $salt, true);
|
||||
|
||||
// TODO: process invite
|
||||
|
||||
$s = $db->prepare("INSERT INTO users (login,email,password_hash,salt,avatar_path,role,invite_id) VALUES (?,?,?,?,?,?,?)");
|
||||
$role = "newbie";
|
||||
$s->bind_param("sssssss", $login, $email, $pwd_hash, $salt, $avatar_path, $role, $invite_id);
|
||||
$result = ($s->execute() !== false);
|
||||
|
||||
if (!$result)
|
||||
return new ReturnT(err_code: E_DBE_INSERTFAIL, err_desc: "cant insert record to users DB");
|
||||
|
||||
return new ReturnT(data: $result);
|
||||
return User_Create($login, $password, $email, $invite_id, $avatar_path);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user