View | Details | Raw Unified | Return to bug 30962
Collapse All | Expand All

(-)a/Koha/REST/V1/Patrons/Password.pm (+43 lines)
Lines 144-147 sub set_public { Link Here
144
    };
144
    };
145
}
145
}
146
146
147
=head3 check_password
148
149
Controller method that checks a patron's password
150
151
=cut
152
153
sub check_password {
154
155
    my $c = shift->openapi->valid_input or return;
156
157
    my $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
158
    my $body   = $c->validation->param('body');
159
160
    unless ($patron) {
161
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
162
    }
163
164
    my $password   = $body->{password}   // "";
165
166
    return try {
167
        my $dbh = C4::Context->dbh;
168
        my ($status, $cardnumber, $userid) = C4::Auth::checkpw($dbh, $patron->userid, $password );
169
        unless ( $status ) {
170
            return $c->render(
171
                status  => 400,
172
                openapi => { error => "Invalid password" }
173
            );
174
        }
175
176
        return $c->render( status => 200, openapi => '' );
177
    }
178
    catch {
179
        if ( blessed $_ and $_->isa('Koha::Exceptions::Password') ) {
180
            return $c->render(
181
                status  => 400,
182
                openapi => { error => "$_" }
183
            );
184
        }
185
186
        $c->unhandled_exception($_);
187
    };
188
}
189
147
1;
190
1;
(-)a/api/v1/swagger/paths/patrons_password.yaml (+56 lines)
Lines 116-118 Link Here
116
    x-koha-authorization:
116
    x-koha-authorization:
117
      permissions:
117
      permissions:
118
        superlibrarian: "1"
118
        superlibrarian: "1"
119
"/patrons/{patron_id}/check_password":
120
  post:
121
    x-mojo-to: Patrons::Password#check_password
122
    operationId: checkPatronPassword
123
    tags:
124
      - patrons
125
    summary: Check password for a patron
126
    parameters:
127
      - $ref: ../swagger.yaml#/parameters/patron_id_pp
128
      - name: body
129
        in: body
130
        description: A JSON object containing password information
131
        schema:
132
          type: object
133
          properties:
134
            password:
135
              description: Password (plain text)
136
              type: string
137
          required:
138
            - password
139
          additionalProperties: false
140
    produces:
141
      - application/json
142
    responses:
143
      "200":
144
        description: Check password succeeded
145
      "400":
146
        description: Bad request
147
        schema:
148
          $ref: ../swagger.yaml#/definitions/error
149
      "401":
150
        description: Authentication required
151
        schema:
152
          $ref: ../swagger.yaml#/definitions/error
153
      "403":
154
        description: Access forbidden
155
        schema:
156
          $ref: ../swagger.yaml#/definitions/error
157
      "404":
158
        description: Patron not found
159
        schema:
160
          $ref: ../swagger.yaml#/definitions/error
161
      "500":
162
        description: |
163
          Internal server error. Possible `error_code` attribute values:
164
165
          * `internal_server_error`
166
        schema:
167
          $ref: ../swagger.yaml#/definitions/error
168
      "503":
169
        description: Under maintenance
170
        schema:
171
          $ref: ../swagger.yaml#/definitions/error
172
    x-koha-authorization:
173
      permissions:
174
        borrowers: "1"
(-)a/api/v1/swagger/swagger.yaml (-1 / +2 lines)
Lines 179-184 paths: Link Here
179
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
179
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
180
  "/patrons/{patron_id}/password/expiration_date":
180
  "/patrons/{patron_id}/password/expiration_date":
181
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
181
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
182
  "/patrons/{patron_id}/check_password":
183
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1check_password"
182
  "/public/biblios/{biblio_id}":
184
  "/public/biblios/{biblio_id}":
183
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
185
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
184
  "/public/biblios/{biblio_id}/items":
186
  "/public/biblios/{biblio_id}/items":
185
- 

Return to bug 30962