Mercurial > hg > fapweb
changeset 110:ff511f5351df
Work on voting.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 21 Oct 2013 22:48:55 +0300 |
parents | 9a3f0ba4d72b |
children | ac1df74619cd |
files | loginerror.inc.php usrlogin.php vote.inc.php |
diffstat | 3 files changed, 75 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loginerror.inc.php Mon Oct 21 22:48:55 2013 +0300 @@ -0,0 +1,4 @@ +<h1>Voting system login failed</h1> +<p> +The vote key was not valid. <a href="vote">Try again</a>. +</p>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usrlogin.php Mon Oct 21 22:48:55 2013 +0300 @@ -0,0 +1,38 @@ +<? +$sessionType = "user"; +require "mconfig.inc.php"; +require "msite.inc.php"; +require "msession.inc.php"; + +stSetupCacheControl(); + +// Initiate SQL database connection +if (!stConnectSQLDB()) + die("Could not connect to SQL database."); + +// Fetch non-"hardcoded" settings from SQL database +stReloadSettings(); + + +$gotoPage = stGetRequestItem("goto", FALSE); +$password = stGetRequestItem("key", FALSE); + +$sql = stPrepareSQL("SELECT id FROM votekeys WHERE key=%s", $password); +if (($votekey_id = stFetchSQLColumn($sql)) !== false) +{ + if (!stSessionStart(SESS_USER, $votekey_id, "userTimeout")) + { + error_log("User session AUTH LOGIN failed (session setup)"); + $gotoPage = "loginerror"; + } + else + stSetSessionItem("mode", stGetRequestItem("mode", "error")); +} +else +{ + error_log("User session AUTH LOGIN failed (password)"); + $gotoPage = "loginerror"; +} + +header("Location: ".($gotoPage !== FALSE ? $gotoPage : "news")); +?> \ No newline at end of file
--- a/vote.inc.php Mon Oct 21 22:48:27 2013 +0300 +++ b/vote.inc.php Mon Oct 21 22:48:55 2013 +0300 @@ -2,41 +2,47 @@ $sessionType = "user"; $userKeyLen = stGetSetting("userKeyLength"); + +function stGetVoteButton() +{ + return + "<div class=\"votectrl\">". + stGetFormSubmitInput("vote", "Submit votes!", "return false"). + "</div>\n"; +} + // Check if voting is enabled if (!stChkSetting("allowVoting")) { echo "<h1>Sorry, voting disabled!</h1>\n". "<p>Voting functionality not available at this time.</p>\n"; - - $status = -1; } else -if (stUserSessionAuth()) +if (!stUserSessionAuth(FALSE)) { - $status = stGetSessionItem("status"); - stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system"); -} else - $status = 0; - - -if ($status == 0) -{ + // Perform authentication if we are not in session already echo - "<h1>Voting system</h1>\n". - stGetFormStart("vote", "usrlogin.php"). - " ".stGetFormHiddenInput("mode", "key")."\n". - " ".stGetFormHiddenInput("goto", "vote")."\n". - " <div class=\"votectrl\">\n". - " Enter your vote key:\n". - " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n". - " ".stGetFormSubmitInput("login", "Login")."\n". - " </div>\n". - "</form>\n"; + "<h1>Voting system</h1>\n". + (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : ""). + stGetFormStart("vote", "usrlogin.php"). + " ".stGetFormHiddenInput("mode", "vote")."\n". + " ".stGetFormHiddenInput("goto", "vote")."\n". + " <div class=\"votectrl\">\n". + " Enter your vote key:\n". + " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\"")."\n". + " ".stGetFormSubmitInput("login", "Login")."\n". + " </div>\n". + "</form>\n"; } else -if ($status == 1) +if (($mode = stGetSessionItem("mode")) == "vote") { +?> +<script type="text/javascript"> +// <? include "ajax.js"; ?> +</script> +<? stGetCompoList(TRUE, TRUE); // Try fetching previously stored votes @@ -55,11 +61,11 @@ // Output voting system HTML echo "<h1>Voting system</h1>\n". - stGetFormStart("vote", "vsubmit.php"). + stGetFormStart("vote", "usrvote.php"). " ".stGetFormHiddenInput("mode", "vote")."\n". " ".stGetFormHiddenInput("goto", "vote")."\n". " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". - " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n"; + stGetVoteButton(); foreach ($compos as $id => $compo) if (count($compo["entries"]) > 0) @@ -109,15 +115,15 @@ } echo - " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n". + stGetVoteButton(). "</form>\n"; } else -if ($status == 2) +if ($mode == "done") { // Voting finished echo "<h1>Yay, you have voted!</h1>\n". "<p>Now go FAP some more! And make a demo about it.</p>"; stSessionEnd(SESS_USER); } -?> \ No newline at end of file +?> \ No newline at end of file