Skip to content

Commit

Permalink
added cat generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DerWaldschrat committed Jul 8, 2012
1 parent 89a4bfc commit 88267cf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
17 changes: 14 additions & 3 deletions User/login.php
Expand Up @@ -13,19 +13,30 @@
$db = db(); $db = db();
$oldPw = $userIn->passwort; $oldPw = $userIn->passwort;
$userIn->passwort = hashme($userIn->passwort, $userIn->nickname); $userIn->passwort = hashme($userIn->passwort, $userIn->nickname);
$st = $db->prepare("SELECT userid, email, vorname, nachname, passwort, profile, rights FROM " . USER . " WHERE nickname = ?"); $st = $db->prepare("SELECT userid, email, vorname, nachname, passwort, profile, cat, rights FROM " . USER . " WHERE nickname = ?");
$st->bind_param("s", $userIn->nickname); $st->bind_param("s", $userIn->nickname);
$user = new stdClass(); $user = new stdClass();
$st->bind_result($user->userid, $user->email, $user->vorname, $user->nachname, $user->passwort, $user->profile, $user->rights); $st->bind_result($user->userid, $user->email, $user->vorname, $user->nachname, $user->passwort, $user->profile, $user->cat, $user->rights);
if ($st->execute()) { if ($st->execute()) {
$st->store_result(); $st->store_result();
if ($st->num_rows === 1) { if ($st->num_rows === 1) {
$st->fetch(); $st->fetch();
if ($user->passwort === $userIn->passwort) { if ($user->passwort === $userIn->passwort) {
$user->nickname = $userIn->nickname; $user->nickname = $userIn->nickname;
$st->close(); $st->close();

// Create new cat
require IN . "random" . PHP_EX;
$cat = randomString(12);
$st = $db->prepare("UPDATE " . USER . " SET cat = ? WHERE nickname = ?");
$st->bind_param("ss", $cat, $user->nickname);
if (exQuery($st)) {
$user->cat = $cat;
}


$_SESSTION["user"] = array(); $_SESSTION["user"] = array();
$toSet = array("userid", "email", "vorname", "nachname", "profile", "rights"); $toSet = array("userid", "email", "vorname", "nachname", "profile", "cat", "rights");
foreach($toSet as $field) { foreach($toSet as $field) {
$_SESSION["user"][$field] = $user->$field; $_SESSION["user"][$field] = $user->$field;
} }
Expand Down
4 changes: 0 additions & 4 deletions design/index.php
Expand Up @@ -22,10 +22,6 @@
require IN . "coreconfig" . PHP_EX; require IN . "coreconfig" . PHP_EX;
require IN . "User/fetchData" . PHP_EX; require IN . "User/fetchData" . PHP_EX;
$user = new stdClass(); $user = new stdClass();
$toSet = array("userid", "email", "vorname", "nachname", "loggedin");
foreach($toSet as $field) {
$user->$field = $_SESSION["user"][$field];
}
$user = (object)$_SESSION["user"]; $user = (object)$_SESSION["user"];
fetchUserData($user); fetchUserData($user);
echo "window.__User = " . json_encode($user).";"; echo "window.__User = " . json_encode($user).";";
Expand Down
4 changes: 0 additions & 4 deletions design/index.production.php
Expand Up @@ -33,10 +33,6 @@
require IN . "coreconfig" . PHP_EX; require IN . "coreconfig" . PHP_EX;
require IN . "User/fetchData" . PHP_EX; require IN . "User/fetchData" . PHP_EX;
$user = new stdClass(); $user = new stdClass();
$toSet = array("userid", "email", "vorname", "nachname", "loggedin");
foreach($toSet as $field) {
$user->$field = $_SESSION["user"][$field];
}
$user = (object)$_SESSION["user"]; $user = (object)$_SESSION["user"];
fetchUserData($user); fetchUserData($user);
echo "window.__User = " . json_encode($user).";"; echo "window.__User = " . json_encode($user).";";
Expand Down
14 changes: 14 additions & 0 deletions random.php
@@ -0,0 +1,14 @@
<?php
function randomString($length = 8)
{
$signs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$result = "";
for ($i = 0; $i < $length; $i++) {
$result .= substr(str_shuffle($signs), 0, 1);
}
return $result;
}



?>

0 comments on commit 88267cf

Please sign in to comment.