Browse code

Added account system

Jaidyn Lev authored on 2018-11-20 06:43:34
Showing 24 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,5 @@
1
+:username ĵenga.p
2
+:password iusethesamepasswordforeverythingandjustgotowned
3
+:email luser@yahoo.co.uk.cn
4
+:name Jenga Phoenix
5
+%
0 6
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+function car($list)
4
+{
5
+	$car = array_shift($list);
6
+	return $car;
7
+}
8
+
9
+function cdr($list)
10
+{
11
+	$car = array_shift($list);
12
+	return $list;
13
+}
14
+
15
+function cadr($list)
16
+{
17
+	return car(cdr($list));
18
+}
19
+
20
+?>
... ...
@@ -1,8 +1,42 @@
1 1
 <?php
2 2
 
3
-function readfi($file)
3
+
4
+// PATHSTRING --> STRING
5
+//	Return the contents of a file in a string.
6
+function file_read($filepath)
4 7
 {
5
-	readfile($file);
8
+	$stack = "";
9
+	$fstream = fopen($filepath, "r");
10
+
11
+	if ($fstream)
12
+	{
13
+		while (($line = fgets($fstream)) !== false)
14
+		{
15
+			$stack = $stack . $line;
16
+		}
17
+
18
+		fclose($fstream);
19
+		return $stack;
20
+	}
21
+
22
+	return 1;
23
+}
24
+
25
+
26
+
27
+// PATHSTRING STRING ["w"/"a"/etc] --> 0
28
+//	Write a string to a file.
29
+function file_write($filepath, $string, $write_type = "w")
30
+{
31
+	$fstream = fopen($filepath, $write_type);
32
+
33
+	if ($fstream)
34
+	{
35
+		fwrite($fstream, $string);
36
+		return 0;
37
+	}
38
+
39
+	return 1;
6 40
 }
7 41
 
8 42
 ?>
9 43
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+<?php
2
+
3
+
4
+// ROOTDIR_NAME --> ABSOLUTE_PATH_TO_PROJECT_DIR
5
+//	Return the absolute path to the project's root.
6
+function get_project_root()
7
+{
8
+	return preg_replace("%" . $GLOBALS["root_name"] . ".*" . "%",
9
+				$GLOBALS["root_name"] . "/",
10
+				getcwd());
11
+}
12
+
13
+// PATH_RELATIVE_TO_PROJECT_ROOT --> ABSOLUTE_PATH
14
+//	Return the absolute path to something within the project's root.
15
+function root($path)
16
+{
17
+	$absolute_path = get_project_root() . $path;
18
+	return $absolute_path;
19
+}
20
+
21
+include("array.php");
22
+include("file.php");
23
+include("user.php");
24
+include("string/colon.php");
25
+include("string/line.php");
26
+
27
+?>
... ...
@@ -18,6 +18,18 @@ function root($path)
18 18
 	return $absolute_path;
19 19
 }
20 20
 
21
+
22
+function redirect($path)
23
+{
24
+	header("Location: https://albertoefg.info/escuela/"
25
+		. "comercio_electronico/plataforma/" 
26
+		. $path);
27
+	}
28
+
29
+include(root("res/bib/array.php"));
21 30
 include(root("res/bib/file.php"));
31
+include(root("res/bib/user.php"));
32
+include(root("res/bib/string/colon.php"));
33
+include(root("res/bib/string/line.php"));
22 34
 
23 35
 ?>
24 36
new file mode 100644
... ...
@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+
4
+// STRING STRING --> STRING
5
+//	Return the value of a colon-variable in a string.
6
+function colon_value($string, $variable)
7
+{
8
+	$colon_line = line_get($string, "/:" . $variable . " /");
9
+
10
+	return preg_replace("/:" . $variable . " /", "", $colon_line);
11
+}
12
+
13
+?>
0 14
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+<?php
2
+
3
+
4
+// STRING --> LIST
5
+//	Turn a string into a list of strings.
6
+function line_list($string)
7
+{
8
+	return preg_split("/\n/", $string);
9
+}
10
+
11
+
12
+
13
+// LIST --> STRING
14
+//	Combine all strings in a list to a single multiple-line-string.
15
+function line_string($list)
16
+{
17
+	return implode("\n", $list);
18
+}
19
+
20
+
21
+
22
+// MULTI_LINE_STRING --> ARRAY
23
+//	Split a multi-line-string by a certain serperating line.
24
+function line_split($string, $line = "%")
25
+{
26
+	$line_list = line_list($string);
27
+
28
+	if (line_list($string)[0] == $line)
29
+	{
30
+		array_shift($line_list);
31
+		return array(line_string($line_list));
32
+	}
33
+	else
34
+	{
35
+		return preg_split("/\n" . $line . "\n/", $string);
36
+	}
37
+}
38
+
39
+
40
+
41
+// MULTI_LINE_STRING --> NUMBER
42
+//	Return the first position of a line in a string.
43
+function line_pos($string, $line)
44
+{
45
+	$split = line_split($string, $line);
46
+	
47
+	if (count($split) == 1)
48
+	{
49
+		return 0;
50
+	}
51
+	else
52
+	{
53
+		return count(line_list($split[0]));
54
+	}
55
+}
56
+
57
+
58
+
59
+// MULTI_LINE_STRING STRING --> STRING
60
+//	Return a line matching the regex.
61
+function line_get($string, $regex)
62
+{
63
+	return car(preg_grep($regex, line_list($string)));
64
+}
65
+
66
+
67
+
68
+// STRING STRING STRING --> STRING
69
+//	Replace a line in a string with another line.
70
+function line_replace($string, $line, $new_line)
71
+{
72
+	$line_list = line_list($string);
73
+	$line_pos = line_pos($string, $line);
74
+
75
+	$line_list[$line_pos] = $new_line;
76
+
77
+	return line_string($line_list);
78
+}
79
+
80
+?>
0 81
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+<?php
2
+
3
+include("principal-local.php");
4
+
5
+
6
+$colon_string = file_read("test.txt");
7
+
8
+echo user_block($colon_string, "bardos");
0 9
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+:username ily.con
2
+:password mydogislove
3
+:email ilyovich.conners@gmail.co.uk.cn
4
+:name Ilyovich Conners
5
+%
6
+:username bh.ri
7
+:password notreallymate
8
+:email bhuahju.riley
9
+:name Bhuaju Riley
10
+%
11
+:username bardos
12
+:password Rafael88}%
13
+:name Bárdos Rafael
14
+:email rafael@rafael.info.zh
15
+%
0 16
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+<?php
2
+
3
+function user_create($username, $password, $email, $name)
4
+{
5
+	$usernamel = ":username " . $username;
6
+	$passwordl = ":password " . $password;
7
+	$emaill = ":email " . $email;
8
+	$namel = ":name " . $name;
9
+
10
+	$user_block = implode("\n", array($usernamel, $passwordl, $emaill, $namel, "%"));
11
+	
12
+	return $user_block;
13
+}
14
+
15
+
16
+
17
+function user_block($string, $username)
18
+{
19
+	$block_list = line_split($string);
20
+	$i = 0;
21
+
22
+
23
+	while (colon_value($block_list[$i], "username") != $username)
24
+	{
25
+		$i++;
26
+	}
27
+
28
+
29
+	return $block_list[$i];
30
+}
31
+
32
+
33
+
34
+
35
+// STRING STRING --> STRING
36
+//	Return a user's name
37
+function user_name($string, $username)
38
+{
39
+	return colon_value($string, "name");
40
+}
41
+
42
+
43
+// STRING STRING --> STRING
44
+//	Return a user's email
45
+function user_email($string, $username)
46
+{
47
+	return colon_value($string, "email");
48
+}
49
+
50
+
51
+// STRING STRING --> STRING
52
+//	Return a user's password
53
+function user_password($string, $username)
54
+{
55
+	return colon_value($string, "password");
56
+}
57
+
58
+
59
+function user_logged_in()
60
+{
61
+	return $_COOKIE["username"];
62
+}
63
+
64
+?>
0 65
new file mode 100644
... ...
@@ -0,0 +1,36 @@
1
+#navbar {
2
+	background-color: #8CDCF2;
3
+
4
+	font-size: 17px;
5
+}
6
+
7
+#navbar ul {
8
+	list-style-type: none;
9
+	margin: 0;
10
+	padding: 0;
11
+	padding-top: 10px;
12
+	padding-bottom: 10px;
13
+}
14
+
15
+#navbar ul li {
16
+	display: inline;
17
+}
18
+
19
+.wide {
20
+	margin-left: 50px;
21
+	margin-right: 50px;
22
+}
23
+
24
+#username {
25
+	margin-right: 5px;
26
+	margin-left: 0px;
27
+}
28
+
29
+#logout {
30
+	margin-right: 0px;
31
+	margin-left: 5px;
32
+}
33
+
34
+.right {
35
+	float: right;
36
+}
... ...
@@ -10,6 +10,7 @@
10 10
 	<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/lato" type="text/css"/>
11 11
 	
12 12
 	<link href="/escuela/comercio_electronico/plataforma/res/css/fontawesome/css/all.css" rel="stylesheet">
13
-	<link rel="stylesheet" href="<?php echo "/escuela/comercio_electronico/plataforma/res/css/chatui.css"; ?>">
14
-	<link rel="stylesheet" href="<?php echo "/escuela/comercio_electronico/plataforma/res/css/styles.css"; ?>">
13
+	<link rel="stylesheet" href="/escuela/comercio_electronico/plataforma/res/css/chatui.css">
14
+	<link rel="stylesheet" href="/escuela/comercio_electronico/plataforma/res/css/styles.css">
15
+	<link rel="stylesheet" href="/escuela/comercio_electronico/plataforma/res/css/site.css">
15 16
     </head>
... ...
@@ -1 +1,38 @@
1
+<?php
2
+	$users = file_read(root("local/users.txt"));
3
+?>
4
+
1 5
 <body>
6
+<div id="navbar">
7
+	<ul>
8
+		<li class="wide"><a href="/escuela/comercio_electronico/plataforma/">Home</a></li>
9
+		<li class="wide"><a href="/escuela/comercio_electronico/plataforma/">Información</a></li>
10
+<?php
11
+
12
+	if (user_logged_in())
13
+	{
14
+		?>
15
+		<li class="right wide" id="logout">
16
+			<a href="/escuela/comercio_electronico/plataforma/visitante/logout">
17
+			<i class="fas fa-door-open"></i></a></li>
18
+		<li class="right wide" id="username">
19
+			<i><a href="/escuela/comercio_electronico/plataforma/visitante/user/">
20
+				<?php echo user_name($users, $user_logged_in); ?></a></i></li>
21
+		<li class="right wide">
22
+			<a href="/escuela/comercio_electronico/plataforma/visitante/user/citas">
23
+			Citas</a></li>
24
+		<li class="right wide">
25
+			<a href="/escuela/comercio_electronico/plataforma/visitante/user/quejas">
26
+			Quejas</a></li>
27
+		<?php
28
+	}
29
+	else
30
+	{
31
+		?>
32
+		<li class="right wide"><a href="/escuela/comercio_electronico/plataforma/empresario">Empresario</a></li>
33
+		<li class="right wide"><a href="/escuela/comercio_electronico/plataforma/visitante">Visitante</a></li>
34
+<?php
35
+	}
36
+?>
37
+	</ul>
38
+</div>
2 39
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+include("../../res/config.php");
4
+include("../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="LOGIN";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<form action="private/login.php" method="post" enctype="multipart/form-data">
17
+	<p><input type="text" placeholder="USERNAME" name="username"></p>
18
+	<p><input type="text" placeholder="PASSWORD" name="password"></p>
19
+
20
+	<input type="submit" name="submit">
21
+</form>
22
+
23
+<?php
24
+// -------------------------------------
25
+
26
+include(root("res/temp/footer.php"));
27
+
28
+?>
0 29
new file mode 100644
... ...
@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$username = $_POST["username"];
9
+$password = $_POST["password"];
10
+
11
+$users = file_read("../../../local/users.txt");
12
+
13
+if (empty($username) || empty($password))
14
+{
15
+	redirect("visitante/login/result/login-incomplete.php");
16
+}
17
+else
18
+{
19
+	if (user_password($users, $username) == $password)
20
+	{
21
+		setcookie("username", $username, time() + (86400 * 30), "/");
22
+
23
+		setcookie("name", user_name($users, $username), time() + (86400 * 30), "/");
24
+		setcookie("email", user_email($users, $username), time() + (86400 * 30), "/");
25
+
26
+		redirect("visitante/login/result/login-pass.php");
27
+	}
28
+	else
29
+	{
30
+		redirect("visitante/login/result/login-fail.php");
31
+	}
32
+}
0 33
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="LOGIN FAILURE";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<h2>INCORRECT PASSWORD OR USERNAME.</h2>
17
+<h3>PLEASE, <a href="../index.php">TRY AGAIN</a>.</h3>
18
+
19
+
20
+<?php
21
+// -------------------------------------
22
+
23
+include(root("res/temp/footer.php"));
24
+
25
+?>
0 26
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="ACCOUNT NOT CREATED";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<h2>PLEASE FILL OUT EVERY REQUIRED FORM.</h2>
17
+<h3>PLEASE, <a href="../index.php">TRY AGAIN</a>.</h3>
18
+
19
+
20
+<?php
21
+// -------------------------------------
22
+
23
+include(root("res/temp/footer.php"));
24
+
25
+?>
0 26
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+redirect("vistante/user/");
9
+
10
+?>
0 11
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+include("../../res/config.php");
4
+include("../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+setcookie("username", "", time() - (86400 * 30), "/");
9
+redirect("");
10
+
11
+?>
0 12
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+include("../../res/config.php");
4
+include("../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="SIGN UP";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<form action="private/account-create.php" method="post" enctype="multipart/form-data">
17
+	<p><input type="text" placeholder="USERNAME" name="username"></p>
18
+	<p><input type="text" placeholder="PASSWORD" name="password"></p>
19
+	<p><input type="text" placeholder="NAME" name="name"></p>
20
+	<p><input type="text" placeholder="EMAIL" name="email"></p>
21
+
22
+	<input type="submit" name="submit">
23
+</form>
24
+
25
+<?php
26
+// -------------------------------------
27
+
28
+include(root("res/temp/footer.php"));
29
+
30
+?>
0 31
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$username = $_POST["username"];
9
+$password = $_POST["password"];
10
+$email = $_POST["email"];
11
+$name = $_POST["name"];
12
+
13
+if (empty($username) || empty($password) || empty($email) || empty($name))
14
+{
15
+	redirect("vistante/signup/result/account/create-fail.php");
16
+}
17
+else
18
+{
19
+	file_write("../../../local/users.txt",
20
+		user_create($username, $password, $email, $name) . "\n",
21
+		"a");
22
+	redirect("visitante/signup/result/account/create-pass.php");
23
+}
0 24
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="ACCOUNT NOT CREATED";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<h2>PLEASE FILL OUT EVERY REQUIRED FORM.</h2>
17
+<h3>PLEASE, <a href="../index.php">TRY AGAIN</a>.</h3>
18
+
19
+
20
+<?php
21
+// -------------------------------------
22
+
23
+include(root("res/temp/footer.php"));
24
+
25
+?>
0 26
new file mode 100644
... ...
@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+include("../../../res/config.php");
4
+include("../../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="ACCOUNT CREATED";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+// -------------------------------------
13
+?>
14
+
15
+
16
+<h2>YOUR ACCOUNT HAS BEEN CREATED!</h2>
17
+<h3>PLEASE, PROCEED TO <a href="../../login">LOG IN</a>.</h3>
18
+
19
+
20
+<?php
21
+// -------------------------------------
22
+
23
+include(root("res/temp/footer.php"));
24
+
25
+?>
0 26
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+include("../../res/config.php");
4
+include("../../res/bib/principal.php");
5
+
6
+// -------------------------------------
7
+
8
+$page_title="Visitante";
9
+include(root("res/temp/head.php"));
10
+include(root("res/temp/header.php"));
11
+
12
+$users = file_read(root("local/users.txt"));
13
+$user = user_logged_in();
14
+
15
+// -------------------------------------
16
+?>
17
+
18
+<h2>Welcome, <?php echo user_name($users, $user); ?>!</h2>
19
+
20
+<?php
21
+// -------------------------------------
22
+
23
+include(root("res/temp/footer.php"));