summaryrefslogtreecommitdiff
path: root/utils/modules/user.php
blob: bd1ce37321b8a0f5d472c60789ac8e244b2a6548 (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
60
61
62
63
<?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) return;
      if($vars['oldpwd'] != "" &&
         $vars['newpwd'] != "" &&
         $vars['rptpwd'] != "") {
        if($user->setPassword($vars['oldpwd'], $vars['newpwd'], $vars['rptpwd']) == 0) {
          $this->users->write();
        }
      }

    default:
			$form = new Form("set");
			$form->addWidget(new LineEditPwd("Old password:", "oldpwd", ""));
			$form->addWidget(new LineEditPwd("New password:", "newpwd", ""));	
			$form->addWidget(new LineEditPwd("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");
}

?>