<?php
/*
include "bank.php";


 //sanitize($_POST['password']);
	if(isset($_GET['username']) && isset($_GET['password'])){
		
					$username = sanitize($_GET['username']);
					$password = sanitize($_GET['password']);
	
		
				$sql = "SELECT * FROM `users` WHERE  mobile = '$username' AND password = '$password'";
				//echo $sql;
				$result = $conn->query($sql);

				
				if ($result->num_rows > 0) {
					// output data of each row
					$R = rand(1111,9999);
					$token = md5(time() + $R);
					$upto = time() + 259200;
					$row = $result->fetch_assoc();
					$conn->query("UPDATE users SET token='".$token."', uptodate='".$upto."' WHERE id='".$row['id']."' ");
						if($row['mood'] == 3){
								
									if(isset($_GET['code'])){
										$code = sanitize($_GET['code']);
										if($row['passcode'] == $code){
											$conn->query("UPDATE users SET mood=1 WHERE id=".$row['id']);
											echo json_encode(array('stats' => "you are logined!" , 'token' => $token));
										}else{
											$data = array("stats" => "0" ,"msg" => "کد تائید صحیح نیست!" );
											echo json_encode($data, JSON_UNESCAPED_UNICODE);
										}
									}else{
										$randi = "1111"; 
										$conn->query("UPDATE users SET passcode=$randi WHERE id=".$row['id']);
										$data = array("stats" => "0" ,"msg" => "لطفا شماره موبایل خود را تائید کنید پیامکی حامل کد تائید برای شما ارسال شد" );
										echo json_encode($data, JSON_UNESCAPED_UNICODE);
										
										$data = "کد تائید شما ".$randi." می باشد";
										sendSms($username,$data);  
									}
							}else{
									
									$data = array('stats' => "you are logined!" , 'token' => $token, 's' => '2323');
									echo json_encode(array('stats' => "you are logined!" , 'token' => $token));
								
								}
				} else {
					$data = array('stats' => "user not found!");
						echo json_encode($data );
				}

	}elseif(isset($_GET['forget'])){
		
					$username = sanitize($_GET['forget']);
				$sql = "SELECT * FROM `users` WHERE  mobile =".$username;
				//echo $sql;
				$result = $conn->query($sql);

				if ($result->num_rows > 0) {
					$row = $result->fetch_assoc();
					$randi = "1111";
					$conn->query("UPDATE users SET passcode=$randi WHERE id=".$row['id']);
					$data = "کد تائید شما ".$randi." می باشد";
					sendSms($username,$data);
					$data2 = array("stats" => "0" ,"msg" => " پیامکی حامل کد تائید برای شما ارسال شد" );
										echo json_encode($data2, JSON_UNESCAPED_UNICODE);
				}else {
					$data = array('stats' => "user not found!");
						echo json_encode($data );
				}
		
		
	}elseif(isset($_GET['verfy']) ){
		
		
					$username = sanitize($_GET['verfy']);
					$code = sanitize($_GET['code']);
				$sql = "SELECT * FROM `users` WHERE  mobile =".$username."  AND passcode = ".$code;
				//echo $sql;
				$result = $conn->query($sql);
				$row = $result->fetch_assoc();
				if ($result->num_rows > 0) {
					$R = rand(1111,9999);
					$token = md5(time() + $R);
					$upto = time() + 259200;
					$conn->query("UPDATE users SET token='".$token."', uptodate='".$upto."' WHERE id='".$row['id']."' ");
					echo json_encode(array('stats' => "you are logined!" , 'token' => $token));
				}else {
					$data = array('stats' => "user not found!");
						echo json_encode($data );
				}
		
		
	}
	
	*/
	include "bank.php";

	$username = $_GET['username'];
	$password = $_GET['password'];
	$pushid = $_GET['pushid'];
	
		
				$sql = "SELECT * FROM `users` WHERE  username = '$username' AND password = '$password'";
				//echo $sql;
				$result = $conn->query($sql);

				if ($result->num_rows > 0) {
					// output data of each row
					$token = md5(time() + 1254);
					$upto = time() + 259200;
					while($row = $result->fetch_assoc()) {
					
					$conn->query("UPDATE users SET token='".$token."', pushid='".$pushid."', uptodate='".$upto."' WHERE id='".$row['id']."' ");
					   $data = array('stats' => "you are logined!" , 'token' => $token);
						echo json_encode(array('stats' => "you are logined!" , 'token' => $token));
						//pushsend("!!!!!!!!!!!!!","ورود موفق!",$pushid);
					}
				} else {
					
					$data = array('stats' => "user not found!");
						echo json_encode($data );
				}

?>

