FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-users.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2013 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: LGPL-2.1-only
6 */
7 
32 function add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility,
33  $agentList, $Folder, $default_bucketpool_fk='')
34 {
35  global $container;
36  $dbManager = $container->get('db.manager');
37 
38  if (empty($default_bucketpool_fk)) {
39  $default_bucketpool_fk = null;
40  }
41 
42  $dbManager->prepare($stmt='users.insert',$sql="INSERT INTO users
43  (user_name,user_desc,user_seed,user_pass,user_perm,user_email,
44  email_notify,upload_visibility,user_agent_list,root_folder_fk,default_folder_fk) VALUES ($1,$2,$3,$4,$5,$6, $7,$8,$9,$10,$11)");
45  $dbManager->execute($stmt,array ($User,$Desc,'Seed',$Hash,$Perm,$Email, $Email_notify,$Upload_visibility,$agentList,$Folder,$Folder));
46 
47  /* Make sure it was added */
48  $row = $dbManager->getSingleRow("SELECT * FROM users WHERE user_name = $1",array($User),$stmt='users.get');
49  if (empty($row['user_name'])) {
50  $text = _("Failed to insert user.");
51  return ($text);
52  }
53 
54  /* The user was added, so create their group and make them the admin */
55  $user_name = $row['user_name'];
56  $user_pk = $row['user_pk'];
57  // Add user group
58  $dbManager->prepare($stmt='group.get', $sql = "select group_pk from groups where LOWER(group_name)=LOWER($1)");
59  $verg = $dbManager->execute('group.get',array($user_name));
60  $GroupRow = $dbManager->fetchArray($verg);
61  if (false === $GroupRow) {
62  $dbManager->getSingleRow('insert into groups(group_name) values ($1)',
63  array($user_name));
64  $GroupRow = $dbManager->fetchArray(
65  $dbManager->execute('group.get', array($user_name)));
66  }
67 
68  $group_pk = $GroupRow['group_pk'];
69  // make user a member of their own group
70  $dbManager->getSingleRow($sql="insert into group_user_member (group_fk, user_fk, group_perm) values ($1,$2,$3)",
71  $param=array($group_pk, $user_pk, 1),$stmt='groupmember.insert');
72  // set active group = own group
73  $dbManager->prepare($stmt='users.update', $sql = "update users SET group_fk=$1, default_bucketpool_fk=$3 WHERE user_pk=$2");
74  $dbManager->execute($stmt,array($group_pk,$user_pk,$default_bucketpool_fk));
75  return ('');
76 }
77 
86 function update_password_hash($User, $Hash)
87 {
88  global $container;
89  $dbManager = $container->get('db.manager');
90 
91  // Check if user exist
92  $row = $dbManager->getSingleRow("SELECT * FROM users WHERE user_name = $1",array($User),$stmt='users.get');
93  if (empty($row['user_name'])) {
94  $text = _("User does not exist.");
95  return ($text);
96  }
97 
98  $dbManager->prepare($stmt = 'users.update_hash', $sql = "UPDATE users SET user_seed = $1, user_pass = $2 WHERE user_name = $3");
99  $dbManager->execute($stmt,array ('Seed', $Hash, $User));
100  return ('');
101 }
update_password_hash($User, $Hash)
Update user password hash.
add_user($User, $Desc, $Hash, $Perm, $Email, $Email_notify, $Upload_visibility, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.