summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-23 22:57:52 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-23 22:57:52 +0300
commita9cb8228e6a8ed7bcc7b6ce3c3008b69b235536e (patch)
tree10ee14123818e80f9f5f84db9512dfc808b0f32e /src
parentbf398b9faf65f0e897bdfefacc2ab14448b74801 (diff)
Checking identity creation input values
Diffstat (limited to 'src')
-rw-r--r--src/app.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/src/app.c b/src/app.c
index 8f4d9d40..3ffb1c94 100644
--- a/src/app.c
+++ b/src/app.c
@@ -539,34 +539,52 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf) {
539static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { 539static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) {
540 if (equal_Command(cmd, "ident.accept") || equal_Command(cmd, "cancel")) { 540 if (equal_Command(cmd, "ident.accept") || equal_Command(cmd, "cancel")) {
541 if (equal_Command(cmd, "ident.accept")) { 541 if (equal_Command(cmd, "ident.accept")) {
542 const iString *commonName = text_InputWidget (findChild_Widget(dlg, "ident.common"));
543 const iString *userId = text_InputWidget (findChild_Widget(dlg, "ident.userid"));
544 const iString *organization = text_InputWidget (findChild_Widget(dlg, "ident.org"));
545 const iString *country = text_InputWidget (findChild_Widget(dlg, "ident.country"));
546 const iBool isTemp = isSelected_Widget(findChild_Widget(dlg, "ident.temp"));
547 if (isEmpty_String(commonName)) {
548 makeMessage_Widget(orange_ColorEscape "MISSING INFO",
549 "A \"Common name\" must be specified.");
550 return iTrue;
551 }
542 iDate until; 552 iDate until;
543 /* Validate the date. */ { 553 /* Validate the date. */ {
544 iZap(until); 554 iZap(until);
545 unsigned int val[6]; 555 unsigned int val[6];
556 iDate today;
557 initCurrent_Date(&today);
546 const int n = 558 const int n =
547 sscanf(cstr_String(text_InputWidget(findChild_Widget(dlg, "ident.until"))), 559 sscanf(cstr_String(text_InputWidget(findChild_Widget(dlg, "ident.until"))),
548 "%04u-%u-%u %u:%u:%u", 560 "%04u-%u-%u %u:%u:%u",
549 &val[0], 561 &val[0], &val[1], &val[2], &val[3], &val[4], &val[5]);
550 &val[1], 562 if (n <= 0 || val[0] < (unsigned) today.year) {
551 &val[2], 563 makeMessage_Widget(orange_ColorEscape "INVALID DATE",
552 &val[3], 564 "Please check the \"Valid until\" date. Examples:\n"
553 &val[4], 565 "2030\n"
554 &val[5]); 566 "2025-06-30\n"
555 if (n <= 0) { 567 "2021-12-31 23:59:59");
556 iWidget *msg =
557 makeMessage_Widget(orange_ColorEscape "INVALID DATE",
558 "Please check the \"Valid until\" date. Examples:\n"
559 "2030\n"
560 "2025-06-30\n"
561 "2021-12-31 23:59:59");
562 return iTrue; 568 return iTrue;
563 } 569 }
570 until.year = val[0];
571 until.month = n >= 2 ? val[1] : 1;
572 until.day = n >= 3 ? val[2] : 1;
573 until.hour = n >= 4 ? val[3] : 0;
574 until.minute = n >= 5 ? val[4] : 0;
575 until.second = n == 6 ? val[5] : 0;
576 /* In the past? */ {
577 iTime now, t;
578 initCurrent_Time(&now);
579 init_Time(&t, &until);
580 if (cmp_Time(&t, &now) <= 0) {
581 makeMessage_Widget(orange_ColorEscape "INVALID DATE",
582 "Expiration date must be in the future.");
583 return iTrue;
584 }
585 }
564 } 586 }
565 const iString *commonName = text_InputWidget(findChild_Widget(dlg, "ident.common")); 587
566 const iString *userId = text_InputWidget(findChild_Widget(dlg, "ident.userid"));
567 const iString *organization = text_InputWidget(findChild_Widget(dlg, "ident.org"));
568 const iString *country = text_InputWidget(findChild_Widget(dlg, "ident.country"));
569 const iBool isTemp = isSelected_Widget(findChild_Widget(dlg, "ident.temp"));
570 } 588 }
571 destroy_Widget(dlg); 589 destroy_Widget(dlg);
572 return iTrue; 590 return iTrue;