summaryrefslogtreecommitdiffstats
path: root/inc/user.inc.php
blob: f10a4f650b65e764e99618db9d74bbc18a89f483 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

require_once('inc/session.inc.php');

class User
{
	private static $user = false;

	public static function isLoggedIn()
	{
		return self::$user !== false;
	}

	public static function getName()
	{
		if (self::$user === false) return false;
		return self::$user['name'];
	}

	public static function load()
	{
		if (Session::loadSession()) {
			self::$user['name'] = 'Hans';
			return true;
		}
		return false;
	}

	public static function login($user, $pass)
	{
		if ($user == 'test' && $pass == 'test') {
			Session::createSession();;
			Session::set('uid', 1);
			Session::set('token', md5(rand() . time() . rand() . $_SERVER['REMOTE_ADDR'] . rand() . $_SERVER['REMOTE_PORT'] . rand() . $_SERVER['HTTP_USER_AGENT']));
			Session::save();
			return true;
		}
		return false;
	}

	public static function logout()
	{
		Session::delete();
		Header('Location: ?do=main&fromlogout');
		exit(0);
	}

}