Skip to content

Commit 7694c1e

Browse files
committed
Working at the moment
1 parent f8d1c71 commit 7694c1e

File tree

10 files changed

+172
-28
lines changed

10 files changed

+172
-28
lines changed

admin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
include_once('header.php');
3+
include_once('footer.php');
4+
include_once('db.php');
5+
?>
6+
<h1>Welcome Admin</h1>
7+
<h1>Ready to ban some kids ?</h1>

db.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
try {
99
$bd=new PDO('mysql:host='.$host.';dbname='.$dbName, $user, $mdp);
1010
$bd->exec("SET NAMES 'utf8'");
11-
echo 'connected to db';
1211
}
1312
catch (Exception $e) {
1413
echo 'Error connecting to DB';

header.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
1+
<?php
2+
session_start();
3+
?>
24
<!DOCTYPE html>
35
<html lang="en" dir="ltr">
46
<head>
@@ -14,8 +16,34 @@
1416
<a href="index.php">Home</a>
1517
<a href="samples.php">Samples</a>
1618
<a href="songs.php">Songs</a>
17-
<a href="profile.php">Profile</a>
18-
<a href="login.php">Login</a>
19+
20+
21+
<?php
22+
if (isset($_SESSION['rights'])) {
23+
if($_SESSION['rights']==3)
24+
{
25+
echo '<a href="admin.php">Admin</a>';
26+
}
27+
if ($_SESSION['rights']==2) {
28+
echo '<a href="modo.php">Modo</a>';
29+
}
30+
if ($_SESSION['rights']==1) {
31+
echo '<a href="profile.php">Profile</a>';
32+
}
33+
}
34+
else {
35+
echo '<a href="profile.php">Profile</a>';
36+
}
37+
38+
39+
?>
40+
<?php if (!isset($_SESSION['username']))
41+
{
42+
echo '<a href="login.php">Login</a>';
43+
} else {
44+
echo '<a href="logout.php">Logout</a>';
45+
}
46+
?>
1947
</div>
2048
</header>
2149
</body>

index.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
include_once('header.php');
33
include_once('footer.php');
44
include_once('db.php');
5-
65
?>
76
<!DOCTYPE html>
87
<html lang="en" dir="ltr">
@@ -14,6 +13,13 @@
1413
</head>
1514
<body>
1615
<p>Welcome
16+
<strong>
17+
<?php
18+
if (isset($_SESSION['username'])){echo $_SESSION['username'];}
19+
else {}
20+
?>
21+
</strong>
1722
</p>
23+
<p>This is your new favorite website</p>
1824
</body>
1925
</html>

login.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
session_start();
32
include("db.php");
3+
include_once('header.php');
44
?>
55
<?php
66
$msg = "";
@@ -10,30 +10,38 @@
1010
$passhash = sha1($password);
1111
if($email != "" && $password != "") {
1212
try {
13-
$query = "select * from `users` where `email`=:email and `passhash`=:password";
13+
$query = "select * from `users` where `email`=:email and `password`=:password";
1414
$stmt = $bd->prepare($query);
1515
$stmt->bindParam('email', $email, PDO::PARAM_STR);
1616
$hashed = sha1($password);
1717
$stmt->bindParam('password',$hashed, PDO::PARAM_STR);
18+
1819
$stmt->execute();
20+
1921
$count = $stmt->rowCount();
2022
$row = $stmt->fetch(PDO::FETCH_ASSOC);
21-
echo "test";
22-
if($count == 1 && !empty($row)) {
23-
/******************** Your code ***********************/
24-
$_SESSION['sess_id'] = $row['id'];
25-
$_SESSION['sess_username'] = $row['username'];
26-
$_SESSION['sess_email'] = $row['email'];
27-
$_SESSION['sess_firstName'] = $row['firstName'];
28-
$_SESSION['sess_lastName'] = $row['lastName'];
29-
$_SESSION['sess_rights'] = $row['rights'];
30-
$_SESSION['sess_active'] = $row['active'];
31-
echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
32-
echo "teub";
33-
} else {
34-
$msg = "Invalid username and password!";
23+
24+
if ($row['active']==1) {
25+
if($count == 1 && !empty($row)) {
26+
$_SESSION['id'] = $row['id'];
27+
$_SESSION['username'] = $row['username'];
28+
$_SESSION['email'] = $row['email'];
29+
$_SESSION['firstName'] = $row['firstName'];
30+
$_SESSION['lastName'] = $row['lastName'];
31+
$_SESSION['rights'] = $row['rights'];
32+
$_SESSION['active'] = $row['active'];
33+
$_SESSION['loggedin'] = TRUE;
34+
header("Location:index.php");
35+
} else {
36+
$msg = "Invalid username and password!";
37+
}
3538
}
36-
} catch (PDOException $e) {
39+
else {
40+
echo "Your account has been disabled by an admin";
41+
}
42+
}
43+
44+
catch (PDOException $e) {
3745
echo "Error : ".$e->getMessage();
3846
}
3947
} else {
@@ -42,9 +50,6 @@
4250
}
4351
?>
4452
<!DOCTYPE html>
45-
<?php
46-
include_once('header.php');
47-
?>
4853
<html lang="en" dir="ltr">
4954
<head>
5055
<meta charset="utf-8">

modo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
include_once('header.php');
3+
include_once('footer.php');
4+
include_once('db.php');
5+
?>
6+
<h1>Moderation</h1>

profile.php

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,91 @@
22
include_once('header.php');
33
include_once('footer.php');
44
include_once('db.php');
5+
if(!isset($_SESSION['loggedin']))
6+
{
7+
echo "You need to login first";
8+
header("Location:profileN.php");
9+
}
10+
11+
if ( isset($_POST['modify']) ) {
12+
//un champ obligatoire
13+
if ( !empty($_POST['firstName']) )
14+
{
15+
$username = trim($_POST['firstName']) ;
16+
}
17+
else
18+
{
19+
$mistakes['firstName'] = true;
20+
}
21+
if ( !empty($_POST['lastName']) )
22+
{
23+
$username = trim($_POST['lastName']) ;
24+
}
25+
else
26+
{
27+
$mistakes['lastName'] = true;
28+
}
29+
30+
31+
32+
if ( !empty($_POST['passmod']) AND isset($_POST['passmodconf'])){
33+
if ($_POST["passmod"]== $_POST["passmodconf"]) {
34+
$passmod = trim($_POST['passmod']);
35+
$passhash = sha1($passmod);
36+
}
37+
}
38+
else
39+
{
40+
$mistakes['passmod'] = true;
41+
}
42+
43+
44+
45+
46+
47+
//un champ obligatoire avec certaines valeurs rejetées
48+
49+
50+
51+
52+
//s'il n'y a pas d'erreur...
53+
if (!empty($mistakes))
54+
{
55+
include("db.php");
56+
echo "sss";
57+
$req=$bd->prepare('UPDATE users WHERE id=:id SET (firstName,lastName,password) VALUES (:username,:email,:password)');
58+
$req->bindValue(':id', $_SESSION['id'], PDO::PARAM_STR);
59+
$req->bindValue(':firstNameMod', $firstNameMod, PDO::PARAM_STR);
60+
$req->bindValue(':lastNameMod', $lastNameMod, PDO::PARAM_STR);
61+
$req->bindValue(':passmod', $passhash, PDO::PARAM_STR);
62+
63+
$req->execute();
64+
$req->closeCursor();
65+
header("Location:profile.php");
66+
exit();
67+
68+
}
69+
else{
70+
print_r($mistakes);
71+
}
72+
}
73+
574
?>
6-
<p>C'te sale gueule</p>
75+
<!DOCTYPE html>
76+
<html lang="en" dir="ltr">
77+
<head>
78+
<meta charset="utf-8">
79+
<title></title>
80+
</head>
81+
<body>
82+
<p>Username : <strong><?php echo $_SESSION['username'];?></strong></p>
83+
<p>First name : <strong><?php echo $_SESSION['firstName'];?></strong></p>
84+
<input type="text" name="firstNameMod" value="First Name" id="firstNameMod">
85+
<p>Last name : <strong><?php echo $_SESSION['lastName'];?></strong></p>
86+
<input type="text" name="lastNameMod" value="Last Name" id="lastNameMod">
87+
<p>Mail address : <strong><?php echo $_SESSION['email'];?></strong></p>
88+
<input type="password" name="passmod" value="" id="passmod" placeholder="Modify your password">
89+
<input type="password" name="passmodconf" value="" id="passmodconf" placeholder="Confirm the password">
90+
<input type='submit' name="modify" value='Modify'>
91+
</body>
92+
</html>

profileN.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
include_once('header.php');
3+
include_once('footer.php');
4+
include_once('db.php');
5+
6+
echo "You need to login first";
7+
?>

samples.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include_once('header.php');
33
include_once('footer.php');
44
?>
5-
<p>V'la les samples ma gozzzz</p>
5+
<p>Samples Here</p>

songs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
include_once('header.php');
33
include_once('footer.php');
44
?>
5-
<p>Tema les sons de fous</p>
5+
<p>Songs Here</p>

0 commit comments

Comments
 (0)