-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
191 additions
and
91 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
global $settings; | ||
$settings = require( '../settings.php' ); | ||
require_once "../models/db.php"; | ||
include "../models/blog.php"; | ||
include "../views/header.php"; | ||
|
||
|
||
if (isset($_GET['page'])) { | ||
$page=$_GET['page']; | ||
$blog=allBlogPosts($page*10-10, $page*10, 'blogdate'); | ||
} | ||
else { | ||
$page=1; | ||
$ground=0; | ||
$ceiling=10; | ||
$blog=allBlogPosts($ground, $ceiling, 'blogdate'); | ||
} | ||
|
||
include "../views/globalblogs/view.php"; | ||
include "../views/footer.php"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
<?php | ||
include "views/header.php"; | ||
include "views/register/view.php"; | ||
include "views/footer.php"; | ||
global $settings; | ||
$settings = require( "../settings.php"); | ||
require "../models/db.php"; | ||
require "../models/user.php"; | ||
include "views/header.php"; | ||
|
||
if (!isset($_POST['username'])||!isset($_POST['password'])||!isset($_POST['email'])) { | ||
include "views/register/view.php"; | ||
include "views/footer.php"; | ||
} | ||
else { | ||
register($_POST['username'], $_POST['password'], $_POST['email']); | ||
header('Location: globalblogs.php'); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,136 @@ | ||
<?php | ||
//A function that given the userid returns the details of the profile | ||
//of the requested user | ||
function getProfileDetails($userid) { | ||
if (!$userid) { | ||
return false; | ||
//A function that given the userid returns the details of the profile | ||
//of the requested user | ||
function getProfileDetails($userid) { | ||
if (!$userid) { | ||
die("Not valid userid!"); | ||
} | ||
$res = mysql_query( | ||
$res = mysql_query( | ||
"SELECT | ||
* | ||
FROM | ||
user | ||
WHERE | ||
userid = $userid | ||
LIMIT 1"); | ||
* | ||
FROM | ||
user | ||
WHERE | ||
userid = :userid | ||
LIMIT 1"); | ||
if(!mysql_num_rows($res)) { | ||
return false; | ||
die("Error fetching from MySQL profile details"); | ||
} | ||
$row = mysql_fetch_array( $res ); | ||
return $row; | ||
} | ||
return $row; | ||
} | ||
|
||
//User login function | ||
function login( $username, $password ){ | ||
$username=sanitize( $username ); | ||
$passwordHash=hash("sha1", $password ); | ||
|
||
$res = mysql_query( | ||
"SELECT | ||
* | ||
FROM | ||
login | ||
WHERE | ||
username='$username' | ||
AND | ||
password='$passwordHash' | ||
"); | ||
if( mysql_num_rows($res) == 0 ){ | ||
die("Login error, username not found"); | ||
} | ||
mysql_query( | ||
"UPDATE | ||
login | ||
SET | ||
enter = 1 | ||
WHERE | ||
username = '$username' | ||
"); | ||
|
||
return mysql_fetch_array( $res ); | ||
} | ||
|
||
//User registration function | ||
function register( $name, $password, $email ){ | ||
$name = sanitize ( $name ); | ||
$email = sanitize ( $email ); | ||
$passwordHash = hash("sha1", $password ); | ||
|
||
$exists = mysql_query( | ||
"SELECT | ||
loginid | ||
FROM | ||
login | ||
WHERE | ||
username = '$name' | ||
"); | ||
if( mysql_num_rows( $exists ) > 0 ){ | ||
die("Username exists!"); | ||
} | ||
|
||
|
||
$insertToLogin = mysql_query( | ||
"INSERT INTO | ||
login ( username, password, email, created ) | ||
VALUES | ||
( '$name', '$passwordHash', '$email', NOW() ) | ||
"); | ||
|
||
//User login function returns details of the user login info | ||
function login( $username, $password ){ | ||
$username=sanitize( $username ); | ||
$passwordHash=hash("sha1", sanitize( $password ) ); | ||
|
||
$loginId = mysql_query( | ||
"SELECT | ||
loginid | ||
FROM | ||
login | ||
WHERE | ||
username = '$name' | ||
"); | ||
|
||
$res = mysql_query( | ||
"SELECT | ||
* | ||
FROM | ||
login | ||
WHERE | ||
username=$username | ||
AND | ||
password=$passwordHash | ||
"); | ||
if( mysql_num_rows($res) == 0 ){ | ||
return false; | ||
} | ||
return mysql_fetch_array( $res ); | ||
} | ||
$insertToUser = mysql_query( | ||
"INSERT INTO | ||
user ( loginid, email ) | ||
VALUES | ||
( '$loginId', '$email' ) | ||
"); | ||
|
||
if( !$insertToLogin | ||
|| !$insertToUser | ||
|| !$loginId ){ | ||
//If something went wrong, delete added records, just in case. | ||
//Basically maybe it doesn't work really well, what if duplicate username??? | ||
mysql_query( | ||
"DELETE FROM | ||
login | ||
WHERE | ||
loginid = '$loginId' | ||
"); | ||
|
||
//User registration function | ||
function register( $username, $password, $email ) { | ||
mysql_query( | ||
"INSERT INTO | ||
login (username, password, email, created, enter) | ||
VALUES | ||
('sanitize($username)', 'sanitize($password)', 'sanitize($email)', 'NOW()', '1') | ||
"); | ||
if( mysql_affected_rows() != 1 ){ | ||
return false; | ||
} | ||
return | ||
array( | ||
"id" => mysql_insert_id(), | ||
"username" => $username | ||
); | ||
} | ||
mysql_query( | ||
"DELETE FROM | ||
user | ||
WHERE | ||
loginid = '$loginId' | ||
"); | ||
|
||
//Sanitizes input to prevent SQl injections | ||
function sanitize($input){ | ||
if( get_magic_quotes_gpc() ){ | ||
$input=stripslashes($input); | ||
} | ||
die( "MySQL error during register" ); | ||
} | ||
return array( | ||
//mysql_insert_id return last auto-incremented value from last query | ||
//in this case, userid from table user | ||
"userid" => mysql_insert_id(), | ||
"username" => $name | ||
); | ||
} | ||
|
||
$input=mysql_real_escape_string($input); | ||
return $input; | ||
} | ||
?> | ||
//Sanitizes input to prevent SQl injections | ||
function sanitize($input){ | ||
if( get_magic_quotes_gpc() ){ | ||
$input=stripslashes($input); | ||
} | ||
|
||
$input=mysql_real_escape_string($input); | ||
return $input; | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div id="bloglist"> | ||
<ul class="list" id="globalblogs"> | ||
<?php | ||
for($i=0;$i<count($blog);$i++) { | ||
echo "<li><a href=\"userblog.php?userid=".$blog[$i]['userid']."\">".$blog[$i]['title']."</a></li>"; | ||
} | ||
?> | ||
</ul> | ||
<?php echo "<a href=globalblogs.php?page=".($page+1).">Next Page</a>"; ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters