diff --git a/backend/onboarding.php b/backend/onboarding.php index cd2c59d..b326174 100644 --- a/backend/onboarding.php +++ b/backend/onboarding.php @@ -3,20 +3,15 @@ if (!User::isLoggedin()){ header("Location: ./login"); } +$userid = User::isLoggedIn(); -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - - +if (User::getUsername($userid)){ + //redirect mans if hes got a username already + header("Location: ./home"); +} +if ($_SERVER['REQUEST_METHOD'] === 'POST') { -try{ -//throw an error if you didn't fill input in or if input value is empty -if(!isset($_POST['fname']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } -if(!isset($_POST['lname']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } -if(!isset($_POST['username']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } -if(!isset($_POST['address']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } -if(!isset($_POST['city']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } -if(!isset($_POST['zipcode']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } //declare variables $fname = $_POST['fname']; @@ -26,6 +21,22 @@ $city = $_POST['city']; $zipcode = $_POST['zipcode']; +try{ +//throw an error if you didn't fill input in or if input value is empty +if(!isset($_POST['fname']) || $_POST['fname'] === ""){ throw new Exception('Error: You need to input all fields!'); } +if(!isset($_POST['lname']) || $_POST['lname'] === ""){ throw new Exception('Error: You need to input all fields!'); } +if(!isset($_POST['username']) || $_POST['username'] === ""){ throw new Exception('Error: You need to input all fields!'); } +if(!isset($_POST['address']) || $_POST['address'] === ""){ throw new Exception('Error: You need to input all fields!'); } +if(!isset($_POST['city']) || $_POST['city'] === ""){ throw new Exception('Error: You need to input all fields!'); } +if(!isset($_POST['zipcode']) || $_POST['zipcode'] === ""){ throw new Exception('Error: You need to input all fields!'); } + + + +if(!is_numeric($zipcode)){ throw new Exception('Error: Zip code must be a number!'); } + + DatabaseConnector::query('UPDATE user SET username=:username, fname=:fname, lname=:lname,addr_line_1=:address,city=:city,zip=:zipcode WHERE id=:userid', array(':username'=>$username,':fname'=>$fname,':lname'=>$lname,':address'=>$address, ':userid'=>$userid, ':city'=>$city,':zipcode'=>$zipcode)); + +$success =true; } catch (Exception $e) { $GLOBALS['errors'][] = $e->getMessage(); } diff --git a/classes/class.general.php b/classes/class.general.php index aa8f2e2..030f703 100644 --- a/classes/class.general.php +++ b/classes/class.general.php @@ -1,8 +1,10 @@ $id))[0]['username']){ + //return username + return DatabaseConnector::query('SELECT username FROM user WHERE id=:id', array(':id'=>$id))[0]['username']; + } + else { + return false; + } +} + public static function isAdmin() diff --git a/frontend/onboarding.php b/frontend/onboarding.php index 0df14c8..3707cf7 100644 --- a/frontend/onboarding.php +++ b/frontend/onboarding.php @@ -35,14 +35,14 @@
- +
- +
@@ -51,14 +51,14 @@
- +
- +
@@ -67,14 +67,14 @@
- +
- +