-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.php
163 lines (152 loc) · 5.86 KB
/
auth.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
157
158
159
160
161
162
163
<?php
include_once("include/CAS.php");
include_once('include/function.php');
include_once('include/autoload.php');
$ad = new ad();
$util = new user;
$bdd = new bdd;
$page['windowTitle'] = 'Connexion';
//phpCAS::setDebug();
if(CAS_STATUS){ //si le CAS est activé
phpCAS::client(CAS_VERSION_2_0,CAS_HOST,443,CAS_DIR);
phpCAS::setNoCasServerValidation();
phpCAS::forceAuthentication();
if (phpCAS::isAuthenticated()){
$data2 = array(
phpCAS::getUser()
);
$bdd->cache("select id, acl, state from users where username=?", $data2);
$result = $bdd->exec();
if (isset($result[0][0]['id'])) {
if ($result[0][0]['state'] == 1) {
$_SESSION['username'] = phpCAS::getUser();
$_SESSION['id'] = $result[0][0]['id'];
$_SESSION['userid'] = $result[0][0]['id'];
$_SESSION['acl'] = $result[0][0]['acl'];
$_SESSION['uid'] = sha1(uniqid('',true).'_'.mt_rand());
$_SESSION['ip']=user::ip();
$_SESSION['expires_on']=time()+INACTIVITY_TIMEOUT;
header('location: index.php');
exit();
}
}
}
if(isset($_SERVER['HTTP_AUTH_USER']) and !empty($_SERVER['HTTP_AUTH_USER'])){
$data2 = array(
$_SERVER['HTTP_AUTH_USER']
);
$bdd->cache("select id, acl, state from users where username=?", $data2);
$result = $bdd->exec();
if (isset($result[0][0]['id'])) {
if ($result[0][0]['state'] == 1) {
$_SESSION['username'] = $_SERVER['HTTP_AUTH_USER'];
$_SESSION['id'] = $result[0][0]['id'];
$_SESSION['userid'] = $result[0][0]['id'];
$_SESSION['acl'] = $result[0][0]['acl'];
$_SESSION['uid'] = sha1(uniqid('',true).'_'.mt_rand());
$_SESSION['ip']=user::ip();
$_SESSION['expires_on']=time()+INACTIVITY_TIMEOUT;
header('location: index.php');
exit();
}
}
}
}
if (isset($_SESSION['uid'])) { //si deja connecté
if(!isset($_SERVER['HTTP_AUTH_USER']) or empty($_SERVER['HTTP_AUTH_USER'])){
$util->check_login();
header('location: index.php');
exit;
} else {
if($_SERVER['HTTP_AUTH_USER']== $_SESSION['username']){
$util->check_login();
header('location: index.php');
exit;
}
}
}
if (!empty($_POST['password']) and !empty($_POST['username'])) { //auth dans la bdd
$result = $util->auth( $_POST['username'],$_POST['password']);
//var_dump($result);
if ($result) {
header('location: index.php');
exit;
} elseif ($ad->login($_POST['username'], $_POST['password'])) { //auth ad
$data2 = array(
$_POST['username']
);
setcookie ("username", $_POST['username'], time() + 432000);
//on verifie que le user exite dans notre table
$bdd->cache("select id, acl, state from users where username=?", $data2);
$result = $bdd->exec();
if (isset($result[0][0]['id'])) {
if ($result[0][0]['state'] == 1) {
$_SESSION['id'] = $result[0][0]['id'];
$_SESSION['username'] = $_POST['username'];
$_SESSION['userid'] = $result[0][0]['id'];
$_SESSION['acl'] = $result[0][0]['acl'];
$_SESSION['uid'] = sha1(uniqid('',true).'_'.mt_rand());
$_SESSION['ip']=user::ip();
$_SESSION['expires_on']=time()+INACTIVITY_TIMEOUT;
header('location: index.php');
exit();
} else {
echo 'compte en cour de validation';
exit;
}
} else {// on l'ajout si il n'est pas present en temps qu'utilisateur desactivé
$info = $ad->get_info($_POST['username'], $_POST['password']);
$array = array(
$_POST['username'],
$info[0]['sn'][0],
$info[0]['givenname'][0],
'',
'1',
$info[0]['mail'][0],
'',
'',
'0'
);
echo '<br><br>';
// var_dump($array);
$bdd->cache("insert into users set id='', username=?, nom=?, prenom=?, password=?, acl=?, mail=?, id_contrat=?, begin=?,state=?", $array);
$bdd->exec();
}
} else {
$errMsg = '<div style="border:solid 2px red; background:pink;color:red;padding:1em;display:inline-block" class="droid">Nom d´utilisateur ou mot de passe invalide.</div>';
}
}
if(isset($_COOKIE['username'])){
$value='value="' . $_COOKIE['username'] . '"';
} else {
$value="";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Auth</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/auth.css">
</head>
<body>
<form method="POST">
<div class="content">
<h1>Connexion</h1>
<?php
if (isset($errMsg)) {
print $errMsg;
}
?>
<p class="free_sans">Please, login to use</p>
<input type="text" class="free_sans" <?php echo $value; ?> name="username" placeholder="username" >
<br>
<input class="free_sans" name="password" placeholder="Mot de passe" type="password">
<br>
<input class="input" type="submit" value="Valider">
<br>
</div>
</form>
</body>
</html>