From 95aadcd21c9a56ef7d3478a2504980ea44f1bd9c Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Mon, 26 Aug 2013 23:21:15 -0400 Subject: Bug 908338 - Create a new webservice called User.valid_login that will verify if a cookie or login token is valid for the current user r=glob,a=sgreen --- Bugzilla/WebService/Server/REST/Resources/User.pm | 5 +++ Bugzilla/WebService/User.pm | 55 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) (limited to 'Bugzilla') diff --git a/Bugzilla/WebService/Server/REST/Resources/User.pm b/Bugzilla/WebService/Server/REST/Resources/User.pm index 1f82f752d..e2a2ea260 100644 --- a/Bugzilla/WebService/Server/REST/Resources/User.pm +++ b/Bugzilla/WebService/Server/REST/Resources/User.pm @@ -19,6 +19,11 @@ BEGIN { sub _rest_resources { my $rest_resources = [ + qr{^/valid_login$}, { + GET => { + method => 'valid_login' + } + }, qr{^/user$}, { GET => { method => 'get' diff --git a/Bugzilla/WebService/User.pm b/Bugzilla/WebService/User.pm index 08c812076..44938a97a 100644 --- a/Bugzilla/WebService/User.pm +++ b/Bugzilla/WebService/User.pm @@ -83,6 +83,17 @@ sub logout { return undef; } +sub valid_login { + my ($self, $params) = @_; + defined $params->{login} + || ThrowCodeError('param_required', { param => 'login' }); + Bugzilla->login(); + if (Bugzilla->user->id && Bugzilla->user->login eq $params->{login}) { + return $self->type('boolean', 1); + } + return $self->type('boolean', 0); +} + ################# # User Creation # ################# @@ -486,6 +497,50 @@ Log out the user. Does nothing if there is no user logged in. =back +=head2 valid_login + +B + +=over + +=item B + +This method will verify whether a client's cookies or current login +token is still valid or have expired. A valid username must be provided +as well that matches. + +=item B + +=over + +=item C + +The login name that matches the provided cookies or token. + +=item C + +(string) Persistent login token current being used for authentication (optional). +Cookies passed by client will be used before the token if both provided. + +=back + +=item B + +Returns true/false depending on if the current cookies or token are valid +for the provided username. + +=item B (none) + +=item B + +=over + +=item Added in Bugzilla B<5.0>. + +=back + +=back + =head1 Account Creation and Modification =head2 offer_account_by_email -- cgit v1.2.3-24-g4f1b