<?php
session_start();
require_once('./config.php');
require_once('usefullfunctions.php');
$url='testaccess.php';
if(isset($_SESSION ['groupstatut'])&&isset($_SESSION["startaccesstime"])&&isset($_SESSION["endaccesstime"])&&$_SESSION ['groupstatut']==true&&inrangetime(explode(':',date('H:I:s')),explode(':',$_SESSION["startaccesstime"]),explode(':',$_SESSION["endaccesstime"]))){
echo '<script type="text/javascript">window.location="'.$url.'";</script>';
exit;
}
if(isset($_GET['action'])&&$_GET['action']=="reset" &&empty($_GET['id'])){?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Password reset</title>
<style type="text/css">
#other {
font-family: verdana;
font-weight: bold;
font-size: 14px;
font-style:italic;
color: #FFFFFF;
background-color: grey;
width: auto;
margin-left: 15%;
margin-right: 15%;
padding:2%;
}
label
{
display: block ;
width: 150px;
float : left ;
}
</style>
</head>
<body>
<div id="other">
<div>
<form id="users" method="POST">
<fieldset><legend>Password reset</legend>
<p>
<label for="email">email</label><input name="email" type="text" id="email" /><br>
</p>
</fieldset>
<p><input type="submit" value="Submit" /></p>
<div id="manage"></div></form></div>
<script language="JavaScript">
var manage=document.getElementById("manage");
var users=document.getElementById("users");
var mail=document.getElementById("email");
function addEvent (element,event,func) {
if (element.attachEvent){
element.attachEvent ("on"+event,func) ;
}else{
element.addEventListener(event,func,true) ;
}
}
function resetmail(){
var xhr=new XMLHttpRequest;
xhr.open("POST","./resetpassword.php?action=ask");
xhr .setRequestHeader ( "Content-Type" ,"application/x-www-form-urlencoded" );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resp=xhr.responseText;
if(resp=="mail successfully sent"){
manage.innerHTML+="An email has been sent to your email";
}else{
manage.innerHTML+="An error occured during email sending please try again later ";
}
}
}
xhr.send('mail='+mail.value);
}
addEvent(users,"submit",function(e){
e = e || window.event ;
resetmail();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
</script>
</div>
</body>
</html>
<?php
}elseif(isset($_GET['action'])&&$_GET['action']=="reset" &&!empty($_GET['id'])){
echo'<script language="JavaScript"> var id="'.$_GET['id'].'";</script>';
$query=$bdd->prepare('SELECT user_id FROM users WHERE idvalidation=:id');//get the id
$query->bindValue(':id',$_GET['id'],PDO::PARAM_STR);
$query->execute();
$id=$query->fetch();
$query->CloseCursor();
if(!empty($id)){?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Password reset</title>
<style type="text/css">
#other {
font-family: verdana;
font-weight: bold;
font-size: 14px;
font-style:italic;
color: #FFFFFF;
background-color: grey;
width: auto;
margin-left: 15%;
margin-right: 15%;
padding:2%;
}
label
{
display: block ;
width: 150px;
float : left ;
}
</style>
</head>
<body>
<div id="other">
<div>
<form id="users" method="POST">
<fieldset><legend>Password reset</legend>
<p>
<label for="password">password:</label><input type="password" name="password" id="password" /><br>
<label for="passwordconfirm">password confirm:</label><input type="password" name="passwordconfirm" id="passwordconfirm" /><br>
</p>
</fieldset>
<p><input type="submit" value="Submit" /></p>
<div id="manage"></div></form></div>
<script language="JavaScript">
var manage=document.getElementById("manage");
var users=document.getElementById("users");
var pass=document.getElementById("passwordconfirm");
var password=document.getElementById("password");
function addEvent (element,event,func) {
if (element.attachEvent){
element.attachEvent ("on"+event,func) ;
}else{
element.addEventListener(event,func,true) ;
}
}
function resetmail(){
if(password.value==pass.value){
var xhr=new XMLHttpRequest;
xhr.open("POST","./resetpassword.php?action=reset");
xhr .setRequestHeader ( "Content-Type" ,"application/x-www-form-urlencoded" );
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var resp=xhr.responseText;
if(resp=="Password reset"){
manage.innerHTML="Your password has successfully been reset";
}else{
manage.innerHTML="An error occured during password reset process please try again later ";
}
}
}
xhr.send('password='+password.value+'&id='+id);
}else{
manage.innerHTML="An error occured during password and the confirmation are not the same ";
}
}
addEvent(users,"submit",function(e){
e = e || window.event ;
resetmail();
e.returnValue= false;
if (e.preventDefault) {
e.preventDefault();
}
}
);
</script></div></body>
</html><?php } }else{}?>
|