forked from SAAR-IITP/SAAR-IITP
-
Notifications
You must be signed in to change notification settings - Fork 13
/
passchange.php
42 lines (38 loc) · 1.45 KB
/
passchange.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$url = 'http://api.saar.iitp.ac.in/changePassword.php';
$ch = curl_init($url);
$data = array(
'rollno' => $_SESSION['cid'],
'new_password' => $_POST["newpassword"],
'confirm_password' => $_POST["confirmnewpassword"],
'access_token' => $_SESSION['access_token']
);
if(isset($_POST['password'])){
$data += array('old_password' => $_POST["password"]);
}
if(isset($_POST['forget_pass'])){
$data += array('forgot_password' => $_POST['forget_pass']);
}
$payload = http_build_query($data);
curl_setopt($ch, CURLOPT_POST, true);
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
//close cURL resource
curl_close($ch);
$response = json_decode($result,true);
if($response['status']== 407){
$_SESSION['error'] = $response['messages'][0];
header("location: changePassword.php");
}else if($response['status'] == 207){
unset($_SESSION['forget_pass']);
$_SESSION['msg'] = $response['messages'][0];
header("location: logout.php");
}
}?>