]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | require_once "SQL/sql.php"; | |
4 | require_once "SQL/user.php"; | |
5 | ||
6 | class sql_auth | |
7 | { | |
8 | public $name = "SQLAuth"; | |
9 | public $author = "Valware"; | |
10 | public $version = "1.0"; | |
11 | public $description = "Provides a User Auth and Management Panel with an SQL backend"; | |
12 | ||
13 | function __construct() | |
14 | { | |
15 | self::create_tables(); | |
16 | Hook::func(HOOKTYPE_NAVBAR, 'sql_auth::add_navbar'); | |
17 | Hook::func(HOOKTYPE_PRE_HEADER, 'sql_auth::session_start'); | |
18 | ||
19 | if (defined('SQL_DEFAULT_USER')) // we've got a default account | |
20 | { | |
21 | $lkup = new SQLA_User(SQL_DEFAULT_USER['username']); | |
22 | ||
23 | if (!$lkup->id) // doesn't exist, add it with full privileges | |
24 | { | |
25 | create_new_user(["user_name" => SQL_DEFAULT_USER['username'], "user_pass" => SQL_DEFAULT_USER['password']]); | |
26 | } | |
27 | } | |
28 | } | |
29 | ||
30 | public static function add_navbar(&$pages) | |
31 | { | |
32 | session_start(); | |
33 | ||
34 | $pages["Panel Access"] = "plugins/sql_auth/"; | |
35 | if (isset($_SESSION['id'])) | |
36 | { | |
37 | $pages["Logout"] = "plugins/sql_auth/login.php?logout=true"; | |
38 | } | |
39 | } | |
40 | ||
41 | public static function session_start($n) | |
42 | { | |
43 | if (!isset($_SESSION['id'])) | |
44 | { | |
45 | header("Location: ".BASE_URL."plugins/sql_auth/login.php"); | |
46 | } | |
47 | } | |
48 | ||
49 | public static function create_tables() | |
50 | { | |
51 | $conn = sqlnew(); | |
52 | $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "users ( | |
53 | user_id int AUTO_INCREMENT NOT NULL, | |
54 | user_name VARCHAR(255) NOT NULL, | |
55 | user_pass VARCHAR(255) NOT NULL, | |
56 | ||
57 | user_fname VARCHAR(255), | |
58 | user_lname VARCHAR(255), | |
59 | user_bio VARCHAR(255), | |
60 | created VARCHAR(255), | |
61 | PRIMARY KEY (user_id) | |
62 | )"); | |
63 | $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "user_meta ( | |
64 | meta_id int AUTO_INCREMENT NOT NULL, | |
65 | user_id int NOT NULL, | |
66 | meta_key VARCHAR(255) NOT NULL, | |
67 | meta_value VARCHAR(255), | |
68 | PRIMARY KEY (meta_id) | |
69 | )"); | |
70 | } | |
71 | ||
72 | } |