5 * This is one of two parts of the User-module.
6 * The other part is the UserHandler-class defined in modules/User/UserHandler.php
7 * The reason for this structure is that it eases the handling of User-data.
8 * Other modules can copy this structure if it is useful in the particular module.
9 * This would mostly be modules that contains the same data for a long time.
11 * @TODO Should UserHandler be a module for it self?
14 class User
extends AOOSModule
16 private $_accesLevel = null;
17 private $_levels = array(
23 private $_groups = array();
25 private $_username = "Guest";
26 private $_password = null;
27 private $_email = null;
29 private $_loggedIn = false;
31 public function show() {
32 $r = $this->core()->getModule("Reciever");
33 $p = $this->core()->getModule("Paginator");
34 require_once("UserHandler.php");
35 $handler = new UserHandler($this->core());
37 if ($p->numOptions() > 0) {
38 switch (array_shift($p->options())) {
40 if (!$r->getModel("POST")) {
41 return '<form method="POST">
42 Brugernavn: <input type="text" name="USERNAME" /><br />
43 Kodeord: <input type="text" name="PASSWORD" /><br />
44 E-mail: <input type="text" name="EMAIL" /><br />
45 <input type="submit" value="Opret" />
49 $m = $r->getModel("POST");
50 if (!$handler->createUser($m)) {
51 return 'Creation failed!';
53 return 'User created';
57 if (!$r->getModel("POST")) {
58 return '<form method="POST">
59 Brugernavn: <input type="text" name="USERNAME" /><br />
60 Kodeord: <input type="text" name="PASSWORD" /><br />
61 <input type="submit" value="Aktiver" />
65 $m = $r->getModel("POST");
66 if (!$handler->activateUser($m)) {
67 return 'Activation failed!';
69 return 'User activated';
77 if (!$this->loggedIn()) {
78 if (!$r->getModel("POST")) {
81 Brugernavn: <input type="text" name="USERNAME" /><br />
82 Kodeord: <input type="text" name="PASSWORD" /><br />
83 <input type="submit" value="Login" /><a href="'.$p->createURL("User", array("create")).'">Opret</a>
87 $m = $r->getModel("POST");
88 if (!$handler->login($m)) {
89 return "Login failed!";
94 return "Logged in as ".$this->username();
98 public function setUsername($username)
100 $this->_username
= $username;
104 public function setPassword($password)
106 $this->_password
= $password;
110 public function setEmail($email)
112 $this->_email
= $email;
116 public function username() { return $this->_username
; }
117 public function password() { return $this->_password
; }
118 public function email() { return $this->_email
; }
120 public function addToGroup($group) {
121 $this->_groups
[] = $group;
125 public function setGroups($groups) {
126 $this->_groups
= $groups;
130 public function checkGroup($group) {
131 if (!in_array($group, $this->_groups
)) {
137 public function setLevel($level) {
138 $this->_accessLevel
= $level;
142 public function checkLevel($level) {
143 if ($this->_levels
[$level] > $this->_accessLevel
) {
149 public function setLoggedIn($state) {
150 if (!is_bool($state)) {
151 throw new AOOSException($this->core(), $this->tr("not_bool"), "", true, 1);
154 $this->_loggedIn
= $state;
157 public function loggedIn() {
158 return $this->_loggedIn
;