Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5ea1852
Merge pull request #35 from Glennmen/develop
Glennmen Feb 19, 2018
d448786
Merge pull request #107 from Glennmen/develop
Glennmen Mar 20, 2018
833cfe6
[add]Simple login form and js login check
mfaalk Mar 26, 2018
7cd9984
[fix]removed old code
mfaalk Mar 26, 2018
9cf6a99
[add]Webhook, change password
mfaalk Mar 26, 2018
fa226a0
[add]enable or disable login from config
mfaalk Mar 26, 2018
0a38249
[add]show expire date on home page
mfaalk Mar 26, 2018
ab35fc2
[add]move salt to config file
mfaalk Mar 26, 2018
41505c3
[add]logout button and user info
mfaalk Mar 26, 2018
6ba7ef5
[add]logout.php
mfaalk Mar 26, 2018
c9fddaa
[fix]Stop it travis :-(
mfaalk Mar 26, 2018
5cc7e4e
[fix]Stop it travis 2 :-(
mfaalk Mar 26, 2018
79f151b
[fix]Stop it travis 3 :-(
mfaalk Mar 26, 2018
e8d25aa
[fix]styleci? ^_^
mfaalk Mar 26, 2018
1156cff
[fix]styleci pls
mfaalk Mar 26, 2018
32e2d90
[fix]pre-index, wh plus sign
mfaalk Mar 26, 2018
1a1d146
[fix]wh plus sign
mfaalk Mar 26, 2018
ca1d738
[fix]wh plus sign
mfaalk Mar 26, 2018
416be1e
[fix]styleci
mfaalk Mar 26, 2018
79c4ac6
[fix]wh plus sign
mfaalk Mar 26, 2018
8d351bc
[fix]more plus signs
mfaalk Mar 26, 2018
4a29508
[add]translations
mfaalk Mar 26, 2018
ba6a3cf
[add]making the login page sexier and minor text fixes
mfaalk Mar 26, 2018
cfbf531
[remove]removed test code
mfaalk Mar 26, 2018
3e8f103
[edit]indents to spaces...
mfaalk Mar 26, 2018
d4d8dd3
[add]lock iv in config for non paying users
mfaalk Mar 26, 2018
9c29415
[fix]change from sha1 to password_hash encryption
mfaalk Mar 27, 2018
927eea7
[fix]indeeeeeeeents <3
mfaalk Mar 27, 2018
836252c
[add]forgot password form, design update and db structure change.
mfaalk Mar 27, 2018
76fa9fe
[fix]comma
mfaalk Mar 27, 2018
62b22fa
[fix]indents to spaces
mfaalk Mar 27, 2018
87376fa
[add]added possibiliy to create admin accounts
mfaalk Mar 28, 2018
1501bd3
[fix]minor text fixes
mfaalk Mar 28, 2018
576bb5b
[add]admin features etc...
mfaalk Mar 28, 2018
279fa20
[add]account creation
mfaalk Apr 4, 2018
5c8fb4f
ooops
mfaalk Apr 4, 2018
917c554
minor text fixes
mfaalk Apr 4, 2018
6b2aff4
[add]logging all queries for emergency
Apr 4, 2018
43c3a34
[fix]permission
Apr 4, 2018
d9f27fa
[fix]test
mfaalk Apr 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions checklogin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
include('config/config.php');
header('Content-Type: application/json');
$info = array();

if ($enableLogin === true) {
$info['enableLogin'] = true;
if (isset($_SESSION['user'])) {
$info['isLoggedIn'] = true;
$info['current_timestamp'] = time();
$info['user'] = $_SESSION['user'];
} else {
$info['isLoggedIn'] = false;
}
} else {
$info['enableLogin'] = false;
}

print json_encode($info);
7 changes: 7 additions & 0 deletions config/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@

$enableDebug = false;

//-----------------------------------------------------
// Login
//-----------------------------------------------------

$enableLogin = false; // true/false
$salt = "5up3r53cr3754l7"; // Type something super secret that will salt your passwords.

//-----------------------------------------------------
// DATABASE CONFIG
//-----------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions config/example.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@

$enableDebug = false;

//-----------------------------------------------------
// Login
//-----------------------------------------------------

$enableLogin = false; // true/false
$salt = "5up3r53cr3754l7"; // Type something super secret that will salt your passwords.

//-----------------------------------------------------
// DATABASE CONFIG
//-----------------------------------------------------
Expand Down
98 changes: 98 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
include('config/config.php');
if ($enableLogin === true) {
if (isset($_POST['submit_updatePwd'])) {
if (!empty($_POST["password"]) && ($_POST["password"] == $_POST["repassword"])) {
$passwordErr = '';
$password = $_POST["password"];

if (strlen($_POST["password"]) <= '5') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt make sense. Says Less than or equal to 5 and the error says 8?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved. Forgot to update the error message. Min character set to 6.

$passwordErr = "<b>Your password must contain at least 8 characters!</b><br>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

} elseif (!preg_match("#[0-9]#", $password)) {
$passwordErr = "<b>Your password must contain at least 1 number!</b><br>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

} elseif (!preg_match("#[A-Z]#", $password)) {
$passwordErr = "<b>Your password must contain at least 1 capital letter!</b><br>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

} elseif (!preg_match("#[a-z]#", $password)) {
$passwordErr = "<b>Your password must contain at least 1 lowercase letter!</b><br>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

}
} else {
$passwordErr = "<b>Your passwords didn't match!</b><br>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

}

if (empty($passwordErr)) {
$db->update("users", [
"password" => sha1($_POST['password'] . $salt),
"updatePwd" => 0
], [
"email" => $_SESSION['user']->email
]);

header("Location: .");
die();
} else {
echo $passwordErr;
}
}

if (isset($_POST['submit_login'])) {
$info = $db->query(
"SELECT email, expire_timestamp, updatePwd FROM users WHERE email = :email AND password = :password", [
":email" => $_POST['email'],
":password" => sha1($_POST['password'] . $salt),
]
)->fetch();

if ($info['email']) {
$_SESSION['user']->email = $info['email'];
$_SESSION['user']->expire_timestamp = $info['expire_timestamp'];
$_SESSION['user']->updatePwd = $info['updatePwd'];
if ($info['updatePwd'] == 1) {
header("Location: /login.php");
die();
} else {
header("Location: .");
die();
}
} else {
echo "Incorrect username or password.";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

}
}

if ($_SESSION['user']->updatePwd == 1) {
?>
Please change your password.
<form action='' method='POST'>
<table>
<tr>
<th>New password</th><td><input type="password" name="password" required></td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

</tr>
<tr>
<th>Confirm password</th><td><input type="password" name="repassword" required></td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

</tr>
<tr>
<td><input type="submit" name="submit_updatePwd"></td><td></td>
</tr>
</table>
</form>
<?php
} else {
?>
<form action='' method='POST'>
<table>
<tr>
<th>E-mail</th><td><input type="text" name="email" required></td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

</tr>
<tr>
<th>Password</th><td><input type="password" name="password" required></td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

</tr>
<tr>
<td><input type="submit" name="submit_login"></td><td></td>
</tr>
</table>
</form>
<?php
}
} else {
header("Location: .");
}
?>
7 changes: 7 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
session_start();
unset($_SESSION);
session_destroy();
session_write_close();
header('Location: .');
die;
68 changes: 63 additions & 5 deletions pre-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function pokemonFilterImages($noPokemonNumbers)
$i = -1;
$z = $z + 48.25;
}
$i++;
$i;
}
echo '</div>';
}
Expand All @@ -92,7 +92,7 @@ function pokemonFilterImages($noPokemonNumbers)
if ($gAnalyticsId != "") {
echo '<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=new Date;
ga("create", "' . $gAnalyticsId . '", "auto");
ga("send", "pageview");
</script>
Expand All @@ -109,10 +109,10 @@ function pokemonFilterImages($noPokemonNumbers)
_paq.push(["enableLinkTracking"]);
(function() {
var u="//' . $piwikUrl . '/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setTrackerUrl", u"piwik.php"]);
_paq.push(["setSiteId", "' . $piwikSiteId . '"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
g.type="text/javascript"; g.async=true; g.defer=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
g.type="text/javascript"; g.async=true; g.defer=true; g.src=u"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->';
Expand Down Expand Up @@ -153,6 +153,35 @@ function pokemonFilterImages($noPokemonNumbers)
<div id="currentWeather"></div>
<?php
} ?>

<?php
if ($enableLogin === true) {
if ($_SESSION['user']->email) {
$info = $db->query(
"SELECT expire_timestamp, updatePwd FROM users WHERE email = :email", [
":email" => $_SESSION['user']->email,
]
)->fetch();

$_SESSION['user']->expire_timestamp = $info['expire_timestamp'];
$_SESSION['user']->updatePwd = $info['updatePwd'];

if ($info['updatePwd'] == 1) {
header("Location: /login.php");
}

$time = date("m-d", $_SESSION['user']->expire_timestamp);

if ($info['expire_timestamp'] > time()) {
echo "<span style='color: green;'>{$time}</span>";
} else {
echo "<span style='color: red;'>{$time}</span>";
}
} else {
echo "<a href='/login.php'>Login</a>";
}
}
?>
<a href="#stats" id="statsToggle" class="statsNav" style="float: right;"><span
class="label"><?php echo i8ln('Stats') ?></span></a>
</header>
Expand Down Expand Up @@ -815,7 +844,7 @@ class="onoffswitch-checkbox"/>
$count = sizeof($areas);
if ($count > 0) {
echo '<div class="form-control switch-container area-container"><ul>';
for ($i = 0; $i <= $count - 1; $i++) {
for ($i = 0; $i <= $count - 1; $i) {
echo '<li><a href="" data-lat="' . $areas[$i][0] . '" data-lng="' . $areas[$i][1] . '" data-zoom="' . $areas[$i][2] . '" class="area-go-to">' . $areas[$i][3] . '</a></li>';
}
echo '</ul></div>';
Expand Down Expand Up @@ -848,6 +877,35 @@ class="onoffswitch-checkbox"/>
</button>
</center>
</div>
<?php
if ($enableLogin === true && $_SESSION['user']->email) {
?>
<div>
<center>
<button class="settings"
onclick="document.location.href='logout.php'">
<i class="fa" aria-hidden="true"></i> Logout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

</button>
</center>
</div><br>
<div>
<center>
<p>
<?php
$time = date("Y-m-d", $_SESSION['user']->expire_timestamp);

echo $_SESSION['user']->email . "<br>";
if ($_SESSION['user']->expire_timestamp > time()) {
echo "<span style='color: green;'>Account expires on {$time}</span>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

} else {
echo "<span style='color: green;'>Account expired on {$time}</span>";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be translatable

} ?>
</p>
</center>
</div>
<?php
}
?>
</nav>
<nav id="stats">
<div class="switch-container">
Expand Down
48 changes: 32 additions & 16 deletions static/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Global map.js variables
//

var donator

var $selectExclude
var $selectExcludeMinIV
var $selectPokemonNotify
Expand Down Expand Up @@ -526,28 +528,35 @@ function pokemonLabel(item) {

var details = ''
if (atk != null && def != null && sta != null) {
var iv = getIv(atk, def, sta)
details =
'<div>' +
'IV: ' + iv.toFixed(1) + '% (' + atk + '/' + def + '/' + sta + ')' +
'</div>'
if (donator.enableLogin === false || (donator.isLoggedIn === true && (donator.current_timestamp < donator.user.expire_timestamp))) {
var iv = getIv(atk, def, sta)
details =
'<div>' +
'IV: ' + iv.toFixed(1) + '% (' + atk + '/' + def + '/' + sta + ')' +
'</div>'

if (cp != null && (cpMultiplier != null || level != null)) {
var pokemonLevel
if (level != null) {
pokemonLevel = level
} else {
pokemonLevel = getPokemonLevel(cpMultiplier)
if (cp != null && (cpMultiplier != null || level != null)) {
var pokemonLevel
if (level != null) {
pokemonLevel = level
} else {
pokemonLevel = getPokemonLevel(cpMultiplier)
}
details +=
'<div>' +
i8ln('CP') + ' : ' + cp + ' | ' + i8ln('Level') + ' : ' + pokemonLevel +
'</div>'
}
details +=
'<div>' +
i8ln('CP') + ' : ' + cp + ' | ' + i8ln('Level') + ' : ' + pokemonLevel +
i8ln('Moves') + ' : ' + pMove1 + ' / ' + pMove2 +
'</div>'
} else {
details +=
'<div>' +
'Sorry, IV stats is a donator only feature.' +
'</div>'
}
details +=
'<div>' +
i8ln('Moves') + ' : ' + pMove1 + ' / ' + pMove2 +
'</div>'
}
if (weatherBoostedCondition !== 0) {
details +=
Expand Down Expand Up @@ -2716,6 +2725,13 @@ $(function () {
}
})

$(function () {
$.ajax('/checklogin.php', {success: function (json) {
donator = json
},
dataType: 'json'})
})

$(function () {
// populate Navbar Style menu
$selectStyle = $('#map-style')
Expand Down
Loading