mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 07:50:12 +01:00
Add delete token api
If someone lost token, then admin user should be can delete a user token.
This commit is contained in:
parent
60bc603399
commit
f304c3ad52
1 changed files with 49 additions and 0 deletions
|
|
@ -2474,6 +2474,55 @@ if (Meteor.isServer) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @operation delete_user_token
|
||||||
|
*
|
||||||
|
* @summary Delete one or all user token.
|
||||||
|
*
|
||||||
|
* @description Only the admin user (the first user) can call the REST API.
|
||||||
|
*
|
||||||
|
* @param {string} userId the user ID
|
||||||
|
* @param {string} token the user token
|
||||||
|
* @return_type {message: string}
|
||||||
|
*/
|
||||||
|
JsonRoutes.add('POST', '/api/deletetoken', function (req, res) {
|
||||||
|
try {
|
||||||
|
const { userId, token } = req.body;
|
||||||
|
Authentication.checkUserId(req.userId);
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
message: 'Expected a userId to be set but received none.',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (token && userId) {
|
||||||
|
Accounts.destroyToken(userId, token);
|
||||||
|
data.message = 'Delete token: [' + token + '] from user: ' + userId;
|
||||||
|
} else if (userId) {
|
||||||
|
Users.update(
|
||||||
|
{
|
||||||
|
_id: userId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
'services.resume.loginTokens': '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
data.message = 'Delete all token from user: ' + userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
JsonRoutes.sendResult(res, {
|
||||||
|
code: 200,
|
||||||
|
data: error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Users;
|
export default Users;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue