Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SurvTech-Public
extendRemoteControl
Commits
e4d145de
Commit
e4d145de
authored
Apr 16, 2021
by
Ulbrich, Christopher
Browse files
Added add_user and set_site_settings functions
parent
980a6400
Changes
1
Hide whitespace changes
Inline
Side-by-side
RemoteControlHandler.php
View file @
e4d145de
...
...
@@ -88,4 +88,95 @@ class RemoteControlHandler extends remotecontrol_handle
'permission'
=>
\
Permission
::
model
()
->
hasSurveyPermission
(
$iSurveyID
,
$sPermission
,
$sCRUD
),
);
}
/**
* Set a global setting
*
* Function to change site settings. Can only be used by super administrators.
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sSetttingName Name of the setting to set
* @param string $sValue Value of the setting to set
* @return string|array The requested value or an array with the error in case of error
*/
public
function
set_site_settings
(
$sSessionKey
,
$sSetttingName
,
$sValue
)
{
if
(
$this
->
_checkSessionKey
(
$sSessionKey
))
{
if
(
Permission
::
model
()
->
hasGlobalPermission
(
'superadmin'
,
'read'
))
{
$sSetttingName
=
(
string
)
$sSetttingName
;
$sValue
=
(
string
)
$sValue
;
if
(
Yii
::
app
()
->
getConfig
(
$sSetttingName
)
!==
false
)
{
return
SettingGlobal
::
setSetting
(
$sSetttingName
,
$sValue
);
}
else
{
return
array
(
'status'
=>
'Invalid setting'
);
}
}
else
{
return
array
(
'status'
=>
'Permission denied'
);
}
}
else
{
return
array
(
'status'
=>
'Invalid session key'
);
}
}
/**
* Create User
*
* Function to ad new survey administrator. Can only be used by administrator having user create permission
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sUserName name of the new survey administrator
* @param string $sFullName Full name of the new survey administrator
* @param string $sUserMail Mail address of the new survey administrator
* @param string $bIsSuperadmin Make the new survey administrator a Superadministrator
* @return string|array The requested value or an array with the error in case of error
*/
public
function
add_user
(
$sSessionKey
,
$sUserName
,
$sFullName
,
$sUserMail
,
$bIsSuperadmin
=
false
)
{
if
(
$this
->
_checkSessionKey
(
$sSessionKey
))
{
if
(
Permission
::
model
()
->
hasGlobalPermission
(
'users'
,
'create'
))
{
if
(
$bIsSuperadmin
&&
!
Permission
::
model
()
->
hasGlobalPermission
(
'superadmin'
,
'create'
)){
return
array
(
'status'
=>
'Permission to create superadmin denied'
);
}
else
{
$sFullName
=
(
string
)
$sFullName
;
$sUserMail
=
(
string
)
$sUserMail
;
$new_user
=
flattenText
((
string
)
$sUserName
,
false
,
true
);
if
(
empty
(
$new_user
))
{
return
array
(
'status'
=>
'Error: A username was not supplied or the username is invalid.'
);
}
elseif
(
User
::
model
()
->
find
(
"users_name=:users_name"
,
array
(
':users_name'
=>
$new_user
)))
{
return
array
(
'status'
=>
'Error: The username already exists.'
);
}
else
{
// Set parent ID if if could be read. Set it to 1 as a fallback
$parentID
=
1
;
if
(
isset
(
Yii
::
app
()
->
session
[
'loginID'
]))
{
$parentID
=
Yii
::
app
()
->
session
[
'loginID'
];
}
// actual create new user
$iNewUID
=
User
::
model
()
->
insertUser
(
$new_user
,
createPassword
(),
$sFullName
,
$parentID
,
$sUserMail
);
if
(
!
$iNewUID
)
{
return
array
(
'status'
=>
'Error: Failed to add user.'
);
}
// grant default permissions
Permission
::
model
()
->
setGlobalPermission
(
$iNewUID
,
'auth_ldap'
);
Permission
::
model
()
->
setGlobalPermission
(
$iNewUID
,
'surveys'
,
array
(
'create_p'
));
// grant superadmin permission if specified and allowed
if
(
$bIsSuperadmin
&&
Permission
::
model
()
->
hasGlobalPermission
(
'superadmin'
,
'create'
)){
Permission
::
model
()
->
setGlobalPermission
(
$iNewUID
,
'superadmin'
,
array
(
'read_p'
,
'create_p'
));
}
return
$iNewUID
;
}
}
}
else
{
return
array
(
'status'
=>
'Permission to create user denied'
);
}
}
else
{
return
array
(
'status'
=>
'Invalid session key'
);
}
}
// what is function flattenText() used in useraction.php:102 ???
// How can we set parameters for the createPassword() function?
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment