| 1 |
<?php
|
| 2 |
// $Id:$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Wrapper for user_save(). Handles new account creation and
|
| 6 |
* hashed passwords.
|
| 7 |
*
|
| 8 |
* @param object $account
|
| 9 |
* User account to be saved, null if a new user is being added.
|
| 10 |
* @param array $array
|
| 11 |
* User edit array like for user_save().
|
| 12 |
* @param bool $hashed_pass
|
| 13 |
* Indicates whether $account['pass'] is hashed or not.
|
| 14 |
*
|
| 15 |
* required keys/properties for user $array
|
| 16 |
* name
|
| 17 |
* mail
|
| 18 |
* pass (if still hashed, set hashed_pass = TRUE)
|
| 19 |
*/
|
| 20 |
function mtk_user_save($account = NULL, $array, $hashed_pass = TRUE) {
|
| 21 |
if ($hashed_pass) {
|
| 22 |
$hashed_pass = $account['pass'];
|
| 23 |
}
|
| 24 |
if (!$account) {
|
| 25 |
$account = new stdClass();
|
| 26 |
}
|
| 27 |
if($user = user_save($account, $array, 'account')) {
|
| 28 |
if ($hashed_pass) {
|
| 29 |
db_query("UPDATE {user} SET pass = '%s'", $hashed_pass);
|
| 30 |
}
|
| 31 |
return $user;
|
| 32 |
}
|
| 33 |
else {
|
| 34 |
return FALSE;
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
*
|
| 40 |
* mtk_user_delete
|
| 41 |
*
|
| 42 |
* @param object or array $user
|
| 43 |
*
|
| 44 |
*/
|
| 45 |
function mtk_user_delete($user) {
|
| 46 |
if (is_object($user)) {
|
| 47 |
$user = (array)$user;
|
| 48 |
}
|
| 49 |
user_delete($user['uid'],$user);
|
| 50 |
}
|