summaryrefslogtreecommitdiff
path: root/utils/modules/user.php
blob: 5e9c23b86dad8a8884c92b1c43cc7f8030097390 (plain)
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
50
51
52
53
54
55
56
57
58
59
<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

global $UTIL_DIR;

include_once($UTIL_DIR . "/user.php");

class UserAdm {
	public $users;

  // Admin config
  public $admin_title = "User";
  public $admin_submodules = array("Password" => "password");

  public function admin_password($action, $vars)
  {
    global $UID;

    switch($action) {
		case "set":
      $user = $this->users->findUser($UID);
      if($user &&
         $user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
        $this->users->write();
      }

    default:
			$form = new Form("set");
			$form->addWidget(new LineEdit("Old password:", "oldpwd", ""));
			$form->addWidget(new LineEdit("New password:", "newpwd", ""));	
			$form->addWidget(new LineEdit("Repeat password:", "rptpwd", ""));
      $form->addWidget(new Button("Update"));
			$form->render();
      break;
    }
  }

  public function admin($sub, $action, $vars)
  {
    switch($sub) {
    case "password":
      $this->admin_password($action, $vars);
      break;
    }
  }


	public function UserAdm($file)
	{
    $this->users = new Users($file);
	}
}

function user_init()
{
  global $DATA_DIR;
  return new UserAdm($DATA_DIR . "/users.xml");
}

?>