create & update card pin details
This commit is contained in:
parent
299ab696cc
commit
b76252d6ef
5 changed files with 71 additions and 13 deletions
29
db/db.go
29
db/db.go
|
|
@ -773,7 +773,7 @@ func Get_card_name_count(card_name string) (card_count int, err error) {
|
||||||
|
|
||||||
func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string,
|
func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k3 string, k4 string,
|
||||||
tx_limit_sats int, day_limit_sats int, lnurlw_enable bool, card_name string, uid_privacy bool,
|
tx_limit_sats int, day_limit_sats int, lnurlw_enable bool, card_name string, uid_privacy bool,
|
||||||
allow_neg_bal_ptr bool) error {
|
allow_neg_bal_ptr bool, pin_enable bool, pin_number string, pin_limit_sats int) error {
|
||||||
|
|
||||||
lnurlw_enable_yn := "N"
|
lnurlw_enable_yn := "N"
|
||||||
if lnurlw_enable {
|
if lnurlw_enable {
|
||||||
|
|
@ -790,6 +790,11 @@ func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k
|
||||||
allow_neg_bal_yn = "Y"
|
allow_neg_bal_yn = "Y"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pin_enable_yn := "N"
|
||||||
|
if pin_enable {
|
||||||
|
pin_enable_yn = "Y"
|
||||||
|
}
|
||||||
|
|
||||||
db, err := open()
|
db, err := open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -811,11 +816,12 @@ func Insert_card(one_time_code string, k0_auth_key string, k2_cmac_key string, k
|
||||||
sqlStatement = `INSERT INTO cards` +
|
sqlStatement = `INSERT INTO cards` +
|
||||||
` (one_time_code, k0_auth_key, k2_cmac_key, k3, k4, uid, last_counter_value,` +
|
` (one_time_code, k0_auth_key, k2_cmac_key, k3, k4, uid, last_counter_value,` +
|
||||||
` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, lnurlw_enable,` +
|
` lnurlw_request_timeout_sec, tx_limit_sats, day_limit_sats, lnurlw_enable,` +
|
||||||
` one_time_code_used, card_name, uid_privacy, allow_negative_balance)` +
|
` one_time_code_used, card_name, uid_privacy, allow_negative_balance,` +
|
||||||
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9, $10, $11);`
|
` pin_enable, pin_number, pin_limit_sats)` +
|
||||||
|
` VALUES ($1, $2, $3, $4, $5, '', 0, 60, $6, $7, $8, 'N', $9, $10, $11, $12, $13, $14);`
|
||||||
res, err = db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
|
res, err = db.Exec(sqlStatement, one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
|
||||||
tx_limit_sats, day_limit_sats, lnurlw_enable_yn, card_name, uid_privacy_yn,
|
tx_limit_sats, day_limit_sats, lnurlw_enable_yn, card_name, uid_privacy_yn,
|
||||||
allow_neg_bal_yn)
|
allow_neg_bal_yn, pin_enable_yn, pin_number, pin_limit_sats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -871,13 +877,19 @@ func Wipe_card(card_name string) (*Card_wipe_info, error) {
|
||||||
return &card_wipe_info, nil
|
return &card_wipe_info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_limit_sats int) error {
|
func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_limit_sats int,
|
||||||
|
pin_enable bool, pin_number string, pin_limit_sats int) error {
|
||||||
|
|
||||||
lnurlw_enable_yn := "N"
|
lnurlw_enable_yn := "N"
|
||||||
if lnurlw_enable {
|
if lnurlw_enable {
|
||||||
lnurlw_enable_yn = "Y"
|
lnurlw_enable_yn = "Y"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pin_enable_yn := "N"
|
||||||
|
if pin_enable {
|
||||||
|
pin_enable_yn = "Y"
|
||||||
|
}
|
||||||
|
|
||||||
db, err := open()
|
db, err := open()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -886,10 +898,11 @@ func Update_card(card_name string, lnurlw_enable bool, tx_limit_sats int, day_li
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
sqlStatement := `UPDATE cards SET lnurlw_enable = $2, tx_limit_sats = $3, day_limit_sats = $4 ` +
|
sqlStatement := `UPDATE cards SET lnurlw_enable = $2, tx_limit_sats = $3, day_limit_sats = $4, ` +
|
||||||
`WHERE card_name = $1 AND wiped = 'N';`
|
`pin_enable = $5, pin_number = $6, pin_limit_sats = $7 WHERE card_name = $1 AND wiped = 'N';`
|
||||||
|
|
||||||
res, err := db.Exec(sqlStatement, card_name, lnurlw_enable_yn, tx_limit_sats, day_limit_sats)
|
res, err := db.Exec(sqlStatement, card_name, lnurlw_enable_yn, tx_limit_sats, day_limit_sats,
|
||||||
|
pin_enable_yn, pin_number, pin_limit_sats)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -83,12 +83,33 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pin_enable_flag_str := r.URL.Query().Get("enable_pin")
|
||||||
|
pin_enable_flag, err := strconv.ParseBool(pin_enable_flag_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: enable_pin is not a valid boolean"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_number := r.URL.Query().Get("pin_number")
|
||||||
|
|
||||||
|
pin_limit_sats_str := r.URL.Query().Get("pin_limit_sats")
|
||||||
|
pin_limit_sats, err := strconv.Atoi(pin_limit_sats_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: pin_limit_sats is not a valid integer"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// log the request
|
// log the request
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"card_name": card_name, "tx_max": tx_max, "day_max": day_max,
|
"card_name": card_name, "tx_max": tx_max, "day_max": day_max,
|
||||||
"enable": enable_flag, "uid_privacy": uid_privacy_flag,
|
"enable": enable_flag, "uid_privacy": uid_privacy_flag,
|
||||||
"allow_neg_bal": allow_neg_bal_flag}).Info("createboltcard API request")
|
"allow_neg_bal": allow_neg_bal_flag, "enable_pin": pin_enable_flag,
|
||||||
|
"pin_number": pin_number, "pin_limit_sats": pin_limit_sats}).Info("createboltcard API request")
|
||||||
|
|
||||||
// create the keys
|
// create the keys
|
||||||
|
|
||||||
|
|
@ -102,7 +123,7 @@ func Createboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err = db.Insert_card(one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
|
err = db.Insert_card(one_time_code, k0_auth_key, k2_cmac_key, k3, k4,
|
||||||
tx_max, day_max, enable_flag, card_name,
|
tx_max, day_max, enable_flag, card_name,
|
||||||
uid_privacy_flag, allow_neg_bal_flag)
|
uid_privacy_flag, allow_neg_bal_flag, pin_enable_flag, pin_number, pin_limit_sats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,26 @@ func Updateboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pin_enable_flag_str := r.URL.Query().Get("enable_pin")
|
||||||
|
pin_enable_flag, err := strconv.ParseBool(pin_enable_flag_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: enable_pin is not a valid boolean"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_number := r.URL.Query().Get("pin_number")
|
||||||
|
|
||||||
|
pin_limit_sats_str := r.URL.Query().Get("pin_limit_sats")
|
||||||
|
pin_limit_sats, err := strconv.Atoi(pin_limit_sats_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: pin_limit_sats is not a valid integer"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
card_name := r.URL.Query().Get("card_name")
|
card_name := r.URL.Query().Get("card_name")
|
||||||
|
|
||||||
// check if card_name exists
|
// check if card_name exists
|
||||||
|
|
@ -64,11 +84,12 @@ func Updateboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"card_name": card_name, "tx_max": tx_max, "day_max": day_max,
|
"card_name": card_name, "tx_max": tx_max, "day_max": day_max,
|
||||||
"enable": enable_flag}).Info("updateboltcard API request")
|
"enable": enable_flag, "enable_pin": pin_enable_flag,
|
||||||
|
"pin_number": pin_number, "pin_limit_sats": pin_limit_sats}).Info("updateboltcard API request")
|
||||||
|
|
||||||
// update the card record
|
// update the card record
|
||||||
|
|
||||||
err = db.Update_card(card_name, enable_flag, tx_max, day_max)
|
err = db.Update_card(card_name, enable_flag, tx_max, day_max, pin_enable_flag, pin_number, pin_limit_sats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ if [ "$x" = "y" ]; then
|
||||||
psql postgres -f sql/create_db_init.sql
|
psql postgres -f sql/create_db_init.sql
|
||||||
psql postgres -f sql/create_db.sql
|
psql postgres -f sql/create_db.sql
|
||||||
psql postgres -f sql/create_db_user.sql
|
psql postgres -f sql/create_db_user.sql
|
||||||
psql postgres -f sql/settings.sql
|
psql postgres -f sql/settings.sql.secret
|
||||||
echo Database created
|
echo Database created
|
||||||
else
|
else
|
||||||
echo No action
|
echo No action
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ CREATE TABLE cards (
|
||||||
one_time_code_expiry TIMESTAMPTZ DEFAULT NOW() + INTERVAL '1 DAY',
|
one_time_code_expiry TIMESTAMPTZ DEFAULT NOW() + INTERVAL '1 DAY',
|
||||||
one_time_code_used CHAR(1) NOT NULL DEFAULT 'Y',
|
one_time_code_used CHAR(1) NOT NULL DEFAULT 'Y',
|
||||||
allow_negative_balance CHAR(1) NOT NULL DEFAULT 'N',
|
allow_negative_balance CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
|
pin_enable CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
|
pin_number CHAR(4) NOT NULL DEFAULT '0000',
|
||||||
|
pin_limit_sats INT NOT NULL,
|
||||||
wiped CHAR(1) NOT NULL DEFAULT 'N',
|
wiped CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
PRIMARY KEY(card_id)
|
PRIMARY KEY(card_id)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue