mirror of
https://github.com/ZeroDream-CN/PHPMC7
synced 2024-12-01 02:02:52 +08:00
KasuganoSoras
01b9046021
增加登录页面 Csrf 验证 修复 Daemon 管理页面显示问题 修复一些操作时的判断问题 修复 AJAX 请求参数构造错误问题 修复控制台字体全绿问题
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
class Profile {
|
|
|
|
public $id;
|
|
public $username;
|
|
public $email;
|
|
public $permission;
|
|
|
|
public function __construct($username) {
|
|
if(!empty($username) && preg_match("/^[A-Za-z0-9\-\_]+$/", $username)) {
|
|
$db = Config::MySQL();
|
|
$conn = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name'], $db['port']);
|
|
// Method 1 通过用户名查找用户
|
|
$rs = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM `{$db['name']}`.`users` WHERE `username`='{$username}'"));
|
|
if($rs) {
|
|
$this->id = $rs['id'];
|
|
$this->username = $rs['username'];
|
|
$this->email = $rs['email'];
|
|
$this->permission = $rs['permission'];
|
|
} else {
|
|
// Method 2 通过用户 ID 查找用户
|
|
$rs = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM `{$db['name']}`.`users` WHERE `id`='{$username}'"));
|
|
if($rs) {
|
|
$this->id = $rs['id'];
|
|
$this->username = $rs['username'];
|
|
$this->email = $rs['email'];
|
|
$this->permission = $rs['permission'];
|
|
} else {
|
|
// Method 3 通过用户邮箱查找用户
|
|
$rs = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM `{$db['name']}`.`users` WHERE `email`='{$username}'"));
|
|
if($rs) {
|
|
$this->id = $rs['id'];
|
|
$this->username = $rs['username'];
|
|
$this->email = $rs['email'];
|
|
$this->permission = $rs['permission'];
|
|
} else {
|
|
// 未找到任何数据,返回 null
|
|
$this->id = null;
|
|
$this->username = null;
|
|
$this->email = null;
|
|
$this->permission = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |