Skip to content
Permalink
0017766e77
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
53 lines (45 sloc) 1.68 KB
<?php
defined('APP_DIR') or define('APP_DIR', 'app/');
include_once('app/config/config.php');
include_once('app/database/Database.php');
include_once('app/model/User.php');
$dbh = new PDO('mysql:host=' . Config::db_host, Config::db_user, Config::db_pass);
/* Create database if it doesn't exist */
$dbh->exec('CREATE DATABASE IF NOT EXISTS ' . Config::db_name);
/* Connect to database */
$dbh = Database::connect();
/* Create users table if it doesn't exist */
$stmt = 'CREATE TABLE IF NOT EXISTS users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(32) NOT NULL,
password VARCHAR(64) NOT NULL,
access VARCHAR(8) NOT NULL,
login_attempts INT(6) UNSIGNED NOT NULL
)';
$dbh->exec($stmt);
/* Create messages table if it doesn't exitst */
$stmt = 'CREATE TABLE IF NOT EXISTS messages (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
message TEXT NOT NULL,
sender_id INT UNSIGNED NOT NULL,
receiver_id INT UNSIGNED NOT NULL,
enc_keys VARCHAR(64) NOT NULL,
keys_iv VARCHAR(24) NOT NULL,
message_iv VARCHAR(24) NOT NULL,
is_read BOOLEAN NOT NULL DEFAULT 0,
FOREIGN KEY (sender_id) REFERENCES users(id),
FOREIGN KEY (receiver_id) REFERENCES users(id)
)';
$dbh->exec($stmt);
/* Create user and admin if they don't exist */
$user = new User;
$user->username = 'user';
$user->password = password_hash('userpass', PASSWORD_DEFAULT);
$user->access = 'user';
$user->save();
$user = new User;
$user->username = 'admin';
$user->password = password_hash('adminpass', PASSWORD_DEFAULT);
$user->access = 'admin';
$user->save();
?>