challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

pg_validate_login_address.c (3333B)


      1 /*
      2    This file is part of Challenger
      3    Copyright (C) 2023 Taler Systems SA
      4 
      5    Challenger is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file challengerdb/pg_validate_login_address.c
     18  * @brief Implementation of the validate_login_address function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <taler/taler_error_codes.h>
     23 #include <taler/taler_dbevents.h>
     24 #include <taler/taler_pq_lib.h>
     25 #include "pg_validate_login_address.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_DB_QueryStatus
     30 CH_PG_validate_login_address (void *cls,
     31                               const struct CHALLENGER_ValidationNonceP *nonce,
     32                               const char *address,
     33                               const char *client_scope,
     34                               const char *client_state,
     35                               const char *client_redirect_uri,
     36                               struct GNUNET_TIME_Absolute *last_tx_time,
     37                               uint32_t *last_pin,
     38                               uint32_t *pin_attempts_left)
     39 {
     40   struct PostgresClosure *pg = cls;
     41   struct GNUNET_PQ_QueryParam params[] = {
     42     GNUNET_PQ_query_param_auto_from_type (nonce),
     43     GNUNET_PQ_query_param_string (address),
     44     GNUNET_PQ_query_param_string (client_scope),
     45     GNUNET_PQ_query_param_string (client_state),
     46     NULL != client_redirect_uri
     47     ? GNUNET_PQ_query_param_string (client_redirect_uri)
     48     : GNUNET_PQ_query_param_null (),
     49     GNUNET_PQ_query_param_end
     50   };
     51   struct GNUNET_PQ_ResultSpec rs[] = {
     52     GNUNET_PQ_result_spec_absolute_time ("last_tx_time",
     53                                          last_tx_time),
     54     GNUNET_PQ_result_spec_uint32 ("last_pin",
     55                                   last_pin),
     56     GNUNET_PQ_result_spec_uint32 ("pin_attempts_left",
     57                                   pin_attempts_left),
     58     GNUNET_PQ_result_spec_end
     59   };
     60 
     61   PREPARE (pg,
     62            "validate_set_address",
     63            "UPDATE validations SET"
     64            "  address_attempts_left=CASE"
     65            "    WHEN address != $2"
     66            "    THEN address_attempts_left - 1"
     67            "    ELSE address_attempts_left"
     68            "  END"
     69            " ,address=$2"
     70            " ,client_scope=$3"
     71            " ,client_state=$4"
     72            " ,client_redirect_uri=$5"
     73            " WHERE nonce=$1"
     74            "   AND (address_attempts_left > 0"
     75            "        OR address == $2)"
     76            " RETURNING"
     77            "   last_tx_time"
     78            "  ,last_pin"
     79            "  ,pin_attempts_left;");
     80   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     81                                                    "validate_set_address",
     82                                                    params,
     83                                                    rs);
     84 }