Skip to content

Commit

Permalink
finished onboarding alongside validation!
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesea3 committed Apr 17, 2022
1 parent a958d00 commit cfdeabf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
33 changes: 22 additions & 11 deletions backend/onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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();
}
Expand Down
14 changes: 10 additions & 4 deletions classes/class.general.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

if (User::isLoggedIn()){
//see if the user has a username
if(5+5===10){


$userid = User::isLoggedIn();
if ($userid){
//see if the user has a username
if(!User::getUsername($userid)){
//make sure not being redirected when already on page
if ($GLOBALS['url_loc'][1] === "setup" || $GLOBALS['url_loc'][1] === "logout"){

Expand All @@ -12,6 +14,10 @@
header("location:../public_html/setup");
}
}




}


Expand Down
12 changes: 12 additions & 0 deletions classes/class.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public static function isLoggedIn()
return false;
}

public static function getUsername($id)
{
//check to see if the username is set then using the given $id. else return false.
if(DatabaseConnector::query('SELECT username FROM user WHERE id=:id', array(':id'=>$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()
Expand Down
12 changes: 6 additions & 6 deletions frontend/onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
<label for="" class="text-xs font-semibold px-1">First name</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-account-outline text-gray-400 text-lg"></i></div>
<input type="text" name="fname" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="John">
<input type="text" name="fname" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="John" value="<?php echo $fname;?>">
</div>
</div>
<div class="w-1/2 px-3 mb-5">
<label for="" class="text-xs font-semibold px-1">Last name</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-account-outline text-gray-400 text-lg"></i></div>
<input type="text" name="lname" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="Smith">
<input type="text" name="lname" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="Smith" value="<?php echo $lname;?>">
</div>
</div>
</div>
Expand All @@ -51,14 +51,14 @@
<label for="" class="text-xs font-semibold px-1">Username</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-email-outline text-gray-400 text-lg"></i></div>
<input type="username" name="username" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" value="" placeholder="joemama123" readonly="">
<input type="username" name="username" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="joemama123" value="<?php echo $username;?>">
</div>
</div>
<div class="w-1/2 px-3 mb-5">
<label for="" class="text-xs font-semibold px-1">Address</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-location-enter text-gray-400 text-lg"></i></div>
<input type="text" name="address" id="pac-input" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="123 Seseme Street">
<input type="text" name="address" id="pac-input" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="123 Seseme Street" value="<?php echo $address;?>">
</div>
</div>
</div>
Expand All @@ -67,14 +67,14 @@
<label for="" class="text-xs font-semibold px-1">City</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-school-outline text-gray-400 text-lg"></i></div>
<input type="text" name="city" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="Rochester">
<input type="text" name="city" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="Rochester" value="<?php echo $city;?>">
</div>
</div>
<div class="w-1/2 px-3 mb-5">
<label for="" class="text-xs font-semibold px-1">Zip Code</label>
<div class="flex">
<div class="w-10 z-10 pl-1 text-center pointer-events-none flex items-center justify-center"><i class="mdi mdi-gender-male-female-variant text-gray-400 text-lg"></i></div>
<input type="text" name="zipcode" id="pac-input" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="41238">
<input type="text" name="zipcode" id="pac-input" class="w-full -ml-10 pl-10 pr-3 py-2 rounded-lg border-2 border-gray-200 outline-none focus:border-indigo-500" placeholder="41238" value="<?php echo $zipcode;?>">
</div>
</div>
</div>
Expand Down

0 comments on commit cfdeabf

Please sign in to comment.