/** * Log in the user if credentials are correct * * @access public */ public function login() { $to_read['table'] = 'user'; $to_read['columns'] = array('USER_ID', 'user_username', 'user_password'); $to_read['condition_columns'][':name'] = 'user_username'; $to_read['condition_types'][':name'] = 'AND'; $to_read['condition_select_types'][':name'] = '='; $to_read['condition_values'][':name'] = VPost::login(); $to_read['value_types'][':name'] = 'str'; $user = $this->_db->read($to_read); if ($user === false || empty($user)) { throw new Exception('Invalid Username'); } else { if ($user[0]['user_username'] == VPost::login() && $user[0]['user_password'] == Helper::make_password(VPost::login(), VPost::password())) { $_SESSION['username'] = $user[0]['user_username']; $_SESSION['user_id'] = $user[0]['USER_ID']; header('Location: index.php'); } else { throw new Exception('Invalid Password'); } } }
/** * Install database with config.php already created * * @access private */ private function install_woc() { require_once 'config.php'; $this->_db_host = DB_HOST; $this->_db_name = DB_NAME; $this->_db_user = DB_USER; $this->_db_pwd = DB_PWD; $this->_db_prefix = DB_PREFIX; $this->_ws_url = WS_URL; $this->_ws_name = WS_NAME; $this->_ws_email = WS_EMAIL; $this->_username = VPost::username(); $this->_password = VPost::password(); try { //try to connect to database, if not exception raisen and we create it $this->_db = new PDO('mysql:dbname=' . $this->_db_name . ';host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); //create tables $this->create_activity(); $this->create_category(); $this->create_comment(); $this->create_link(); $this->create_media(); $this->create_post(); $this->create_setting(); $this->create_user(); $this->_result = 'successful'; } catch (Exception $e) { if ($e->getMessage() == 'SQLSTATE[42000] [1049] Unknown database \'' . $this->_db_name . '\'') { try { $this->_db = new PDO('mysql:host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $this->create_database(); $this->_db = new PDO('mysql:dbname=' . $this->_db_name . ';host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $this->create_activity(); $this->create_category(); $this->create_comment(); $this->create_link(); $this->create_media(); $this->create_post(); $this->create_setting(); $this->create_user(); $this->_result = 'successful'; } catch (Exception $e) { if ($e->getMessage() == 'false create') { $this->_result = 'false create'; } else { $this->_result = 'unknown'; } } } elseif ($e->getMessage() == 'false create') { $this->_result = 'false create'; } else { $this->_result = 'unknown'; } } }