validate_login_address.c (3335B)
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 src/challengerdb/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 "validate_login_address.h" 26 #include "pg_helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 CHALLENGERDB_validate_login_address (struct CHALLENGERDB_PostgresContext *ctx, 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 GNUNET_PQ_QueryParam params[] = { 41 GNUNET_PQ_query_param_auto_from_type (nonce), 42 GNUNET_PQ_query_param_string (address), 43 GNUNET_PQ_query_param_string (client_scope), 44 GNUNET_PQ_query_param_string (client_state), 45 NULL != client_redirect_uri 46 ? GNUNET_PQ_query_param_string (client_redirect_uri) 47 : GNUNET_PQ_query_param_null (), 48 GNUNET_PQ_query_param_end 49 }; 50 struct GNUNET_PQ_ResultSpec rs[] = { 51 GNUNET_PQ_result_spec_absolute_time ("last_tx_time", 52 last_tx_time), 53 GNUNET_PQ_result_spec_uint32 ("last_pin", 54 last_pin), 55 GNUNET_PQ_result_spec_uint32 ("pin_attempts_left", 56 pin_attempts_left), 57 GNUNET_PQ_result_spec_end 58 }; 59 60 PREPARE (ctx, 61 "validate_set_address", 62 "UPDATE validations SET" 63 " address_attempts_left=CASE" 64 " WHEN address != $2" 65 " THEN address_attempts_left - 1" 66 " ELSE address_attempts_left" 67 " END" 68 " ,address=$2" 69 " ,client_scope=$3" 70 " ,client_state=$4" 71 " ,client_redirect_uri=$5" 72 " WHERE nonce=$1" 73 " AND (address_attempts_left > 0" 74 " OR address == $2)" 75 " RETURNING" 76 " last_tx_time" 77 " ,last_pin" 78 " ,pin_attempts_left;"); 79 return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn, 80 "validate_set_address", 81 params, 82 rs); 83 }