Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
1fe5f5a2
Commit
1fe5f5a2
authored
14 years ago
by
Jakob Sack
Browse files
Options
Downloads
Patches
Plain Diff
Better documentation for OC_USER
parent
a70330e9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/User/backend.php
+48
-24
48 additions, 24 deletions
lib/User/backend.php
lib/User/database.php
+69
-32
69 additions, 32 deletions
lib/User/database.php
lib/log.php
+1
-1
1 addition, 1 deletion
lib/log.php
lib/user.php
+48
-22
48 additions, 22 deletions
lib/user.php
with
166 additions
and
79 deletions
lib/User/backend.php
+
48
−
24
View file @
1fe5f5a2
...
...
@@ -24,64 +24,88 @@
/**
* Base class for user management
*
* abstract base class for user management
*/
abstract
class
OC_USER_BACKEND
{
/**
* Try to create a new user
* @brief Create a new user
* @param $username The username of the user to create
* @param $password The password of the new user
* @returns true/false
*
* @param string $username The username of the user to create
* @param string $password The password of the new user
* Creates a new user
*/
public
static
function
createUser
(
$username
,
$password
){}
/**
* @brief Delete a new user
* @param $username The username of the user to delete
* @brief delete a user
* @param $uid The username of the user to delete
* @returns true/false
*
* Deletes a user
*/
public
static
function
deleteUser
(
$uid
){}
/**
* @brief Try to login a user
* @param $uid The username of the user to log in
* @param $password The password of the user
* @returns true/false
*
* Log in a user - if the password is ok
*/
public
static
function
deleteUser
(
$username
){}
public
static
function
login
(
$uid
,
$password
){}
/**
* Try to login a user
* @brief Kick the user
* @returns true
*
* @param string $username The username of the user to log in
* @param string $password The password of the user
* Logout, destroys session
*/
public
static
function
log
in
(
$username
,
$password
){}
public
static
function
log
out
(
){}
/**
* Check if some user is logged in
* @brief Check if the user is logged in
* @returns true/false
*
* Checks if the user is logged in
*/
public
static
function
isLoggedIn
(){}
/**
* Generate a random password
* @brief Autogenerate a password
* @returns string
*
* generates a password
*/
public
static
function
generatePassword
(){}
/**
* Set the password of a user
* @brief Set password
* @param $uid The username
* @param $password The new password
* @returns true/false
*
* @param string $username User who password will be changed
* @param string $password The new password for the user
* Change the password of a user
*/
public
static
function
setPassword
(
$u
sername
,
$password
){}
public
static
function
setPassword
(
$u
id
,
$password
){}
/**
* Check if the password of the user is correct
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns true/false
*
* @param string $username Name of the user
* @param string $password Password of the user
* Check if the password is correct without logging in the user
*/
public
static
function
checkPassword
(
$username
,
$password
){}
public
static
function
checkPassword
(
$uid
,
$password
){}
/**
* get a list of all users
* @brief Get a list of all users
* @returns array with all uids
*
* Get a list of all users.
*/
public
static
function
getUsers
(){}
}
This diff is collapsed.
Click to expand it.
lib/User/database.php
+
69
−
32
View file @
1fe5f5a2
...
...
@@ -37,57 +37,70 @@ require_once('User/backend.php');
/**
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
*
*/
class
OC_USER_DATABASE
extends
OC_USER_BACKEND
{
static
private
$userGroupCache
=
array
();
/**
* Try to create a new user
* @brief Create a new user
* @param $username The username of the user to create
* @param $password The password of the new user
* @returns true/false
*
* @param string $username The username of the user to create
* @param string $password The password of the new user
* Creates a new user
*/
public
static
function
createUser
(
$uid
,
$password
){
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*users` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$uid
));
public
static
function
createUser
(
$username
,
$password
){
// Check if the user already exists
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*users` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$username
));
if
(
$result
->
numRows
()
>
0
){
return
false
;
}
else
{
$query
=
OC_DB
::
prepare
(
"INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )"
);
$result
=
$query
->
execute
(
array
(
$u
id
,
sha1
(
$password
)));
$result
=
$query
->
execute
(
array
(
$u
sername
,
sha1
(
$password
)));
return
$result
?
true
:
false
;
}
}
/**
* Try to delete a user
* @brief delete a user
* @param $uid The username of the user to delete
* @returns true/false
*
*
@param string $username The username of the user to delete
*
Deletes a user
*/
public
static
function
deleteUser
(
$uid
){
// Delete user
$query
=
OC_DB
::
prepare
(
"DELETE FROM `*PREFIX*users` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$uid
));
// Delete user-group-relation
$query
=
OC_DB
::
prepare
(
"DELETE FROM `*PREFIX*group_user` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$uid
));
return
true
;
}
/**
* Try to login a user
* @brief Try to login a user
* @param $uid The username of the user to log in
* @param $password The password of the user
* @returns true/false
*
* @param string $username The username of the user to log in
* @param string $password The password of the user
* Log in a user - if the password is ok
*/
public
static
function
login
(
$username
,
$password
){
public
static
function
login
(
$uid
,
$password
){
// Query
$query
=
OC_DB
::
prepare
(
"SELECT uid FROM *PREFIX*users WHERE uid = ? AND password = ?"
);
$result
=
$query
->
execute
(
array
(
$u
sername
,
sha1
(
$password
)));
$result
=
$query
->
execute
(
array
(
$u
id
,
sha1
(
$password
)));
if
(
$result
->
numRows
()
>
0
){
// Set username if name and password are known
$row
=
$result
->
fetchRow
();
$_SESSION
[
'user_id'
]
=
$row
[
"uid"
];
OC_LOG
::
add
(
"core"
,
$_SESSION
[
'user_id'
],
"login"
);
return
true
;
}
else
{
...
...
@@ -96,17 +109,23 @@ class OC_USER_DATABASE extends OC_USER_BACKEND {
}
/**
* Kick the user
* @brief Kick the user
* @returns true
*
* Logout, destroys session
*/
public
static
function
logout
(){
OC_LOG
::
add
(
"core"
,
$_SESSION
[
'user_id'
],
"logout"
);
$_SESSION
[
'user_id'
]
=
false
;
return
true
;
}
/**
* Check if the user is logged in
* @brief Check if the user is logged in
* @returns true/false
*
* Checks if the user is logged in
*/
public
static
function
isLoggedIn
()
{
if
(
isset
(
$_SESSION
[
'user_id'
])
AND
$_SESSION
[
'user_id'
]
){
...
...
@@ -118,34 +137,50 @@ class OC_USER_DATABASE extends OC_USER_BACKEND {
}
/**
* Generate a random password
* @brief Autogenerate a password
* @returns string
*
* generates a password
*/
public
static
function
generatePassword
(){
return
uniqId
();
}
/**
* Set the password of a user
* @brief Set password
* @param $uid The username
* @param $password The new password
* @returns true/false
*
* @param string $username User who password will be changed
* @param string $password The new password for the user
* Change the password of a user
*/
public
static
function
setPassword
(
$username
,
$password
){
public
static
function
setPassword
(
$uid
,
$password
){
// Check if the user already exists
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `*PREFIX*users` WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
$uid
));
if
(
$result
->
numRows
()
>
0
){
return
false
;
}
else
{
$query
=
OC_DB
::
prepare
(
"UPDATE *PREFIX*users SET password = ? WHERE uid = ?"
);
$result
=
$query
->
execute
(
array
(
sha1
(
$password
),
$u
sername
));
$result
=
$query
->
execute
(
array
(
sha1
(
$password
),
$u
id
));
return
true
;
}
}
/**
* Check if the password of the user is correct
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns true/false
*
* @param string $username Name of the user
* @param string $password Password of the user
* Check if the password is correct without logging in the user
*/
public
static
function
checkPassword
(
$u
sername
,
$password
){
public
static
function
checkPassword
(
$u
id
,
$password
){
$query
=
OC_DB
::
prepare
(
"SELECT uid FROM *PREFIX*users WHERE uid = ? AND password = ?"
);
$result
=
$query
->
execute
(
array
(
$u
sername
,
sha1
(
$password
)));
$result
=
$query
->
execute
(
array
(
$u
id
,
sha1
(
$password
)));
if
(
$result
->
numRows
()
>
0
){
return
true
;
...
...
@@ -156,8 +191,10 @@ class OC_USER_DATABASE extends OC_USER_BACKEND {
}
/**
* get a list of all users
* @brief Get a list of all users
* @returns array with all uids
*
* Get a list of all users.
*/
public
static
function
getUsers
(){
$query
=
OC_DB
::
prepare
(
"SELECT uid FROM *PREFIX*users"
);
...
...
This diff is collapsed.
Click to expand it.
lib/log.php
+
1
−
1
View file @
1fe5f5a2
...
...
@@ -50,7 +50,7 @@ class OC_LOG {
*
* This function adds another entry to the log database
*/
public
static
function
add
(
$subject
,
$predicate
,
$object
=
null
){
public
static
function
add
(
$appid
,
$subject
,
$predicate
,
$object
=
null
){
// TODO: write function
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
lib/user.php
+
48
−
22
View file @
1fe5f5a2
...
...
@@ -87,33 +87,45 @@ class OC_USER {
}
/**
* @brief Create
s
a new user
* @brief Create a new user
* @param $username The username of the user to create
* @param $password The password of the new user
* @returns true/false
*
* Creates a new user
*/
public
static
function
createUser
(
$username
,
$password
){
return
self
::
$_backend
->
createUser
(
$username
,
$password
);
}
/**
* @brief Delete a new user
* @param $username The username of the user to delete
* @brief delete a user
* @param $uid The username of the user to delete
* @returns true/false
*
* Deletes a user
*/
public
static
function
deleteUser
(
$u
sername
){
return
self
::
$_backend
->
deleteUser
(
$u
sername
);
public
static
function
deleteUser
(
$u
id
){
return
self
::
$_backend
->
deleteUser
(
$u
id
);
}
/**
* @brief
t
ry to login a user
* @param $u
sername
The username of the user to log in
* @brief
T
ry to login a user
* @param $u
id
The username of the user to log in
* @param $password The password of the user
* @returns true/false
*
* Log in a user - if the password is ok
*/
public
static
function
login
(
$u
sername
,
$password
){
return
self
::
$_backend
->
login
(
$u
sername
,
$password
);
public
static
function
login
(
$u
id
,
$password
){
return
self
::
$_backend
->
login
(
$u
id
,
$password
);
}
/**
* @brief Kick the user
* @returns true
*
* Logout, destroys session
*/
public
static
function
logout
(){
return
self
::
$_backend
->
logout
();
...
...
@@ -121,39 +133,53 @@ class OC_USER {
/**
* @brief Check if the user is logged in
* @returns true/false
*
* Checks if the user is logged in
*/
public
static
function
isLoggedIn
(){
return
self
::
$_backend
->
isLoggedIn
();
}
/**
* @brief Generate a random password
* @brief Autogenerate a password
* @returns string
*
* generates a password
*/
public
static
function
generatePassword
(){
return
substr
(
md5
(
uniqId
()
.
time
()),
0
,
10
);
}
/**
* @brief Set the password of a user
* @param $username User whose password will be changed
* @param $password The new password for the user
* @brief Set password
* @param $uid The username
* @param $password The new password
* @returns true/false
*
* Change the password of a user
*/
public
static
function
setPassword
(
$u
sername
,
$password
){
return
self
::
$_backend
->
setPassword
(
$u
sername
,
$password
);
public
static
function
setPassword
(
$u
id
,
$password
){
return
self
::
$_backend
->
setPassword
(
$u
id
,
$password
);
}
/**
* @brief Check if the password of the user is correct
* @param string $username Name of the user
* @param string $password Password of the user
* @brief Check if the password is correct
* @param $uid The username
* @param $password The password
* @returns true/false
*
* Check if the password is correct without logging in the user
*/
public
static
function
checkPassword
(
$u
sername
,
$password
){
return
self
::
$_backend
->
checkPassword
(
$u
sername
,
$password
);
public
static
function
checkPassword
(
$u
id
,
$password
){
return
self
::
$_backend
->
checkPassword
(
$u
id
,
$password
);
}
/**
* @brief get a list of all users
* @returns array with uids
* @brief Get a list of all users
* @returns array with all uids
*
* Get a list of all users.
*/
public
static
function
getUsers
(){
return
self
::
$_backend
->
getUsers
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment