CS71 – Ass1 – Finance – Part 4 – Login Register Forgotten password

I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning 🙂 even if allot of it you may already know.

Since most of the work is done in the class files, from the previous post then we just use the classes to only have basic php pages for the user. So the login page is just, which also has a check for if the user is already logged in and goto the viewdetails page, or if the user requests to logout then logout the user, the main page is just logging the user in.

LoginCheck($_REQUEST["username"], $_REQUEST["password"]);
	}

	if (isset($_REQUEST["logout"]))
		$theUser->Logout();

	if (isset($_SESSION["authenticated"]) && $_SESSION["authenticated"]== true)
	{
		header("Location: /viewdetails.php");
		exit;
	}
	
	HTMLHeader("Login to the stocks!",false);

	if (isset($error))
	{
		if ($error==false)
			echo "
Not able to login, please try again
"; } if (isset($_REQUEST["logout"])) echo "Thanks for using the site, you are logged out!"; ?>
" onsubmit=""> Login

Username : "/>

Password :

Here is the register page, where I send the request to the users class and utilize the return value to display either a message of check your emails (or in this case it will be a link on the top of the page) or display a error to the user depending on what could happen, e.g. not a valid valid/password(if the user turned off javascript checking) and also if there is already that email address present, the next check checks for the valid ID value that is sent to the user to validate there email.

RegisterUser($_REQUEST["username"], $_REQUEST["password"]);
		if ($error == -2)
			$notValidPassword = true;
		else if ($error == -1)
			$notValidEmail = true;
		else if ($error == 0)
			$emailAddressAlreadyPresent = true;
		else if ($error == 1)
			$checkEmails = true;
	}

	if (isset($_REQUEST["validid"]) && isset($_REQUEST["uid"]))
	{
		$error = $theUser->CheckUserGUID($_REQUEST["uid"], $_REQUEST["validid"]);
		if ($error == false)
			$userInvalid = true;
		else if ($error == true)
		{			
			$theUser->LoginCheck($_REQUEST["uid"],"",true);
			header("Location: /viewdetails.php");
			exit;
		}
	}
	
	if (isset($_SESSION["authenticated"]) && $_SESSION["authenticated"]== true)
	{
		header("Location: /viewdetails.php");
		exit;
	}
	
	HTMLHeader("Register",false);

	if (isset($error))
	{
		if (isset($checkEmails))
			echo "
Please check your emails to validate your email address
"; else if (isset($notValidPassword)) echo "
Not a valid password!, please enter one that is 6 characters and has at least 1 aphla/numeric
"; else if (isset($emailAddressAlreadyPresent)) echo "
Please use the forgotten password recovery, already email address registered
"; else if (isset($notValidEmail)) echo "
Not a valid email address
"; else if (isset($userInvalid)) echo "
Does not validate correctly, please contact the system admin
"; } ?>
" onsubmit="return CheckRegister()"> Register

Username : "/> (valid email address)

Password : (Has to be at least 6 characters and with 1 numeric and aplha character

Here is the last part, that will allow the user to enter there email to be able to get a link to enable them to change there password.

ForgottenUser($_REQUEST["username"]);
		if ($error)
			$checkEmails = true;
		else 
			$notValidEmail = true;
	}

	if (isset($_REQUEST["validid"]) && isset($_REQUEST["uid"]))
	{
		$error = $theUser->CheckUserGUID($_REQUEST["uid"], $_REQUEST["validid"]);
		if ($error == false)
			$userInvalid = true;
		else if ($error == true)
		{			
			$theUser->LoginCheck($_REQUEST["uid"],"",true);
			header("Location: /changepassword.php");
			exit;
		}
	}
	
	if (isset($_SESSION["authenticated"]) && $_SESSION["authenticated"]== true)
	{
		header("Location: /viewdetails.php");
		exit;
	}
	
	HTMLHeader("Forgotten password",false);

	if (isset($error))
	{
		if (isset($checkEmails))
			echo "
Please check your emails to validate your email address
"; else if (isset($notValidEmail)) echo "
Cannot find that email address
"; } ?>
" onsubmit="return CheckRegister(true)"> Forgotten password, please enter your username

Username : "/> (valid email address)

As you can see the actual pages are really simple because most of the work is done in the class files

Leave a Reply

Your email address will not be published.