Skip to content

Commit 4850142

Browse files
Merge pull request #35 from BinarySoftware/SE2GoldenMaster
StockExperience 2.0 Golden Master
2 parents a8bec02 + 4fc2171 commit 4850142

20 files changed

+284
-128
lines changed

backend/db(needs_setup).php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
<!--
2+
db.html
3+
StockExperience
4+
5+
Edited by BinarySoftware on 07/03/2019.
6+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
7+
8+
Purpose: Database connection settings - you need to set them according to specs of your server, then rename file to db.php
9+
-->
10+
111
<?php
2-
/* Database connection settings */
312
$host = 'your_host';
413
$user = 'your_username';
514
$pass = 'your_password';

backend/debug.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
<!--
2+
debug.html
3+
StockExperience
4+
5+
Edited by BinarySoftware on 07/03/2019.
6+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
7+
8+
Purpose: Methods for debugging app, not crucial to functioning
9+
-->
10+
111
<?php
212

3-
function console_log( $data ){
13+
// using this method to log small bits of data to the console while debugging
14+
function console_log( $data ) {
415
echo '<script>';
516
echo 'console.log('. json_encode( $data ) .')';
617
echo '</script>';
7-
}
18+
}
819

9-
function console_log_messages( ...$messages ){
20+
// using this method to log larger arrays of data to the console while debugging
21+
function console_log_messages( ...$messages ) {
1022
$msgs = '';
23+
1124
foreach ($messages as $msg) {
1225
$msgs .= json_encode($msg);
1326
}

backend/forgotBackend.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
<?php
22
require 'db.php';
33
session_start();
4+
?>
45

5-
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
6-
{
6+
<!--
7+
forgotBackend.html
8+
StockExperience
9+
10+
Edited by BinarySoftware on 07/03/2019.
11+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
12+
13+
Purpose: Backend part for sending data to user if user requested to change password
14+
-->
15+
16+
<?php
17+
// this page is used in order to help users in case they have forgotten their password
18+
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
719
$email = $mysqli->escape_string($_POST['email']);
820
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
9-
if ( $result->num_rows == 0 ) // User doesn't exist
10-
{
21+
if ( $result->num_rows == 0 ) {// result has no rows, hence user doesn't exist
1122
$_SESSION['message'] = "Użytkownik z takim adresem nie istnieje!";
1223
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
13-
}
14-
else { // User exists (num_rows != 0)
15-
$user = $result->fetch_assoc(); // $user becomes array with user data
24+
} else { // User exists (num_rows != 0)
25+
$user = $result->fetch_assoc(); // $user - array containing all user data
1626
$email = $user['email'];
1727
$hash = $user['hash'];
1828
$first_name = $user['first_name'];
19-
// Session message to display on success.php
29+
30+
//message informing user to check their inbox
2031
$_SESSION['message'] = "<p>Proszę sprawdzić mail <span>$email</span>"
2132
. " gdzie został wysłany link do ukończenia zerowania hasła!</p>";
22-
// Send registration confirmation link (reset.php)
2333
$to = $email;
2434
$subject = 'Zerowanie hasła ( StockExperience )';
2535
$message_body = '
2636
Witaj '.$first_name.',
2737
Prosiłeś o możliwość wyzerowania hasła, oto twój link:
2838
http://stockexperiencepl.000webhostapp.com/reset.php?email='.$email.'&hash='.$hash;
2939
mail($to, $subject, $message_body);
40+
3041
echo "<script type='text/javascript'> document.location = '../success.php'; </script>";
3142
}
3243
}

backend/login.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
<!--
2+
login.html
3+
StockExperience
4+
5+
Edited by BinarySoftware on 07/03/2019.
6+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
7+
8+
Purpose: Backend part for logging in user
9+
-->
10+
111
<?php
212
// Escape email to protect against SQL injections
313
$email = $mysqli->escape_string($_POST['email']);
414
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
515

6-
if ( $result->num_rows == 0 ){ // User doesn't exist
16+
if ( $result->num_rows == 0 ) { // result has no rows, hence user doesn't exist
717
$_SESSION['message'] = "Użytkownik z takim adresem nie istnieje!";
818
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
9-
}
10-
else { // User exists
19+
} else { // User exists
1120
$user = $result->fetch_assoc();
1221
if ( password_verify($_POST['password'], $user['password']) ) {
1322
$_SESSION['email'] = $user['email'];
@@ -16,11 +25,10 @@
1625
$_SESSION['active'] = $user['active'];
1726
$_SESSION['money'] = $user['money'];
1827
$_SESSION['action_qty_dict'] = $user['action_qty_dict'];
19-
// This is how we'll know the user is logged in
28+
// flag to check if user is logged in, for later use
2029
$_SESSION['logged_in'] = true;
2130
echo "<script type='text/javascript'> document.location = '../profile.php'; </script>";
22-
}
23-
else {
31+
} else { // wrong password
2432
$_SESSION['message'] = "Błędne hasło!";
2533
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
2634
}

backend/profileBackend.php

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<?php
22
error_reporting(0);
33
require 'db.php';
4-
// require 'debug.php';
54
session_start();
5+
?>
66

7+
<!--
8+
profileBackend.html
9+
StockExperience
10+
11+
Edited by BinarySoftware on 07/03/2019.
12+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
13+
14+
Purpose: Backend part for setting up profile page
15+
-->
16+
17+
<?php
718
// Check if user is logged in using the session variable
819
if ( $_SESSION['logged_in'] != 1 ) {
920
$_SESSION['message'] = "Nie wyświetlimy danych bez zalogowania!";
1021
echo "<!DOCTYPE html><script type='text/javascript'> document.location = '../error.php'; </script>";
11-
}
12-
else {
22+
} else { //correct check, parse data
1323
$email = $mysqli->escape_string($_SESSION['email']);
1424
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'");
1525
$user = $result->fetch_assoc();
@@ -41,8 +51,7 @@
4151

4252
$Header = $DOM->getElementsByTagName('tr');
4353
//#Get header name of the table
44-
foreach($Header as $NodeHeader)
45-
{
54+
foreach($Header as $NodeHeader) {
4655
$aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
4756
}
4857

@@ -63,35 +72,15 @@
6372
$actions_dict = implode(",", $actions_ar);
6473
$sql = "UPDATE users SET money='$money', action_qty_dict='$actions_dict' WHERE email='$email'";
6574
if ( $mysqli->query($sql) ) {
66-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
67-
<div class=\"modal-content\">
68-
<span class=\"close\">x</span>
69-
<h3 style='color:#000000'>Pomyslnie zakupiono akcje</h3>
70-
</div>
71-
</div>";
75+
createModal("Pomyślnie zakupiono akcje");
7276
} else {
73-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
74-
<div class=\"modal-content\">
75-
<span class=\"close\">x</span>
76-
<h3 style='color:#000000'>Problem z serwerem, transakcja odrzucona</h3>
77-
</div>
78-
</div>";
77+
createModal("Problem z serwerem, transakcja odrzucona");
7978
}
8079
} else {
81-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
82-
<div class=\"modal-content\">
83-
<span class=\"close\">x</span>
84-
<h3 style='color:#000000'>Za mało środków na koncie, transakcja odrzucona</h3>
85-
</div>
86-
</div>";
80+
createModal("Za mało środków na koncie, transakcja odrzucona");
8781
}
8882
} else {
89-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
90-
<div class=\"modal-content\">
91-
<span class=\"close\">x</span>
92-
<h3 style='color:#000000'>Brak wartosci podanej w okienku</h3>
93-
</div>
94-
</div>";
83+
createModal("Brak wartości podanej w okienku");
9584
}
9685
//sell index
9786
} elseif ( isset( $_GET[$index[0].'s'] ) ) {
@@ -104,38 +93,29 @@
10493
$actions_dict = implode(",", $actions_ar);
10594
$sql = "UPDATE users SET money='$money', action_qty_dict='$actions_dict' WHERE email='$email'";
10695
if ( $mysqli->query($sql) ) {
107-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
108-
<div class=\"modal-content\">
109-
<span class=\"close\">x</span>
110-
<h3 style='color:#000000'>Pomyslnie sprzedano akcje</h3>
111-
</div>
112-
</div>";
96+
createModal("Pomyślnie sprzedano posiadane akcje");
11397
} else {
114-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
115-
<div class=\"modal-content\">
116-
<span class=\"close\">x</span>
117-
<h3 style='color:#000000'>Problem z serwerem, transakcja odrzucona</h3>
118-
</div>
119-
</div>";
98+
createModal("Problem z serwerem, transakcja odrzucona");
12099
}
121100
} else {
122-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
123-
<div class=\"modal-content\">
124-
<span class=\"close\">x</span>
125-
<h3 style='color:#000000'>Za mało akcji, transakcja odrzucona</h3>
126-
</div>
127-
</div>";
101+
createModal("Za mało posiadanych akcji, transakcja odrzucona");
128102
}
129103
} else {
130-
echo "<!DOCTYPE html><div id=\"ActionSendWindow\", class=\"modal\">
131-
<div class=\"modal-content\">
132-
<span class=\"close\">x</span>
133-
<h3 style='color:#000000'>Brak wartosci podanej w okienku</h3>
134-
</div>
135-
</div>";
104+
createModal("Brak wartości podanej w okienku");
136105
}
137106
}
107+
//recalculate wallet
138108
$totalMoneyInStocks += floatval($price)*floatval($index[1]);
139109
}
140110
}
111+
112+
function createModal( $message ) {
113+
echo '<!DOCTYPE html><div id="ActionSendWindow", class="modal">
114+
<div class="modal-content">
115+
<span class="close">x</span>
116+
<h3 style="color:#010101">'.$message.'</h3>
117+
</div>
118+
</div>';
119+
}
120+
141121
?>

backend/register.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<!--
2+
register.html
3+
StockExperience
4+
5+
Edited by BinarySoftware on 07/03/2019.
6+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
7+
8+
Purpose: Backend part for registering new user
9+
-->
10+
111
<?php
212
// Set session variables to be used on profile.php page
313
$_SESSION['email'] = $_POST['email'];
@@ -17,11 +27,10 @@
1727
if ( $result->num_rows > 0 ) {
1828
$_SESSION['message'] = 'Uzytkownik z takim mailem już istnieje!';
1929
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
20-
}
21-
else {
30+
} else {
2231
// active is 0 by DEFAULT
2332
//Small forloop to make mainteneance easier in case of changes in stock indexes
24-
$indexes = ["KGH","PKO","PKN","PZU","JSW","CCC","DNP","CDR","LTS","ALR","TPE","PEO","SAN","PGN","GNB","ENG","PGE","ENA","EUR","KRU","PKP","LPP","PLY","MIL","CPS","OPL","MBK","EAT","BMC","VST","GTC","BFT","MRB","11B","MAB","EURPLN","CHFPLN","USDPLN","GBPPLN"];
33+
$indexes = ["KGH","PKO","PKN","PZU","JSW","CCC","DNP","CDR","LTS","ALR","TPE","PEO","SAN","PGN","GNB","ENG","PGE","ENA","EUR","KRU","PKP","LPP","PLY","MIL","CPS","OPL","MBK","EAT","BMC","VST","GTC","BFT","MRB","11B","MAB","EURPLN","CHFPLN","USDPLN","GBPPLN"]; //indexes we want to use from GPW
2534
$listIndexValue = "";
2635
$lastElement = end($indexes);
2736
foreach ($indexes as &$index) {
@@ -32,15 +41,15 @@
3241
$listIndexValue .= "-0,";
3342
}
3443
}
44+
//sql query to add user to app
3545
$sql = "INSERT INTO users (first_name, last_name, email, password, hash, money, action_qty_dict) "
3646
. "VALUES ('$first_name','$last_name','$email','$password','$hash','100000','$listIndexValue')";
3747

38-
// Add user to the database
39-
if ( $mysqli->query($sql) ){
48+
if ( $mysqli->query($sql) ) {
4049
$_SESSION['active'] = 0; //0 until user activates their account with verify.php
4150
$_SESSION['logged_in'] = true; // So we know the user has logged in
4251
$_SESSION['message'] = "Link weryfikacyjny wysłany na: $email, prosimy o weryfikacje przez kliknięcie w link!";
43-
// Send registration confirmation link (verify.php)
52+
// Send registration confirmation link (verify.php) via email
4453
$to = $email;
4554
$subject = 'Weryfikacja konta ( StockExperience )';
4655
$message_body = '
@@ -50,7 +59,7 @@
5059
https://stockexperiencepl.000webhostapp.com/backend/verify.php?email='.$email.'&hash='.$hash;
5160
mail( $to, $subject, $message_body );
5261
echo "<script type='text/javascript'> document.location = '../profile.php'; </script>";
53-
} else {
62+
} else { //if anything has gone wrongs
5463
$_SESSION['message'] = 'Błąd rejestracji!';
5564
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
5665
}

backend/resetBackend.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
<?php
22
require 'db.php';
33
session_start();
4+
?>
5+
6+
<!--
7+
resetBackend.html
8+
StockExperience
9+
10+
Edited by BinarySoftware on 07/03/2019.
11+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
12+
13+
Purpose: Backend part of forgot.php
14+
-->
15+
16+
<?php
417
// Make sure email and hash variables aren't empty
5-
if( isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash']) )
6-
{
18+
if( isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash']) ) {
719
$email = $mysqli->escape_string($_GET['email']);
820
$hash = $mysqli->escape_string($_GET['hash']);
9-
// Make sure user email with matching hash exist
21+
// Make sure user email with matching hash exist in db
1022
$result = $mysqli->query("SELECT * FROM users WHERE email='$email' AND hash='$hash'");
11-
if ( $result->num_rows == 0 )
12-
{
23+
if ( $result->num_rows == 0 ) {
1324
$_SESSION['message'] = "Zły adres do wyzerowania hasła!";
1425
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
1526
}

backend/reset_password.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<?php
2-
/* Password reset process, updates database with new user password */
32
require 'db.php';
43
session_start();
4+
?>
5+
6+
<!--
7+
reset_password.html
8+
StockExperience
9+
10+
Edited by BinarySoftware on 07/03/2019.
11+
Copyright ©2019 BinarySoftware/Maciej Mikołajek. All rights reserved.
12+
13+
Purpose: Backend part of reset.php
14+
-->
15+
16+
<?php
517
// Make sure the form is being submitted with method="post"
618
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
719
// Make sure the two passwords match
@@ -15,8 +27,7 @@
1527
$_SESSION['message'] = "Hasło pomyślnie wyzerowane!";
1628
echo "<script type='text/javascript'> document.location = '../success.php'; </script>";
1729
}
18-
}
19-
else {
30+
} else {
2031
$_SESSION['message'] = "Hasła się nie zgadzają!";
2132
echo "<script type='text/javascript'> document.location = '../error.php'; </script>";
2233
}

0 commit comments

Comments
 (0)