{
  "meta": {
    "options": {
      "linkedFile": "/views/registration.ejs",
      "linkedForm": "register1"
    },
    "$_POST": [
      {
        "type": "text",
        "fieldName": "username",
        "name": "username"
      },
      {
        "type": "text",
        "fieldName": "userid",
        "name": "userid"
      },
      {
        "type": "text",
        "fieldName": "firstname",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            }
          }
        },
        "name": "firstname"
      },
      {
        "type": "text",
        "fieldName": "lastname",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            }
          }
        },
        "name": "lastname"
      },
      {
        "type": "text",
        "fieldName": "email",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            },
            "core:email": {
              "param": ""
            }
          }
        },
        "name": "email"
      },
      {
        "type": "text",
        "fieldName": "password",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            },
            "core:minlength": {
              "param": "8"
            }
          }
        },
        "name": "password"
      },
      {
        "type": "text",
        "fieldName": "password2",
        "options": {
          "rules": {
            "core:equalTo": {
              "param": "password"
            }
          }
        },
        "name": "password2"
      },
      {
        "type": "text",
        "name": "pwd"
      }
    ]
  },
  "exec": {
    "steps": [
      {
        "name": "validate",
        "module": "validator",
        "action": "validate",
        "options": {
          "data": [
            {
              "name": "validate_1",
              "value": "{{$_POST.email}}",
              "rules": {
                "db:notexists": {
                  "param": {
                    "connection": "authdb",
                    "table": "users",
                    "column": "email"
                  }
                }
              }
            }
          ]
        }
      },
      {
        "name": "",
        "module": "core",
        "action": "condition",
        "options": {
          "if": "{{$_POST.username.length()>0}}",
          "then": {
            "steps": {
              "name": "Unauthorized",
              "module": "core",
              "action": "response",
              "options": {
                "status": 401,
                "data": "Unauthorized"
              }
            }
          }
        },
        "outputType": "boolean"
      },
      {
        "name": "",
        "module": "core",
        "action": "condition",
        "options": {
          "if": "{{$_POST.userid!=$_SESSION.regcode}}",
          "then": {
            "steps": {
              "name": "Unauthorized",
              "module": "core",
              "action": "response",
              "options": {
                "status": 401,
                "data": "Unauthorized"
              }
            }
          }
        },
        "outputType": "boolean"
      },
      {
        "name": "hash",
        "module": "crypto",
        "action": "passwordHash",
        "options": {
          "password": "{{$_POST.password}}"
        },
        "outputType": "text",
        "output": true
      },
      {
        "name": "validationcode",
        "module": "core",
        "action": "setvalue",
        "options": {
          "key": "g_validationcode",
          "value": "{{UUID}}"
        },
        "meta": [],
        "outputType": "text",
        "output": true
      },
      {
        "name": "insert",
        "module": "dbupdater",
        "action": "insert",
        "options": {
          "connection": "authdb",
          "sql": {
            "type": "insert",
            "values": [
              {
                "table": "users",
                "column": "email",
                "type": "text",
                "value": "{{$_POST.email}}"
              },
              {
                "table": "users",
                "column": "pwd",
                "type": "text",
                "value": "{{hash}}"
              },
              {
                "table": "users",
                "column": "regcode",
                "type": "text",
                "value": "{{validationcode}}"
              },
              {
                "table": "users",
                "column": "firstname",
                "type": "text",
                "value": "{{$_POST.firstname}}"
              },
              {
                "table": "users",
                "column": "lastname",
                "type": "text",
                "value": "{{$_POST.lastname}}"
              }
            ],
            "table": "users",
            "returning": "id",
            "query": "insert into `users` (`email`, `firstname`, `lastname`, `pwd`, `regcode`) values (?, ?, ?, ?, ?) returning `id`",
            "params": [
              {
                "name": ":P1",
                "type": "expression",
                "value": "{{$_POST.email}}",
                "test": ""
              },
              {
                "name": ":P2",
                "type": "expression",
                "value": "{{hash}}",
                "test": ""
              },
              {
                "name": ":P3",
                "type": "expression",
                "value": "{{validationcode}}",
                "test": ""
              },
              {
                "name": ":P4",
                "type": "expression",
                "value": "{{$_POST.firstname}}",
                "test": ""
              },
              {
                "name": ":P5",
                "type": "expression",
                "value": "{{$_POST.lastname}}",
                "test": ""
              }
            ]
          }
        },
        "meta": [
          {
            "name": "identity",
            "type": "number"
          },
          {
            "name": "affected",
            "type": "number"
          }
        ],
        "output": true
      },
      {
        "name": "",
        "module": "mail",
        "action": "send",
        "options": {
          "instance": "mail",
          "subject": "Validation Code",
          "fromName": "No-Reply",
          "fromEmail": "no-reply@rpmindustries.com",
          "toName": "{{$_POST.firstname+' '+$_POST.lastname}}",
          "toEmail": "{{$_POST.email}}",
          "body": "Your validation code is : {{validationcode}}"
        },
        "metaData": {
          "sendToName": {
            "name": "lastname",
            "type": "text"
          },
          "sendToEmail": {
            "name": "email",
            "type": "text"
          }
        }
      }
    ]
  },
  "usedModules": {
    "argon2": "^0.30.2"
  }
}