on api-key reset also log the username

main
Felix Favre 10 years ago
parent bc6aa9a209
commit 5b3d0d302f

@ -39,14 +39,14 @@ function User_sortable_columns() {
'Aktiv', 'Aktiv',
'force_active', 'force_active',
'Tshirt', 'Tshirt',
'lastLogIn' 'lastLogIn'
); );
} }
/** /**
* Get all users, ordered by Nick by default or by given param. * Get all users, ordered by Nick by default or by given param.
* *
* @param string $order_by * @param string $order_by
*/ */
function Users($order_by = 'Nick') { function Users($order_by = 'Nick') {
return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC"); return sql_select("SELECT * FROM `User` ORDER BY `" . sql_escape($order_by) . "` ASC");
@ -55,23 +55,23 @@ function Users($order_by = 'Nick') {
/** /**
* Returns true if user is freeloader * Returns true if user is freeloader
* *
* @param User $user * @param User $user
*/ */
function User_is_freeloader($user) { function User_is_freeloader($user) {
global $max_freeloadable_shifts, $user; global $max_freeloadable_shifts, $user;
return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts; return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts;
} }
/** /**
* Returns all users that are not member of given angeltype. * Returns all users that are not member of given angeltype.
* *
* @param Angeltype $angeltype * @param Angeltype $angeltype
*/ */
function Users_by_angeltype_inverted($angeltype) { function Users_by_angeltype_inverted($angeltype) {
return sql_select(" return sql_select("
SELECT `User`.* SELECT `User`.*
FROM `User` FROM `User`
LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`=" . sql_escape($angeltype['id']) . ") LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`=" . sql_escape($angeltype['id']) . ")
WHERE `UserAngelTypes`.`id` IS NULL WHERE `UserAngelTypes`.`id` IS NULL
ORDER BY `Nick`"); ORDER BY `Nick`");
@ -80,13 +80,13 @@ function Users_by_angeltype_inverted($angeltype) {
/** /**
* Returns all members of given angeltype. * Returns all members of given angeltype.
* *
* @param Angeltype $angeltype * @param Angeltype $angeltype
*/ */
function Users_by_angeltype($angeltype) { function Users_by_angeltype($angeltype) {
return sql_select(" return sql_select("
SELECT SELECT
`User`.*, `User`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`confirm_user_id`,
`UserAngelTypes`.`coordinator` `UserAngelTypes`.`coordinator`
FROM `User` FROM `User`
@ -105,7 +105,7 @@ function User_ids() {
/** /**
* Strip unwanted characters from a users nick. * Strip unwanted characters from a users nick.
* *
* @param string $nick * @param string $nick
*/ */
function User_validate_Nick($nick) { function User_validate_Nick($nick) {
return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick); return preg_replace("/([^a-z0-9üöäß. _+*-]{1,})/ui", '', $nick);
@ -114,7 +114,7 @@ function User_validate_Nick($nick) {
/** /**
* Returns user by id. * Returns user by id.
* *
* @param $id UID * @param $id UID
*/ */
function User($id) { function User($id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1"); $user_source = sql_select("SELECT * FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1");
@ -129,7 +129,7 @@ function User($id) {
* TODO: Merge into normal user function * TODO: Merge into normal user function
* Returns user by id (limit informations. * Returns user by id (limit informations.
* *
* @param $id UID * @param $id UID
*/ */
function mUser_Limit($id) { function mUser_Limit($id) {
$user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber`, `Avatar` FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1"); $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber`, `Avatar` FROM `User` WHERE `UID`=" . sql_escape($id) . " LIMIT 1");
@ -159,7 +159,7 @@ function User_by_api_key($api_key) {
/** /**
* Returns User by email. * Returns User by email.
* *
* @param string $email * @param string $email
* @return Matching user, null or false on error * @return Matching user, null or false on error
*/ */
function User_by_email($email) { function User_by_email($email) {
@ -174,7 +174,7 @@ function User_by_email($email) {
/** /**
* Returns User by password token. * Returns User by password token.
* *
* @param string $token * @param string $token
* @return Matching user, null or false on error * @return Matching user, null or false on error
*/ */
function User_by_password_recovery_token($token) { function User_by_password_recovery_token($token) {
@ -189,20 +189,20 @@ function User_by_password_recovery_token($token) {
/** /**
* Generates a new api key for given user. * Generates a new api key for given user.
* *
* @param User $user * @param User $user
*/ */
function User_reset_api_key(&$user) { function User_reset_api_key(&$user) {
$user['api_key'] = md5($user['Nick'] . time() . rand()); $user['api_key'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1"); $result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
if ($result === false) if ($result === false)
return false; return false;
engelsystem_log("API key resetted."); engelsystem_log(sprintf("API key resetted (%s).",User_Nick_render($user)));
} }
/** /**
* Generates a new password recovery token for given user. * Generates a new password recovery token for given user.
* *
* @param User $user * @param User $user
*/ */
function User_generate_password_recovery_token(&$user) { function User_generate_password_recovery_token(&$user) {
$user['password_recovery_token'] = md5($user['Nick'] . time() . rand()); $user['password_recovery_token'] = md5($user['Nick'] . time() . rand());

Loading…
Cancel
Save