-
Notifications
You must be signed in to change notification settings - Fork 8
/
verify.php
156 lines (148 loc) · 4.63 KB
/
verify.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
include_once('includes/config.php');
include_once('includes/umf.php');
$SUCCESS=false;
$ERROR=false;
$AUTHORIZED=false;
if(isset($_POST['change']) && isset($_SESSION['UM_DATA']['forget'])){
$DB->query("update users set password='".UM_PASSWORD($_POST['password'])."' where _id={$_SESSION['UM_DATA']['forget']}");
unset($_SESSION['UM_DATA']['forget']);
$SUCCESS="Your Password has been Changed";
}else if(!isset($_GET['verify'])){
header('Location: user.php');
exit;
}
if(isset($_GET['verify'])){
$r=$DB->query("select *,UNIX_TIMESTAMP(date) as date from verify where _id=".intval($_GET['verify']))->fetch_assoc();
try{
if(!$r || $r['used'])
throw new Exception('Link is Invalid');
if($r['email']!=$_GET['email'] || $r['secret']!==$_GET['code']){
$DB->query("update verify set wrong=wrong+1 where _id={$r['_id']}");
throw new Exception('Link is Invalid');
}
if($r['wrong']>10 || time()>($r['date']+(UM_VERIFY_EMAIL_EXPIRE*3600))){
throw new Exception('Link is Expired! please repeat your Request.');
}
$DB->query("update verify set used=1 where _id={$r['_id']}");
if($r['action']=='verify'){
$st=$DB->prepare('update users set email=? where _id=?');
$st->bind_param('si',$r['email'],$r['user_id']);
$st->execute();
$SUCCESS="Your email Verified";
}else if($r['action']=='forget'){
$_SESSION['UM_DATA']=array('_id'=>$r['user_id'],'forget'=>$r['user_id']);
$AUTHORIZED=true;
}
}catch(Exception $e){
$ERROR=$e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Register</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="@irhosseinz">
<meta content="fa" http-equiv="Content-Language" />
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/usermanager.css" rel="stylesheet">
<script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script src="/js/jquery.validate.min.js"></script>
<link rel="shortcut icon" href="/img/favicon.png" />
<script type="text/javascript">
$( document ).ready(function(){
var rules={password0:{required:true}},msgs={};
rules.password={
required:true
,minlength:<?php echo UM_PASSWORD_MIN;?>
};
rules.password2={
equalTo:"#input_password"
};
msgs.password2={
equalTo:"Please enter same password again"
}
$("#form").validate({
focusInvalid: false,onkeyup: false,
errorClass: "is-invalid",validClass: "is-valid",
errorPlacement: function(error, element) {
if (element.parent().hasClass('input-group')) {
error.insertAfter(element.parent());
}else{
error.insertAfter(element);
}
}
,rules:rules,messages:msgs
,submitHandler: function(form) {
form.submit();
}
});
});
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#"><?php echo $UM_CONFIG['TITLE'];?></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Home</a>
</li>
<?php
if(!isset($_SESSION['UM_DATA'])){
?>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<?php
}
?>
</ul>
</div>
</nav>
<div class="container">
<?php
if(@$ERROR){
echo '<div class="alert alert-danger" role="alert">'.$ERROR.'</div>';
}else if(@$SUCCESS){
echo '<div class="alert alert-success" role="alert">'.$SUCCESS.'</div>';
}
if($AUTHORIZED){
?>
<form id="form" action="verify.php" method="post">
<hr/><h4>Change Password:</h4>
<div class="form-group">
<label for="input_password">New Password</label>
<input type="password" class="form-control" name="password" id="input_password"/>
</div>
<div class="form-group">
<label for="input_password2">Repeat New Password</label>
<input type="password" class="form-control" name="password2" id="input_password2"/>
</div>
<br/><input type="submit" class="btn btn-primary my-1" value="Change" name="change"/>
</form>
</div>
<?php
}
?>
<hr>
<footer>
<p class="text-center text-ltr engFont">© <a href="http://h.sandbad.biz/User-Manager/" target="_blank">UserManager</a></p>
</footer>
</body>
</html>
<?php
$DB->close();
?>