From 0a227dcc73505ccb784ffdcf832b1181d514c2ab Mon Sep 17 00:00:00 2001 From: PedroSilva9 Date: Wed, 20 Dec 2023 14:47:00 +0000 Subject: [PATCH] added endpoint to set password of a user via api --- lib/RT/REST2/Resource/User.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/RT/REST2/Resource/User.pm b/lib/RT/REST2/Resource/User.pm index af4c8c0c2b5..35a9c0e3de8 100644 --- a/lib/RT/REST2/Resource/User.pm +++ b/lib/RT/REST2/Resource/User.pm @@ -81,6 +81,21 @@ sub dispatch_rules { return { record => $user }; }, ), + Path::Dispatcher::Rule::Regex->new( + regex => qr{^/user/([^/]+)/set-password/?$}, + block => sub { + my ($match, $req) = @_; + my $user = RT::User->new($req->env->{"rt.current_user"}); + $user->Load($match->pos(1)); + my $user_data = JSON::from_json($req->content); + $user->SafeSetPassword( + Current => $user_data->{"Current"}, + New => $user_data->{"New"}, + Confirmation => $user_data->{"Confirmation"}, + ); + return { record => $user }; + }, + ), } around 'serialize' => sub {