forked from lda/telodendria
[MOD] Modify UserDeactivate and remove UserDeactivateWithInfo.
This commit is contained in:
parent
15d0ffb0f4
commit
0d3a660419
4 changed files with 18 additions and 23 deletions
|
@ -96,7 +96,7 @@ ROUTE_IMPL(RouteAdminDeactivate, path, argp)
|
|||
|
||||
if (method == HTTP_DELETE)
|
||||
{
|
||||
UserDeactivateWithInfo(removed, UserGetName(user), reason);
|
||||
UserDeactivate(removed, UserGetName(user), reason);
|
||||
response = HashMapCreate();
|
||||
|
||||
JsonSet(response, JsonValueString(removedLocalpart), 1, "user");
|
||||
|
|
|
@ -126,7 +126,7 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
goto finish;
|
||||
}
|
||||
|
||||
if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user))
|
||||
if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user, NULL, NULL))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
|
|
23
src/User.c
23
src/User.c
|
@ -429,31 +429,30 @@ UserSetPassword(User * user, char *password)
|
|||
}
|
||||
|
||||
int
|
||||
UserDeactivate(User * user)
|
||||
{
|
||||
return UserDeactivateWithInfo(user, NULL, NULL);
|
||||
}
|
||||
int
|
||||
UserDeactivateWithInfo(User * user, char * admin, char * reason)
|
||||
UserDeactivate(User * user, char * from, char * reason)
|
||||
{
|
||||
HashMap *json;
|
||||
JsonValue *val;
|
||||
|
||||
if (!user)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* By default, it's the target's username */
|
||||
if (!from)
|
||||
{
|
||||
from = UserGetName(user);
|
||||
}
|
||||
|
||||
json = DbJson(user->ref);
|
||||
|
||||
JsonValueFree(HashMapSet(json, "deactivated", JsonValueBoolean(1)));
|
||||
|
||||
if (admin && reason)
|
||||
val = JsonValueString(from);
|
||||
JsonValueFree(JsonSet(json, val, 2, "deactivate", "by"));
|
||||
if (reason)
|
||||
{
|
||||
JsonValue * val;
|
||||
|
||||
val = JsonValueString(admin);
|
||||
JsonValueFree(JsonSet(json, val, 2, "deactivate", "admin"));
|
||||
|
||||
val = JsonValueString(reason);
|
||||
JsonValueFree(JsonSet(json, val, 2, "deactivate", "reason"));
|
||||
}
|
||||
|
|
|
@ -199,15 +199,12 @@ extern int UserSetPassword(User *, char *);
|
|||
* is to prevent future users from pretending to be a previous user
|
||||
* of a given localpart. The user is logged out; all access tokens are
|
||||
* invalidated.
|
||||
* Additionally, it stores information on who deactivated the account
|
||||
* (be it an admin or the user itself), and why. If the user
|
||||
* responsible for deactivating the target user is NULL, then it is
|
||||
* set to the target's own name.
|
||||
*/
|
||||
extern int UserDeactivate(User *);
|
||||
|
||||
/**
|
||||
* Acts just like
|
||||
* .Fn UserDeactivate ,
|
||||
* but saves the reason and admin that deactivated the user
|
||||
*/
|
||||
extern int UserDeactivateWithInfo(User *, char *, char *);
|
||||
extern int UserDeactivate(User *, char *, char *);
|
||||
|
||||
/**
|
||||
* Reactivates the given user account if it has been deactvated with
|
||||
|
@ -220,7 +217,6 @@ extern int UserReactivate(User *);
|
|||
* Return a boolean value indicating whether or not the user was
|
||||
* deactivated using
|
||||
* .Fn UserDeactivate .
|
||||
* Note that once deactivated, users cannot be reactivated.
|
||||
*/
|
||||
extern int UserDeactivated(User *);
|
||||
|
||||
|
|
Loading…
Reference in a new issue