Updates to User-module
[AOOS.git] / modules / User / User.php
blobc72988f78e9da73419c29bd7e0825e6a9a312d8d
1 <?php
3 class User extends AOOSModule
5 private $_accesLevel = null;
6 private $_levels = array(
7 "guest" => 1,
8 "user" => 2,
9 "moderator" => 4,
10 "admin" => 8
12 private $_groups = array();
14 private $_username = "Guest";
15 private $_password = null;
16 private $_email = null;
18 private $_loggedIn = false;
20 public function show() {
21 if (!$this->loggedIn()) {
22 $r = $this->core()->getModule("Reciever");
23 if (!$r->getModel("POST")) {
24 print '
25 <form method="POST">
26 Brugernavn: <input type="text" name="USERNAME" /><br />
27 Kodeord: <input type="text" name="PASSWORD" /><br />
28 <input type="submit" value"Login">
29 </form>';
31 else {
32 require_once("UserHandler.php");
33 $handler = new UserHandler($this->core());
34 $m = $r->getModel("POST");
35 $handler->login(
36 array_pop($m->getColumn("USERNAME")),
37 array_pop($m->getColumn("PASSWORD"))
43 public function setUsername($username)
45 $this->_username = $username;
46 return true;
49 public function setPassword($password)
51 $this->_password = $password;
52 return true;
55 public function setEmail($email)
57 $this->_email = $email;
58 return true;
61 public function username() { return $this->_username; }
62 public function password() { return $this->_password; }
63 public function email() { return $this->_email; }
65 public function addToGroup($group) {
66 $this->_groups[] = $group;
67 return true;
70 public function setGroups($groups) {
71 $this->_groups = $groups;
72 return true;
75 public function checkGroup($group) {
76 if (!in_array($group, $this->_groups)) {
77 return false;
79 return true;
82 public function setLevel($level) {
83 $this->_accessLevel = $level;
84 return true;
87 public function checkLevel($level) {
88 if ($this->_levels[$level] > $this->_accessLevel) {
89 return false;
91 return true;
94 public function setLoggedIn($state) {
95 if (!is_bool($state)) {
96 throw new AOOSException($this->core(), $this->tr("not_bool"), "", true, 1);
97 return false;
99 $this->_loggedIn = $state;
102 public function loggedIn() {
103 return $this->_loggedIn;