authpartner

Clone or download

error handling

Modified Files

M otp_form.php
+88 −106
--- 'a/otp_form.php'
+++ b/otp_form.php
@@ -1,39 +1,38 @@
<link href="css/bootstrap.min.css" rel="stylesheet">
- <!-- Custom CSS -->
- <link href="css/style.css" rel="stylesheet">
- <link href="css/styles.css" rel="stylesheet">
- <link href="css/font-style.css" rel="stylesheet" type="text/css">
- <!-- Custom Fonts -->
- <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
- <link href="css/stylecrt.css" rel="stylesheet" type="text/css"/>
+<!-- Custom CSS -->
+<link href="css/style.css" rel="stylesheet">
+<link href="css/styles.css" rel="stylesheet">
+<link href="css/font-style.css" rel="stylesheet" type="text/css">
+<!-- Custom Fonts -->
+<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
+<link href="css/stylecrt.css" rel="stylesheet" type="text/css"/>
<link href="css/datepicker.css" rel="stylesheet" type="text/css"/>
+<?php
+include 'config.php';
-<?php include 'config.php';
+if (isset($_SESSION['mob'])) {
+ $mobile = $_SESSION['mob'];
+ $name = $_SESSION['name'];
+ $uid = $_SESSION['uid'];
+ $dob = $_SESSION['dob'];
+ $gender = $_SESSION['gen'];
+ $verification = $_SESSION['verification'];
+} else {
-if(isset($_GET['error_description'])){
- header("Location: otp_form.php?message=".$_GET['error_description']);
- exit;
-}
-if(isset($_GET['mob']))
-{
-$mobile = $_GET['mob'];
-$name = $_GET['name'];
-$uid = $_GET['uid'];
-$dob= $_GET['dob'];
-$gender = $_GET['gen'];
-$verification = 'Y';
+ $_SESSION['message'] = "Please fill your form";
+ header("Location: signup.php");
+ exit;
}
?>
-
<div class="col-lg-12">
<div class="container">
<?php
$msg = "message";
- if (isset($_GET[$msg])) {
- $message=$_GET[$msg];
- $alert = "red";
-
+ isset($_SESSION[$msg]) ? $message = $_SESSION[$msg] : $message = "";
+ if (!empty($message)) {
+ $alert = "red";
echo "<div class='alert' id='alert' style='color:" . $alert . "'> <button type='button' class='close' data-dismiss='alert'>x</button>" . $message . "</div>";
+ unset($_SESSION[$msg]);
}
?>
</div>
@@ -66,12 +65,12 @@ $verification = 'Y';
<h4>Please Verify OTP for Login</h4>
<div class="panel-body login-panel">
<form action = "" method = "POST" role="form">
- <input type="hidden" name="" value="" />
- <div class="form-group">
- <input type="text" class="form-control" placeholder="Enter OTP" name="otp" id="otp" maxlength="6" autocomplete="off" required>
- </div>
- <input type="submit" id="verify" name="verify" value="Verify OTP" class="btn btn-primary form-control" >
-
+ <input type="hidden" name="" value="" />
+ <div class="form-group">
+ <input type="text" class="form-control" placeholder="Enter OTP" name="otp" id="otp" maxlength="6" autocomplete="off" required>
+ </div>
+ <input type="submit" id="verify" name="verify" value="Verify OTP" class="btn btn-primary form-control" >
+
</form>
</div>
</div>
@@ -79,87 +78,70 @@ $verification = 'Y';
</div>
</div>
</div>
-
</div>
</div>
-<?php
-if(!empty($_POST))
-{
+<?php
+if (!empty($_POST)) {
$clientid = $config['client_id_download'];
-$secret = $config['client_secret_download'];
-$ts = time();
-$otp = $_POST['otp'];
-$hmac = hash('SHA256', $secret . $clientid . $mobile . $otp . $ts);
-$url = $config['demoauthverify_url'];
-$post = array(
- 'clientid' => $clientid,
- 'uid' => $uid,
- 'dob' => $dob,
- 'name' => $name,
- 'gender' => $gender,
- 'otp' => $otp,
- 'mobile' => $mobile,
- 'verification' => $verification,
- 'ts' => $ts,
- 'hmac' => $hmac
-);
+ $secret = $config['client_secret_download'];
+ $ts = time();
+ $otp = $_POST['otp'];
+ $hmac = hash('SHA256', $secret . $clientid . $mobile . $otp . $ts);
+ $url = $config['demoauthverify_url'];
+ $post = array(
+ 'clientid' => $clientid,
+ 'uid' => $uid,
+ 'dob' => $dob,
+ 'name' => $name,
+ 'gender' => $gender,
+ 'otp' => $otp,
+ 'mobile' => $mobile,
+ 'verification' => $verification,
+ 'ts' => $ts,
+ 'hmac' => $hmac
+ );
$vh = curl_init($url);
-curl_setopt($vh, CURLOPT_CUSTOMREQUEST, "POST");
-curl_setopt($vh, CURLOPT_POST, true);
-curl_setopt($vh, CURLOPT_TIMEOUT, 30);
-curl_setopt($vh, CURLOPT_HEADER, 1);
-curl_setopt($vh, CURLOPT_POSTFIELDS, $post);
-curl_setopt($vh, CURLOPT_SSL_VERIFYPEER, 0);
-curl_setopt($vh, CURLOPT_SSL_VERIFYHOST, 0);
-curl_setopt($vh, CURLOPT_RETURNTRANSFER, true);
-$result = curl_exec($vh);
-$curl_info = curl_getinfo($vh);
-if (curl_errno($vh)) {
- $error_status = curl_error($vh);
- curl_close($vh);
-} else {
- curl_close($vh);
-}
-print_r($result);
-$header_size = $curl_info['header_size'];
-$header = substr($result, 0, $header_size);
-$body = substr($result, $header_size);
-$header = explode("\n", $header);
-
-
-$statuscode = (int)substr($header[2], 9, 3);
-$rest = json_decode($body);
-
-if($statuscode=='200')
-{
- header("Location: signup.php?message=Your Account has been created. Please login through <a href='https://developers.digitallocker.gov.in' target='_blank' style='color:blue'>this </a> link ");
- exit;
-}
-else
-{
-if(isset($rest->error) || !$result){
-
- header("Location: otp_form.php?message=".$rest->error_description);
- exit;
-}
-}
+ curl_setopt($vh, CURLOPT_CUSTOMREQUEST, "POST");
+ curl_setopt($vh, CURLOPT_POST, true);
+ curl_setopt($vh, CURLOPT_TIMEOUT, 30);
+ curl_setopt($vh, CURLOPT_HEADER, 1);
+ curl_setopt($vh, CURLOPT_POSTFIELDS, $post);
+ curl_setopt($vh, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_setopt($vh, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt($vh, CURLOPT_RETURNTRANSFER, true);
+ $result = curl_exec($vh);
+ $curl_info = curl_getinfo($vh);
+ if (curl_errno($vh)) {
+ $error_status = curl_error($vh);
+ curl_close($vh);
+ } else {
+ curl_close($vh);
+ }
+ print_r($result);
+ $header_size = $curl_info['header_size'];
+ $header = substr($result, 0, $header_size);
+ $body = substr($result, $header_size);
+ $header = explode("\n", $header);
+ $statuscode = (int) substr($header[2], 9, 3);
+ $rest = json_decode($body);
+ if ($statuscode == '200') {
+ $_SESSION['message'] = "Your Account has been created. Please login through <a href='https://developers.digitallocker.gov.in' target='_blank' style='color:blue'>this </a> link ";
+ header("Location: signup.php");
+ exit;
+ } else {
+ if (isset($rest->error) || !$result) {
+ $_SESSION['message'] = $rest->error_description;
+ header("Location: otp_form.php");
+ exit;
+ }
+ }
}
?>
-<script>
- <?php
- if(isset($_GET['message'])){
- echo 'setTimeout(function () {
- window.location.href = "otp_form.php";
- }, 3000);
- ';
- }
- ?>
-</script>
<script src="js/jquery.min.js"></script>
- <script src="js/modernizr.js" type="text/javascript"></script>
- <script src="js/jQuery-2.1.3.min.js" type="text/javascript"></script>
- <!-- <script src="js/bootstrap.min.js" type="text/javascript"></script> --->
- <script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
- <script src="js/app.min.js" type="text/javascript"></script>
+<script src="js/modernizr.js" type="text/javascript"></script>
+<script src="js/jQuery-2.1.3.min.js" type="text/javascript"></script>
+ <script src="js/bootstrap.min.js" type="text/javascript"></script>
+<script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
+<script src="js/app.min.js" type="text/javascript"></script>
</body>
</html>
M signup.php
+5 −15
--- 'a/signup.php'
+++ b/signup.php
@@ -3,12 +3,12 @@
<div class="container">
<?php
$msg = "message";
- if (isset($_GET[$msg])) {
- $message = $_GET[$msg];
+ isset($_SESSION[$msg])?$message = $_SESSION[$msg]:$message="";
+ if (!empty($message)) {
$alert = "red";
-
- echo "<div class='alert' id='alert' style='color:" . $alert . "'> <button type='button' class='close' data-dismiss='alert'>x</button>" . $message . "</div>";
+ echo "<div class='alert' id='alert' style='color:" . $alert . "'> <button type='button' class='close' data-dismiss='alert'>x</button>" . $message . "</div>";
}
+ session_destroy();
?>
</div>
</div>
@@ -51,7 +51,7 @@
<div class="form-group col-md-6">
<label>Gender</label>
<select style="color: #999;" class="form-control" name="gender" id="gender" required>
- <option value="">Select Gender *</option>
+ <option value="" selected>Select Gender *</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
@@ -89,13 +89,3 @@
endDate: "today"
});
</script>
-<!--<script>
-<?php
-//if (isset($_GET['message'])) {
- //echo 'setTimeout(function () {
- // window.location.href = "signup.php";
- // }, 5000);
- // ';
-//}
-?>
-</script>-->
M signupcurl.php
+11 −9
--- 'a/signupcurl.php'
+++ b/signupcurl.php
@@ -1,9 +1,5 @@
<?php
include 'config.php';
-if(isset($_GET['error_description'])){
- header("Location: signup.php?message=".$_GET['error_description']);
- exit;
-}
$uid = $_POST['uid'];
$name = $_POST['name'];
$dob = str_replace('/','',$_POST['dob']);
@@ -55,19 +51,25 @@ $statuscode = (int)substr($header[2], 9,
$rst = json_decode($body);
if($statuscode=='200' && $verification=='N')
{
- header("Location: signup.php?message=Your Account has been created. Please login through <a href='https://developers.digitallocker.gov.in' target='_blank' style='color:blue'>this </a> link ");
+ $_SESSION['message'] = "Your Account has been created. Please login through <a href='https://developers.digitallocker.gov.in' target='_blank' style='color:blue'>this </a> link ";
+ header("Location: signup.php");
exit;
}
-
-//$rst = json_decode($result);
if(isset($rst->error) || !$result){
- header("Location: signup.php?message=".$rst->error_description);
+ $_SESSION['message'] = $rst->error_description;
+ header("Location: signup.php");
exit;
}
if(!empty($rst->mobile))
{
$path = $config['baseUrl'];
- header('Location: '.$path.'otp_form.php?uid='.$uid.'&name='.$name.'&dob='.$dob.'&gen='.$gender.'&mob='.$mobile);
+ $_SESSION['name'] = $name;
+ $_SESSION['uid'] = $uid;
+ $_SESSION['dob'] = $dob;
+ $_SESSION['gen'] = $gender;
+ $_SESSION['mob'] = $mobile;
+ $_SESSION['verification'] = $verification;
+ header('Location: '.$path.'otp_form.php');
}
?>
\ No newline at end of file