Example #1
0
 /**
  * Get a user instance from a token
  * @param int $token
  * @return User|bool
  */
 static function GetByToken($token)
 {
     $db = new DB();
     $data = ["token" => $token];
     if ($user_id = $db->fetch("SELECT user_id FROM Token WHERE token = :token", $data)) {
         $user = User::Get($user_id);
         return $user;
     } else {
         return false;
     }
 }
Example #2
0
 public function __construct()
 {
     $this->Infos['Title'] = Language::Get('com.sbb.page.profile');
     // If logged in, redirect to start page
     if (!User::LoggedIn()) {
         header("Location: index.php");
     }
     $Message = '';
     if (isset($_POST['Submit'])) {
         if (User::CheckUpdate($_POST)) {
             User::Update(array('Homepage' => $_POST['Homepage'], 'Signatur' => $_POST['Signature']));
             $Message = Language::Get('com.sbb.profile.success');
         } else {
             $Message = '<b>' . Language::Get('com.sbb.error') . ':</b><ul><li>' . implode('</li><li>', Register::GetError()) . '</li></ul>';
         }
     }
     // Füllt die Variablen im TPL
     SBB::Template()->Assign(array('Homepage' => User::Get('Homepage'), 'Signature' => User::Get('Signatur'), 'Message' => $Message, 'Page' => 'Profile'));
 }
Example #3
0
 public function tryLoginUser($suppliedUserName, $suppliedPassword)
 {
     $valid = $this->checkIfUserSuppliedInput($suppliedUserName, $suppliedPassword);
     if ($valid != true) {
         $valid = false;
         return $valid;
     }
     $user = User::Get($this->suppliedUserName);
     if ($user != NULL && $user->comparePassword($this->suppliedPassword)) {
         if (!isset($_SESSION[self::$userLoginSession])) {
             $valid = true;
             $_SESSION[self::$userLoginSession] = true;
             $this->messageKey = FeedbackStrings::LOGINSUCCESS;
         }
     } else {
         $this->messageKey = FeedbackStrings::LOGINFAIL;
         $valid = false;
     }
     return $valid;
 }
Example #4
0
<?php

if (!defined('ADMIN')) {
    die("Access denied!");
}
$edit_user = new User();
if (isset($_GET['id']) && $edit_user->Load(array('id' => $_GET['id']))) {
    ?>
	<form class="ajaxform" method="POST" action="">
		<h2>Edit an user</h2>
		<div class="message-box"></div>
		Username:
		<input type="text" name="username" value="<?php 
    echo $edit_user->Get('username');
    ?>
"><br>
		Email:
		<input type="text" name="email" value="<?php 
    echo $edit_user->Get('email');
    ?>
"><br>
		User type:
		<select name="user_type">
			<option value="user" <?php 
    echo $edit_user->Get('user_type') == 'user' ? 'selected' : '';
    ?>
>user</option>
			<option value="admin" <?php 
    echo $edit_user->Get('user_type') == 'admin' ? 'selected' : '';
    ?>
>admin</option>
 public function ProjectUser(User $oUser)
 {
     if (is_array($this->m_aUserProjections)) {
         // Hit!
         return $this->m_aUserProjections;
     }
     $sExpr = $this->Get('value');
     if ($sExpr == '<user>') {
         $sColumn = $this->Get('attribute');
         if (empty($sColumn)) {
             $aRes = array($oUser->GetKey());
         } else {
             $aRes = array($oUser->Get($sColumn));
         }
     } elseif ($sExpr == '<any>' || $sExpr == '') {
         $aRes = null;
     } elseif (strtolower(substr($sExpr, 0, 6)) == 'select') {
         $sColumn = $this->Get('attribute');
         // SELECT...
         $oValueSetDef = new ValueSetObjects($sExpr, $sColumn, array(), true);
         $aRes = $oValueSetDef->GetValues(array('user' => $oUser), '');
     } else {
         // Constant value(s)
         $aRes = explode(';', trim($sExpr));
     }
     $this->m_aUserProjections = $aRes;
     return $aRes;
 }
 function do_updateUserMembers()
 {
     $old_search = KTUtil::arrayGet($_REQUEST, 'old_search');
     $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
     $oGroup = Group::get($group_id);
     if (PEAR::isError($oGroup) || $oGroup === false) {
         $this->errorRedirectToMain(_kt('No such group.'));
     }
     $userAdded = KTUtil::arrayGet($_REQUEST, 'users_items_added', '');
     $userRemoved = KTUtil::arrayGet($_REQUEST, 'users_items_removed', '');
     $aUserToAddIDs = explode(",", $userAdded);
     $aUserToRemoveIDs = explode(",", $userRemoved);
     $this->startTransaction();
     $usersAdded = array();
     $usersRemoved = array();
     $addWarnings = array();
     $removeWarnings = array();
     foreach ($aUserToAddIDs as $iUserId) {
         if ($iUserId > 0) {
             $oUser = User::Get($iUserId);
             $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup);
             //var_dump($memberReason);
             if (!(PEAR::isError($memberReason) || is_null($memberReason))) {
                 $addWarnings[] = $memberReason;
             }
             $res = $oGroup->addMember($oUser);
             if (PEAR::isError($res) || $res == false) {
                 $this->errorRedirectToMain(sprintf(_kt('Unable to add user "%s" to group "%s"'), $oUser->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search));
             } else {
                 $usersAdded[] = $oUser->getName();
             }
         }
     }
     // Remove groups
     foreach ($aUserToRemoveIDs as $iUserId) {
         if ($iUserId > 0) {
             $oUser = User::get($iUserId);
             $res = $oGroup->removeMember($oUser);
             if (PEAR::isError($res) || $res == false) {
                 $this->errorRedirectToMain(sprintf(_kt('Unable to remove user "%s" from group "%s"'), $oUser->getName(), $oGroup->getName()), sprintf("old_search=%s&do_search=1", $old_search));
             } else {
                 $usersRemoved[] = $oUser->getName();
                 $memberReason = GroupUtil::getMembershipReason($oUser, $oGroup);
                 //var_dump($memberReason);
                 if (!(PEAR::isError($memberReason) || is_null($memberReason))) {
                     $removeWarnings[] = $memberReason;
                 }
             }
         }
     }
     if (!empty($addWarnings)) {
         $sWarnStr = _kt('Warning:  some users were already members of some subgroups') . ' &mdash; ';
         $sWarnStr .= implode(', ', $addWarnings);
         $_SESSION['KTInfoMessage'][] = $sWarnStr;
     }
     if (!empty($removeWarnings)) {
         $sWarnStr = _kt('Warning:  some users are still members of some subgroups') . ' &mdash; ';
         $sWarnStr .= implode(', ', $removeWarnings);
         $_SESSION['KTInfoMessage'][] = $sWarnStr;
     }
     $msg = '';
     if (!empty($usersAdded)) {
         $msg .= ' ' . _kt('Added') . ': ' . implode(', ', $usersAdded) . '. ';
     }
     if (!empty($usersRemoved)) {
         $msg .= ' ' . _kt('Removed') . ': ' . implode(', ', $usersRemoved) . '.';
     }
     if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) {
         $this->rollbackTransaction();
         $this->errorRedirectTo('manageUsers', _kt('For security purposes, you cannot remove your own administration priviledges.'), sprintf('group_id=%d', $oGroup->getId()), sprintf("old_search=%s&do_search=1", $old_search));
         exit(0);
     }
     $this->commitTransaction();
     $this->successRedirectToMain($msg, sprintf("old_search=%s&do_search=1", $old_search));
 }
Example #7
0
 private static function TemplateAssign()
 {
     global $GeneratingTime;
     self::Template()->Assign(array('DIR_STYLE' => DIR_STYLE, 'DIR_JS' => DIR_JS, 'User' => User::Get(), 'Load' => '~Load: ' . round((microtime(true) - $GeneratingTime) * 1000, 2) . 'ms'));
     self::Template()->AssignLanguage(Language::Assign());
 }
<?php

include_once '../Models/User.php';
$user = User::Get();
my_print($user);
Example #9
0
                if (!Mail::send($email, $name, "Account created", $message)) {
                    throw new Exception("Error sending email", 500);
                }
                $app->render_json(["id" => $user_id]);
                // Create the user token for the first time
                Token::Update($user_id);
            } else {
                throw new Exception("Something went wrong!", 500);
            }
        }
    }
});
/* Delete User
 **********************************************************************************************************************/
$app->delete('/users/:id', function ($id) use($app) {
    if ($user = User::Get($id)) {
        // Set the user status to disabled instead of deleting it
        $user->setStatus('disabled');
        $app->render_json(["success" => true]);
    } else {
        throw new Exception("User not found", 404);
    }
});
/* Get stats by user
 **********************************************************************************************************************/
$app->get('/users/:id/stats', function ($id) use($app) {
    $stats = Stats::GetByUser($id);
    $app->render_json($stats);
});
/* Get all teams
 **********************************************************************************************************************/
Example #10
0
<?php

require dirname(__FILE__) . '/../../fx.php';
// Are we logged in?
if (strlen(User::cGet('id')) == 0 or strlen(User::cGet('oat')) == 0 or strlen(User::cGet('oats')) == 0) {
    Redirect('/account/signin');
}
$data = array();
$data['user'] = User::Get();
$data['services'] = User::GetServices($data['user']);
Layout('Your Account', 'account');
TPL('account/index', $data);
Example #11
0
function DisplayDefaultData()
{
    global $smarty;
    $session = new session();
    require_once 'objects/class.user.php';
    $user = new User();
    $user->Get($session->get('currentuserid'));
    $smarty->assign('currentuserid', $user->userId);
    $smarty->assign('currentusername', $user->username);
    $smarty->assign('currentfirst', $user->firstname);
    $smarty->assign('currentlast', $user->lastname);
}
Example #12
0
 static function Login($fields, $encrypted = false)
 {
     $username = $fields['username'];
     $password = $fields['password'];
     $validator = new Validate();
     $result = $validator->AddValue('usernameoremail', $username)->AddRule('required', true)->AddValue('password', $password)->AddRule('required', true)->Check();
     if (!$encrypted) {
         $password = Validate::Encrypt($password);
     }
     if ($result) {
         if (strpos($username, '@') !== false) {
             $type = "email";
         } else {
             $type = "username";
             $username = Validate::Escape($username);
         }
         $user = new User();
         $result = $user->Load(array($type => $username, 'password' => $password));
         if ($result) {
             if ($user->Get('activation_state') == '0') {
                 Error::Set("email", "notactivated");
             } else {
                 if (isset($fields['rememberme'])) {
                     Cookie::Set($username, $password);
                 }
                 Session::Set("current_user", $user);
                 return true;
             }
         } else {
             Error::Set("username", "usernotfound");
         }
     }
     return false;
 }
Example #13
0
 $userid = intval($_SESSION['user_id']);
 $the_comment = Utils::secure($_POST['comment']);
 $id = intval($_POST['id']);
 if (User::login_check(Query::$mysqli) == true) {
     $date = date("Y-m-d H:i:s");
     Query::query("INSERT INTO tbl_comments (user, comment, link_id, date, ip) VALUES ('{$userid}', '{$the_comment}', '{$id}', '{$date}', '{$_SERVER['REMOTE_ADDR']}')");
     $user_url = '';
     //'uploads/avatars/' . User::Get('id') . User::Get('AvatarType');//ProfileUrl($user2['id'], $user2['seo_url']);
     $content = stripslashes(nl2br(strip_tags($_POST['comment'])));
     $username = User::Get('Username');
     $report_button = '';
     $delete = '';
     if (User::Get('AvatarType') == '') {
         $avatar_url = '/uploads/avatars/default.png';
     } else {
         $avatar_url = 'uploads/avatars/' . User::Get('id') . User::Get('AvatarType');
     }
     //$this->set('user_avatar', 'uploads/avatars/' . User::Get('id') . User::Get('AvatarType'));
     include '../../../app/templates/sections/CommentsAJAX.tpl';
     //$comment = array('username' => $user2['username'], 'content' => stripslashes(nl2br(strip_tags($_POST['comment']))), 'user_points' => $user2['points'], 'date' => FormatDate($date, 'time'));
     //$comment['delete'] = '';
     //$seo_username = seoname($user2['username']);
     //$comment['user_url'] = ProfileUrl($user2['id'], $user2['seo_url']);
     //if ($user2['admin'] == 1) {
     //    $comment['delete'] = '<a href="#" onclick="DeleteNewsComment(' . mysql_insert_id() . ', ' . "'" . $setting['site_url'] . "'" . '); return false">Delete</a>';
     //    $comment['report_button'] = '<a href="' . $setting['site_url'] . '/admin/?task=manage_users#page=1&ip=' . $_SERVER['REMOTE_ADDR'] . '"><img src="' . $setting['site_url'] . '/images/report.png" title="' . $_SERVER['REMOTE_ADDR'] . '" style="vertical-align:middle;"/></a>';
     //} else {
     //    if ($setting['report_permissions'] == "1" || $setting['report_permissions'] == "2" && $user['login_status'] == 1) {
     //		$comment['report_button'] = '<a href="#" onclick="ShowPopup(\'ava-popup\', \'' . $setting['site_url'] . '/includes/forms/comment_report_form.php?id=' . mysql_insert_id() . '&type=2\', \'Report comment\'); return false"><img src="' . $setting['site_url'] . '/images/report.png" title="' . REPORT . '" style="vertical-align:middle;"/></a>';
     //    } else {
     //		$comment['report_button'] = '';
Example #14
0
 /**
  * Returns a sorted array of objects that match given conditions
  * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
  * @param string $sortBy 
  * @param boolean $ascending 
  * @param int limit 
  * @return array $userList
  */
 static function GetList($fcv_array, $sortBy = '', $ascending = true, $limit = '')
 {
     $sqlLimit = $limit != '' && $sortBy == '' ? "LIMIT {$limit}" : '';
     if (sizeof($fcv_array) > 0) {
         $userList = array();
         $Database = new DatabaseConnection();
         $pog_query = "select userid from `user` where ";
         for ($i = 0, $c = sizeof($fcv_array) - 1; $i < $c; $i++) {
             $pog_query .= "`" . $fcv_array[$i][0] . "` " . $fcv_array[$i][1] . " '" . $Database->Escape($fcv_array[$i][2]) . "' AND";
         }
         $pog_query .= "`" . $fcv_array[$i][0] . "` " . $fcv_array[$i][1] . " '" . $Database->Escape($fcv_array[$i][2]) . "' order by userid asc {$sqlLimit}";
         $Database->Query($pog_query);
         for ($i = 0; $i < $Database->Rows(); $i++) {
             $user = new User();
             $user->Get($Database->Result($i, "userid"));
             $userList[] = $user;
         }
         if ($sortBy != '') {
             $f = '';
             $user = new User();
             if (isset($user->pog_attribute_type[strtolower($sortBy)]) && $user->pog_attribute_type[strtolower($sortBy)][0] == "NUMERIC") {
                 $f = 'return $user1->' . $sortBy . ' > $user2->' . $sortBy . ';';
             } else {
                 if (isset($user->pog_attribute_type[strtolower($sortBy)])) {
                     $f = 'return strcmp(strtolower($user1->' . $sortBy . '), strtolower($user2->' . $sortBy . '));';
                 }
             }
             usort($userList, create_function('$user1, $user2', $f));
             if (!$ascending) {
                 $userList = array_reverse($userList);
             }
             if ($limit != '') {
                 $limitParts = explode(',', $limit);
                 if (sizeof($limitParts) > 1) {
                     return array_slice($userList, $limitParts[0], $limitParts[1]);
                 } else {
                     return array_slice($userList, 0, $limit);
                 }
             }
         }
         return $userList;
     }
     return null;
 }
Example #15
0
<?php

require dirname(__FILE__) . '/../../../fx.php';
// Are we logged in?
if (strlen(User::cGet('id')) == 0 or strlen(User::cGet('oat')) == 0 or strlen(User::cGet('oats')) == 0) {
    Redirect('/account/signin');
}
$data = array('user' => User::Get());
$follows = array('status' => 'active', 'email' => !empty($_POST['email']) ? trim($_POST['email']) : '', 'frequency' => 'daily', 'hour' => date('H'), 'when' => '', 'post_url' => '', 'post_format' => '');
$result = User::InstallService('follows', $data['user'], $follows);
if ($result === true) {
    Redirect('/account/follows/');
}
$data['message'] = 'Installation failed; ' . $result;
Layout('Follows', 'account');
TPL('account/follows/install', $data);
Example #16
0
 /**
  * Get all the comments from the match
  * @return array|bool
  */
 function getComments()
 {
     $db = new DB();
     $data = ['match_id' => $this->id];
     if ($comments = $db->fetch("SELECT id, user_id, text, created_at FROM UserComment WHERE match_id = :match_id AND deleted = 0", $data)) {
         foreach ($comments as &$comment) {
             $user = User::Get($comment['user_id']);
             $comment['user']['name'] = $user->name;
             $comment['user']['avatar'] = $user->avatar['small'];
         }
         return $comments;
     } else {
         return false;
     }
 }
Example #17
0
 /**
  * Set the bet result to won or lost
  * @param int $result
  */
 function setResult($result)
 {
     $db = new DB();
     $user = User::Get($this->user_id);
     $data = ['bet_id' => $this->id, 'result' => $result];
     $db->modify("UPDATE Bet SET result = :result WHERE id = :bet_id", $data);
 }
Example #18
0
				<h2>Logged as <?php 
        echo Session::Get('current_user')->Get('username');
        ?>
</h2>
				<a href="../user/settings.php">My Account</a>
				<a href="../auth/logout.php">Logout</a>
			<?php 
    } else {
        ?>
				<a href="../auth/login.php">Log in</a>
				<a href="../auth/signup.php">Sign up</a>
			<?php 
    }
    ?>
			<img src="<?php 
    echo $user->GetAvatar();
    ?>
" style="width:300px;"><br>
			<?php 
    echo $user->Get('username');
    ?>
<br>
			Joined : <?php 
    echo $user->Get('join_date');
    ?>
		<?php 
}
?>
	</body>
</html>
Example #19
0
     $success = User::AddUser($_POST);
     if (isset($_POST['emailpassword']) && $success) {
         Email::SendEmail($_POST['email'], 'New account', 'Admin created an account with your email; Your password is : ' . $_POST['password']);
     }
     $message = $success ? array(Config::Get('success.created')) : Error::GetAll();
     break;
 case 'admin_edit':
     $user = new User();
     $user->Load(array('id' => $_POST['user_id']));
     $user->ChangeSettings($_POST);
     $success = Error::HasErrors() ? false : true;
     if (!empty($_POST['password']) || !empty($_POST['cpassword'])) {
         $success = $success && $user->ChangePassword($_POST);
     }
     $message = $success ? array(Config::Get('success.saved')) : Error::GetAll();
     $data = array('email' => $user->Get('email'), 'username' => $user->Get('username'));
     break;
 case 'admin_delete':
     $user = new User();
     if ($user->Load(array('id' => $_POST['user_id']))) {
         $success = $user->Delete();
     } else {
         Error::Set('user', 'usernotfound');
     }
     $message = $success ? array(Config::Get('success.saved')) : Error::GetAll();
     break;
 case 'admin_compose':
     $validator = new Validate();
     $success = $validator->AddValue('email', $_POST['email'])->AddPattern('email')->Check();
     $success = $success && Email::SendEmail($_POST['email'], $_POST['subject'], $_POST['message']);
     $message = $success ? array(Config::Get('success.sent')) : Error::GetAll();
Example #20
0
<?php

if (!defined('ADMIN')) {
    die("Access denied!");
}
$compose_user = new User();
if (isset($_GET['id']) && $compose_user->Load(array('id' => $_GET['id']))) {
    $email = $compose_user->Get('email');
} else {
    $email = '';
}
?>
  	<form class="ajaxform" method="POST" action="">
 		<h2>Compose an email</h2>
		<div class="message-box"></div>
		To:
		<input type="text" name="email" value="<?php 
echo $email;
?>
"><br>
		Subject:
		<input type="text" name="subject"><br>
		Message:
		<textarea name="message"></textarea><br>
		<input type="hidden" name="action" value="admin_compose">
		<button type="submit" name="sendemail">SEND EMAIL</button>
	</form>
Example #21
0
 $team1_id = $match->progress[0]['team_id'];
 $team1_goals = $match->progress[0]['goals'];
 $team1_yellow_cards = $match->progress[0]['yellow_cards'];
 $team1_redcards = $match->progress[0]['redcards'];
 $team1_defenses = $match->progress[0]['defenses'];
 $team2_id = $match->progress[1]['team_id'];
 $team2_goals = $match->progress[1]['goals'];
 $team2_yellow_cards = $match->progress[1]['yellow_cards'];
 $team2_redcards = $match->progress[1]['redcards'];
 $team2_defenses = $match->progress[1]['defenses'];
 $team1_rank = 0;
 $team2_rank = 0;
 if ($bets = Bet::GetByMatch($match->id)) {
     foreach ($bets as $bet) {
         if ($bet->result == null) {
             $user = User::Get($bet->user_id);
             $result = null;
             // Simple bet
             if ($bet->type == 1) {
                 if ($team1_goals > $team2_goals) {
                     $result = 1;
                     $team1_rank += $bet->points_total;
                     $team2_rank -= $bet->points_total;
                 } elseif ($team1_goals == $team2_goals) {
                     $result = 0;
                 } elseif ($team1_goals > $team2_goals) {
                     $result = 2;
                     $team2_rank += $bet->points_total;
                     $team1_rank -= $bet->points_total;
                 }
                 if ($bet->team == $result) {
Example #22
0
<?php

require dirname(__FILE__) . '/../../../fx.php';
// Are we logged in?
if (strlen(User::cGet('id')) == 0 or strlen(User::cGet('oat')) == 0 or strlen(User::cGet('oats')) == 0) {
    Redirect('/account/signin');
}
$data = array('user' => User::Get(), 'message' => '&nbsp;');
if (!empty($_POST['save'])) {
    $pattern = '/^([a-z0-9\\+])(([-a-z0-9\\+._])*([a-z0-9\\+]))*\\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
    if (!preg_match($pattern, $_POST['email'])) {
        $data['message'] = '<span style="color:red;">Save failed: Invalid email address; please try again.</span>';
    } else {
        $replies = array();
        $replies['status'] = trim($_POST['status']) == 'active' ? 'active' : 'inactive';
        $replies['email'] = trim($_POST['email']);
        $replies['min_interval'] = intval($_POST['min_interval']) * 60;
        $replies['max_queued'] = intval($_POST['max_queued']);
        $replies['replies_only'] = empty($_POST['replies_only']) ? 0 : 1;
        $replies['ignore_self'] = empty($_POST['ignore_self']) ? 0 : 1;
        $result = User::UpdateService('replies', $data['user'], $replies);
        if ($result === true) {
            $data['message'] = 'Changes saved <strong>successfully</strong>';
        } else {
            $data['message'] = '<span style="color:red;">Save failed: ' . $result . '</span>';
        }
    }
}
$data['replies'] = User::GetServices($data['user'], 'replies');
Layout('Replies', 'account');
if ($data['replies'] === false) {
Example #23
0
        } else {
            if ($format == 'json') {
                header("Location: ?action=edit&format=json&id={$_REQUEST['id']}");
            } else {
                header("Location: ?sub_action={$sub_action}&id={$_REQUEST['id']}");
            }
            //header("Location: ?sub_action=$sub_action&id=$_REQUEST[id]");
        }
        break;
    case 'search_GET':
        $model = User::Search($_REQUEST['q']);
        $view = 'users/index.php';
        break;
    case 'index_GET':
    default:
        $model = User::Get();
        $view = 'users/index.php';
        break;
}
switch ($format) {
    case 'json':
        echo json_encode($model);
        break;
    case 'plain':
        include __DIR__ . "/../Views/{$view}";
        break;
    case 'web':
    default:
        include __DIR__ . "/../Views/shared/_Template.php";
        break;
}