odac 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/rules/coding.md +27 -0
- package/.agent/rules/memory.md +33 -0
- package/.agent/rules/project.md +30 -0
- package/.agent/rules/workflow.md +16 -0
- package/.github/workflows/auto-pr-description.yml +3 -1
- package/.github/workflows/release.yml +42 -1
- package/.github/workflows/test-coverage.yml +6 -5
- package/.github/workflows/test-publish.yml +36 -0
- package/.husky/pre-commit +10 -0
- package/.husky/pre-push +13 -0
- package/.releaserc.js +3 -3
- package/CHANGELOG.md +184 -0
- package/README.md +53 -34
- package/bin/odac.js +181 -49
- package/client/odac.js +878 -995
- package/docs/backend/01-overview/03-development-server.md +39 -46
- package/docs/backend/02-structure/01-typical-project-layout.md +59 -25
- package/docs/backend/03-config/00-configuration-overview.md +15 -6
- package/docs/backend/03-config/01-database-connection.md +3 -3
- package/docs/backend/03-config/02-static-route-mapping-optional.md +1 -1
- package/docs/backend/03-config/03-request-timeout.md +1 -1
- package/docs/backend/03-config/04-environment-variables.md +4 -4
- package/docs/backend/03-config/05-early-hints.md +2 -2
- package/docs/backend/04-routing/02-controller-less-view-routes.md +9 -3
- package/docs/backend/04-routing/03-api-and-data-routes.md +18 -0
- package/docs/backend/04-routing/07-cron-jobs.md +17 -1
- package/docs/backend/04-routing/09-websocket.md +29 -0
- package/docs/backend/05-controllers/01-how-to-build-a-controller.md +48 -3
- package/docs/backend/05-controllers/02-your-trusty-odac-assistant.md +2 -0
- package/docs/backend/05-controllers/03-controller-classes.md +61 -55
- package/docs/backend/05-forms/01-custom-forms.md +103 -95
- package/docs/backend/05-forms/02-automatic-database-insert.md +21 -21
- package/docs/backend/06-request-and-response/01-the-request-object-what-is-the-user-asking-for.md +17 -0
- package/docs/backend/07-views/02-rendering-a-view.md +1 -1
- package/docs/backend/07-views/03-variables.md +5 -5
- package/docs/backend/07-views/04-request-data.md +1 -1
- package/docs/backend/07-views/08-backend-javascript.md +1 -1
- package/docs/backend/07-views/10-styling-and-tailwind.md +93 -0
- package/docs/backend/08-database/01-getting-started.md +100 -0
- package/docs/backend/08-database/02-basics.md +136 -0
- package/docs/backend/08-database/03-advanced.md +84 -0
- package/docs/backend/08-database/04-migrations.md +48 -0
- package/docs/backend/09-validation/01-the-validator-service.md +1 -0
- package/docs/backend/10-authentication/03-register.md +9 -2
- package/docs/backend/10-authentication/04-odac-register-forms.md +48 -48
- package/docs/backend/10-authentication/05-session-management.md +16 -2
- package/docs/backend/10-authentication/06-odac-login-forms.md +50 -50
- package/docs/backend/10-authentication/07-magic-links.md +134 -0
- package/docs/backend/11-mail/01-the-mail-service.md +118 -28
- package/docs/backend/12-streaming/01-streaming-overview.md +2 -2
- package/docs/backend/13-utilities/01-odac-var.md +7 -7
- package/docs/backend/13-utilities/02-ipc.md +73 -0
- package/docs/frontend/01-overview/01-introduction.md +5 -1
- package/docs/frontend/02-ajax-navigation/01-quick-start.md +1 -1
- package/docs/index.json +21 -125
- package/eslint.config.mjs +5 -47
- package/jest.config.js +1 -1
- package/package.json +16 -7
- package/src/Auth.js +414 -121
- package/src/Config.js +12 -7
- package/src/Database.js +188 -0
- package/src/Env.js +3 -1
- package/src/Ipc.js +337 -0
- package/src/Lang.js +9 -2
- package/src/Mail.js +408 -37
- package/src/Odac.js +105 -40
- package/src/Request.js +71 -49
- package/src/Route/Cron.js +62 -18
- package/src/Route/Internal.js +215 -12
- package/src/Route/Middleware.js +7 -2
- package/src/Route.js +372 -109
- package/src/Server.js +118 -12
- package/src/Storage.js +169 -0
- package/src/Token.js +6 -4
- package/src/Validator.js +95 -3
- package/src/Var.js +22 -6
- package/src/View/EarlyHints.js +43 -33
- package/src/View/Form.js +210 -28
- package/src/View.js +108 -7
- package/src/WebSocket.js +18 -3
- package/template/odac.json +5 -0
- package/template/package.json +3 -1
- package/template/route/www.js +12 -10
- package/template/view/content/home.html +3 -3
- package/template/view/head/main.html +2 -2
- package/test/Client.test.js +168 -0
- package/test/Config.test.js +112 -0
- package/test/Lang.test.js +92 -0
- package/test/Odac.test.js +86 -0
- package/test/{framework/middleware.test.js → Route/Middleware.test.js} +2 -2
- package/test/{framework/Route.test.js → Route.test.js} +1 -1
- package/test/{framework/View → View}/EarlyHints.test.js +1 -1
- package/test/{framework/WebSocket.test.js → WebSocket.test.js} +2 -2
- package/test/scripts/check-coverage.js +4 -4
- package/docs/backend/08-database/01-database-connection.md +0 -99
- package/docs/backend/08-database/02-using-mysql.md +0 -322
- package/src/Mysql.js +0 -575
- package/template/config.json +0 -5
- package/test/cli/Cli.test.js +0 -36
- package/test/core/Candy.test.js +0 -234
- package/test/core/Commands.test.js +0 -538
- package/test/core/Config.test.js +0 -1432
- package/test/core/Lang.test.js +0 -250
- package/test/core/Process.test.js +0 -156
- package/test/server/Api.test.js +0 -647
- package/test/server/DNS.test.js +0 -2050
- package/test/server/DNS.test.js.bak +0 -2084
- package/test/server/Hub.test.js +0 -497
- package/test/server/Log.test.js +0 -73
- package/test/server/Mail.account.test_.js +0 -460
- package/test/server/Mail.init.test_.js +0 -411
- package/test/server/Mail.test_.js +0 -1340
- package/test/server/SSL.test_.js +0 -1491
- package/test/server/Server.test.js +0 -765
- package/test/server/Service.test_.js +0 -1127
- package/test/server/Subdomain.test.js +0 -440
- package/test/server/Web/Firewall.test.js +0 -175
- package/test/server/Web/Proxy.test.js +0 -397
- package/test/server/Web.test.js +0 -1494
- package/test/server/__mocks__/acme-client.js +0 -17
- package/test/server/__mocks__/bcrypt.js +0 -50
- package/test/server/__mocks__/child_process.js +0 -389
- package/test/server/__mocks__/crypto.js +0 -432
- package/test/server/__mocks__/fs.js +0 -450
- package/test/server/__mocks__/globalOdac.js +0 -227
- package/test/server/__mocks__/http.js +0 -575
- package/test/server/__mocks__/https.js +0 -272
- package/test/server/__mocks__/index.js +0 -249
- package/test/server/__mocks__/mail/server.js +0 -100
- package/test/server/__mocks__/mail/smtp.js +0 -31
- package/test/server/__mocks__/mailparser.js +0 -81
- package/test/server/__mocks__/net.js +0 -369
- package/test/server/__mocks__/node-forge.js +0 -328
- package/test/server/__mocks__/os.js +0 -320
- package/test/server/__mocks__/path.js +0 -291
- package/test/server/__mocks__/selfsigned.js +0 -8
- package/test/server/__mocks__/server/src/mail/server.js +0 -100
- package/test/server/__mocks__/server/src/mail/smtp.js +0 -31
- package/test/server/__mocks__/smtp-server.js +0 -106
- package/test/server/__mocks__/sqlite3.js +0 -394
- package/test/server/__mocks__/testFactories.js +0 -299
- package/test/server/__mocks__/testHelpers.js +0 -363
- package/test/server/__mocks__/tls.js +0 -229
|
@@ -4,7 +4,7 @@ The `<odac:register>` component provides a zero-configuration way to create secu
|
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
|
-
### 1. Configure Database (
|
|
7
|
+
### 1. Configure Database (odac.json)
|
|
8
8
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
@@ -23,17 +23,17 @@ That's all you need! The `auth` configuration is optional.
|
|
|
23
23
|
|
|
24
24
|
```html
|
|
25
25
|
<odac:register redirect="/dashboard">
|
|
26
|
-
<odac:
|
|
26
|
+
<odac:input name="email" type="email" placeholder="Email" unique>
|
|
27
27
|
<odac:validate rule="required|email" message="Please enter a valid email"/>
|
|
28
|
-
</odac:
|
|
28
|
+
</odac:input>
|
|
29
29
|
|
|
30
|
-
<odac:
|
|
30
|
+
<odac:input name="username" type="text" placeholder="Username" unique>
|
|
31
31
|
<odac:validate rule="required|minlen:4" message="Username must be at least 4 characters"/>
|
|
32
|
-
</odac:
|
|
32
|
+
</odac:input>
|
|
33
33
|
|
|
34
|
-
<odac:
|
|
34
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
35
35
|
<odac:validate rule="required|minlen:8" message="Password must be at least 8 characters"/>
|
|
36
|
-
</odac:
|
|
36
|
+
</odac:input>
|
|
37
37
|
|
|
38
38
|
<odac:submit>Create Account</odac:submit>
|
|
39
39
|
</odac:register>
|
|
@@ -94,12 +94,12 @@ Main form container with configuration options:
|
|
|
94
94
|
|
|
95
95
|
## Field Types
|
|
96
96
|
|
|
97
|
-
### `<odac:
|
|
97
|
+
### `<odac:input>`
|
|
98
98
|
|
|
99
99
|
Defines an input field with validation rules:
|
|
100
100
|
|
|
101
101
|
```html
|
|
102
|
-
<odac:
|
|
102
|
+
<odac:input
|
|
103
103
|
name="email" <!-- Field name (required) -->
|
|
104
104
|
type="email" <!-- Input type (default: text) -->
|
|
105
105
|
placeholder="Email" <!-- Placeholder text -->
|
|
@@ -107,7 +107,7 @@ Defines an input field with validation rules:
|
|
|
107
107
|
unique> <!-- Check uniqueness in database -->
|
|
108
108
|
|
|
109
109
|
<odac:validate rule="required|email" message="Valid email required"/>
|
|
110
|
-
</odac:
|
|
110
|
+
</odac:input>
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
**Attributes:**
|
|
@@ -132,19 +132,19 @@ Use the `skip` attribute for fields that should be validated but not saved to th
|
|
|
132
132
|
|
|
133
133
|
```html
|
|
134
134
|
<!-- Password confirmation - validate but don't save -->
|
|
135
|
-
<odac:
|
|
135
|
+
<odac:input name="confirm_password" type="password" placeholder="Confirm Password" skip>
|
|
136
136
|
<odac:validate rule="required|same:password" message="Passwords must match"/>
|
|
137
|
-
</odac:
|
|
137
|
+
</odac:input>
|
|
138
138
|
|
|
139
139
|
<!-- Terms acceptance - validate but don't save -->
|
|
140
|
-
<odac:
|
|
140
|
+
<odac:input name="terms" type="checkbox" label="I accept the terms" skip>
|
|
141
141
|
<odac:validate rule="accepted" message="You must accept the terms"/>
|
|
142
|
-
</odac:
|
|
142
|
+
</odac:input>
|
|
143
143
|
|
|
144
144
|
<!-- Captcha verification - validate but don't save -->
|
|
145
|
-
<odac:
|
|
145
|
+
<odac:input name="captcha" type="text" placeholder="Enter captcha" skip>
|
|
146
146
|
<odac:validate rule="required" message="Please complete the captcha"/>
|
|
147
|
-
</odac:
|
|
147
|
+
</odac:input>
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
**Common Use Cases:**
|
|
@@ -213,24 +213,24 @@ Defines validation rules for a field:
|
|
|
213
213
|
You can add multiple `<odac:validate>` tags for different error messages:
|
|
214
214
|
|
|
215
215
|
```html
|
|
216
|
-
<odac:
|
|
216
|
+
<odac:input name="username" type="text" unique>
|
|
217
217
|
<odac:validate rule="required" message="Username is required"/>
|
|
218
218
|
<odac:validate rule="minlen:4" message="Username must be at least {min} characters"/>
|
|
219
219
|
<odac:validate rule="maxlen:20" message="Username cannot exceed {max} characters"/>
|
|
220
220
|
<odac:validate rule="alphanumeric" message="Username can only contain letters and numbers"/>
|
|
221
221
|
<odac:validate rule="unique" message="Username '{value}' is already taken"/>
|
|
222
|
-
</odac:
|
|
222
|
+
</odac:input>
|
|
223
223
|
```
|
|
224
224
|
|
|
225
225
|
Or combine rules in a single tag:
|
|
226
226
|
|
|
227
227
|
```html
|
|
228
|
-
<odac:
|
|
228
|
+
<odac:input name="username" type="text" unique>
|
|
229
229
|
<odac:validate
|
|
230
230
|
rule="required|minlen:4|maxlen:20|alphanumeric"
|
|
231
231
|
message="Username must be 4-20 alphanumeric characters"/>
|
|
232
232
|
<odac:validate rule="unique" message="Username '{value}' is already taken"/>
|
|
233
|
-
</odac:
|
|
233
|
+
</odac:input>
|
|
234
234
|
```
|
|
235
235
|
|
|
236
236
|
## Message Placeholders
|
|
@@ -238,17 +238,17 @@ Or combine rules in a single tag:
|
|
|
238
238
|
Use placeholders in error messages for dynamic values:
|
|
239
239
|
|
|
240
240
|
```html
|
|
241
|
-
<odac:
|
|
241
|
+
<odac:input name="username" type="text">
|
|
242
242
|
<odac:validate
|
|
243
243
|
rule="minlen:4"
|
|
244
244
|
message="Username '{value}' is too short. Minimum {min} characters required"/>
|
|
245
|
-
</odac:
|
|
245
|
+
</odac:input>
|
|
246
246
|
|
|
247
|
-
<odac:
|
|
247
|
+
<odac:input name="age" type="number">
|
|
248
248
|
<odac:validate
|
|
249
249
|
rule="min:18|max:120"
|
|
250
250
|
message="Age must be between {min} and {max} years"/>
|
|
251
|
-
</odac:
|
|
251
|
+
</odac:input>
|
|
252
252
|
```
|
|
253
253
|
|
|
254
254
|
**Available Placeholders:**
|
|
@@ -269,9 +269,9 @@ Set values that are processed only on the backend (not visible in HTML):
|
|
|
269
269
|
```html
|
|
270
270
|
<odac:register redirect="/dashboard">
|
|
271
271
|
<!-- User input fields -->
|
|
272
|
-
<odac:
|
|
272
|
+
<odac:input name="email" type="email" unique>
|
|
273
273
|
<odac:validate rule="required|email"/>
|
|
274
|
-
</odac:
|
|
274
|
+
</odac:input>
|
|
275
275
|
|
|
276
276
|
<!-- Backend-only values -->
|
|
277
277
|
<odac:set name="role" value="user"/>
|
|
@@ -309,9 +309,9 @@ Use `compute` attribute for dynamic values:
|
|
|
309
309
|
Use `if-empty` to set a default only if the user didn't provide a value:
|
|
310
310
|
|
|
311
311
|
```html
|
|
312
|
-
<odac:
|
|
312
|
+
<odac:input name="country" type="text" placeholder="Country (optional)">
|
|
313
313
|
<!-- User can optionally fill this -->
|
|
314
|
-
</odac:
|
|
314
|
+
</odac:input>
|
|
315
315
|
|
|
316
316
|
<odac:set name="country" value="TR" if-empty/>
|
|
317
317
|
<!-- If user leaves it empty, set to "TR" -->
|
|
@@ -342,51 +342,51 @@ Or use content as button text:
|
|
|
342
342
|
<odac:register redirect="/dashboard" autologin="true">
|
|
343
343
|
|
|
344
344
|
<!-- Email Field -->
|
|
345
|
-
<odac:
|
|
345
|
+
<odac:input name="email" type="email" placeholder="Email Address" unique>
|
|
346
346
|
<odac:validate rule="required" message="Email is required"/>
|
|
347
347
|
<odac:validate rule="email" message="Please enter a valid email address"/>
|
|
348
348
|
<odac:validate rule="unique" message="The email '{value}' is already registered"/>
|
|
349
|
-
</odac:
|
|
349
|
+
</odac:input>
|
|
350
350
|
|
|
351
351
|
<!-- Username Field -->
|
|
352
|
-
<odac:
|
|
352
|
+
<odac:input name="username" type="text" placeholder="Username" unique>
|
|
353
353
|
<odac:validate rule="required" message="Username is required"/>
|
|
354
354
|
<odac:validate rule="minlen:4" message="Username must be at least {min} characters"/>
|
|
355
355
|
<odac:validate rule="maxlen:20" message="Username cannot exceed {max} characters"/>
|
|
356
356
|
<odac:validate rule="alphanumeric" message="Only letters and numbers allowed"/>
|
|
357
357
|
<odac:validate rule="unique" message="Username '{value}' is already taken"/>
|
|
358
|
-
</odac:
|
|
358
|
+
</odac:input>
|
|
359
359
|
|
|
360
360
|
<!-- Password Field -->
|
|
361
|
-
<odac:
|
|
361
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
362
362
|
<odac:validate rule="required" message="Password is required"/>
|
|
363
363
|
<odac:validate rule="minlen:8" message="Password must be at least {min} characters"/>
|
|
364
|
-
</odac:
|
|
364
|
+
</odac:input>
|
|
365
365
|
|
|
366
366
|
<!-- Password Confirmation -->
|
|
367
|
-
<odac:
|
|
367
|
+
<odac:input name="password_confirm" type="password" placeholder="Confirm Password" skip>
|
|
368
368
|
<odac:validate rule="required" message="Please confirm your password"/>
|
|
369
369
|
<odac:validate rule="same:password" message="Passwords do not match"/>
|
|
370
|
-
</odac:
|
|
370
|
+
</odac:input>
|
|
371
371
|
|
|
372
372
|
<!-- Full Name -->
|
|
373
|
-
<odac:
|
|
373
|
+
<odac:input name="name" type="text" placeholder="Full Name">
|
|
374
374
|
<odac:validate rule="required" message="Name is required"/>
|
|
375
375
|
<odac:validate rule="alphaspace" message="Name can only contain letters and spaces"/>
|
|
376
376
|
<odac:validate rule="minlen:3" message="Name must be at least {min} characters"/>
|
|
377
|
-
</odac:
|
|
377
|
+
</odac:input>
|
|
378
378
|
|
|
379
379
|
<!-- Age -->
|
|
380
|
-
<odac:
|
|
380
|
+
<odac:input name="age" type="number" placeholder="Age">
|
|
381
381
|
<odac:validate rule="required" message="Age is required"/>
|
|
382
382
|
<odac:validate rule="min:18" message="You must be at least {min} years old"/>
|
|
383
383
|
<odac:validate rule="max:120" message="Please enter a valid age"/>
|
|
384
|
-
</odac:
|
|
384
|
+
</odac:input>
|
|
385
385
|
|
|
386
386
|
<!-- Terms Checkbox -->
|
|
387
|
-
<odac:
|
|
387
|
+
<odac:input name="terms" type="checkbox" label="I agree to the terms and conditions" skip>
|
|
388
388
|
<odac:validate rule="accepted" message="You must accept the terms to continue"/>
|
|
389
|
-
</odac:
|
|
389
|
+
</odac:input>
|
|
390
390
|
|
|
391
391
|
<!-- Backend-only values -->
|
|
392
392
|
<odac:set name="role" value="user"/>
|
|
@@ -427,9 +427,9 @@ Each form gets a unique token when rendered:
|
|
|
427
427
|
Fields marked with `unique` attribute are checked against the database:
|
|
428
428
|
|
|
429
429
|
```html
|
|
430
|
-
<odac:
|
|
430
|
+
<odac:input name="email" type="email" unique>
|
|
431
431
|
<odac:validate rule="unique" message="Email already exists"/>
|
|
432
|
-
</odac:
|
|
432
|
+
</odac:input>
|
|
433
433
|
```
|
|
434
434
|
|
|
435
435
|
The system automatically queries the auth table to check for duplicates.
|
|
@@ -440,9 +440,9 @@ Odac automatically adds HTML5 validation attributes for better UX:
|
|
|
440
440
|
|
|
441
441
|
```html
|
|
442
442
|
<!-- This field -->
|
|
443
|
-
<odac:
|
|
443
|
+
<odac:input name="username" type="text">
|
|
444
444
|
<odac:validate rule="required|minlen:4|maxlen:20|alphanumeric"/>
|
|
445
|
-
</odac:
|
|
445
|
+
</odac:input>
|
|
446
446
|
|
|
447
447
|
<!-- Generates this HTML -->
|
|
448
448
|
<input
|
|
@@ -653,14 +653,14 @@ Then handle the response in JavaScript if needed (though not required for basic
|
|
|
653
653
|
|
|
654
654
|
### Form Not Submitting
|
|
655
655
|
|
|
656
|
-
- Check that `
|
|
656
|
+
- Check that `odac.json` has auth configuration
|
|
657
657
|
- Verify database table exists
|
|
658
658
|
- Check browser console for JavaScript errors
|
|
659
659
|
|
|
660
660
|
### Validation Not Working
|
|
661
661
|
|
|
662
662
|
- Ensure validation rules are spelled correctly
|
|
663
|
-
- Check that field names match between `<odac:
|
|
663
|
+
- Check that field names match between `<odac:input>` and validation
|
|
664
664
|
- Verify HTML5 validation isn't blocking submission
|
|
665
665
|
|
|
666
666
|
### Unique Check Failing
|
|
@@ -31,7 +31,7 @@ Sessions use a **sliding window** approach (similar to NextAuth.js):
|
|
|
31
31
|
|
|
32
32
|
### Configuration
|
|
33
33
|
|
|
34
|
-
Configure session behavior in `
|
|
34
|
+
Configure session behavior in `odac.json`:
|
|
35
35
|
|
|
36
36
|
```json
|
|
37
37
|
{
|
|
@@ -127,9 +127,23 @@ const isLoggedIn = await Odac.Auth.check()
|
|
|
127
127
|
**Get user info:**
|
|
128
128
|
```javascript
|
|
129
129
|
const user = Odac.Auth.user(null) // Full user object
|
|
130
|
+
const user = Odac.Auth.user(null) // Full user object
|
|
130
131
|
const email = Odac.Auth.user('email') // Specific field
|
|
131
132
|
```
|
|
132
133
|
|
|
134
|
+
### Custom Session Data
|
|
135
|
+
|
|
136
|
+
If you need to store your own data in the session (e.g. shopping cart ID, preferences), use the `Odac.session()` helper:
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
// Store data
|
|
140
|
+
Odac.session('theme', 'dark')
|
|
141
|
+
|
|
142
|
+
// Retrieve data
|
|
143
|
+
const theme = Odac.session('theme')
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
|
|
133
147
|
### Best Practices
|
|
134
148
|
|
|
135
149
|
1. **Choose appropriate timeouts** based on your app's security needs
|
|
@@ -153,7 +167,7 @@ const email = Odac.Auth.user('email') // Specific field
|
|
|
153
167
|
- Manually clean old sessions if needed:
|
|
154
168
|
```javascript
|
|
155
169
|
const cutoffDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
|
|
156
|
-
await Odac.
|
|
170
|
+
await Odac.DB.user_tokens
|
|
157
171
|
.where('active', '<', cutoffDate)
|
|
158
172
|
.delete()
|
|
159
173
|
```
|
|
@@ -4,7 +4,7 @@ The `<odac:login>` component provides a zero-configuration way to create secure
|
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
|
-
### 1. Configure Database (
|
|
7
|
+
### 1. Configure Database (odac.json)
|
|
8
8
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
@@ -23,13 +23,13 @@ That's all you need! The `auth` configuration is optional.
|
|
|
23
23
|
|
|
24
24
|
```html
|
|
25
25
|
<odac:login redirect="/dashboard">
|
|
26
|
-
<odac:
|
|
26
|
+
<odac:input name="email" type="email" placeholder="Email">
|
|
27
27
|
<odac:validate rule="required|email" message="Please enter a valid email"/>
|
|
28
|
-
</odac:
|
|
28
|
+
</odac:input>
|
|
29
29
|
|
|
30
|
-
<odac:
|
|
30
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
31
31
|
<odac:validate rule="required" message="Password is required"/>
|
|
32
|
-
</odac:
|
|
32
|
+
</odac:input>
|
|
33
33
|
|
|
34
34
|
<odac:submit>Login</odac:submit>
|
|
35
35
|
</odac:login>
|
|
@@ -79,12 +79,12 @@ Main form container with configuration options:
|
|
|
79
79
|
|
|
80
80
|
## Field Types
|
|
81
81
|
|
|
82
|
-
### `<odac:
|
|
82
|
+
### `<odac:input>`
|
|
83
83
|
|
|
84
84
|
Defines an input field with validation rules:
|
|
85
85
|
|
|
86
86
|
```html
|
|
87
|
-
<odac:
|
|
87
|
+
<odac:input
|
|
88
88
|
name="email" <!-- Field name (required) -->
|
|
89
89
|
type="email" <!-- Input type (default: text) -->
|
|
90
90
|
placeholder="Email" <!-- Placeholder text -->
|
|
@@ -93,7 +93,7 @@ Defines an input field with validation rules:
|
|
|
93
93
|
id="email-field"> <!-- HTML ID (optional) -->
|
|
94
94
|
|
|
95
95
|
<odac:validate rule="required|email" message="Valid email required"/>
|
|
96
|
-
</odac:
|
|
96
|
+
</odac:input>
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
**Attributes:**
|
|
@@ -153,20 +153,20 @@ Defines validation rules for a field:
|
|
|
153
153
|
You can add multiple `<odac:validate>` tags for different error messages:
|
|
154
154
|
|
|
155
155
|
```html
|
|
156
|
-
<odac:
|
|
156
|
+
<odac:input name="email" type="email">
|
|
157
157
|
<odac:validate rule="required" message="Email is required"/>
|
|
158
158
|
<odac:validate rule="email" message="Please enter a valid email address"/>
|
|
159
|
-
</odac:
|
|
159
|
+
</odac:input>
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
Or combine rules in a single tag:
|
|
163
163
|
|
|
164
164
|
```html
|
|
165
|
-
<odac:
|
|
165
|
+
<odac:input name="email" type="email">
|
|
166
166
|
<odac:validate
|
|
167
167
|
rule="required|email"
|
|
168
168
|
message="Please enter a valid email address"/>
|
|
169
|
-
</odac:
|
|
169
|
+
</odac:input>
|
|
170
170
|
```
|
|
171
171
|
|
|
172
172
|
## Message Placeholders
|
|
@@ -174,11 +174,11 @@ Or combine rules in a single tag:
|
|
|
174
174
|
Use placeholders in error messages for dynamic values:
|
|
175
175
|
|
|
176
176
|
```html
|
|
177
|
-
<odac:
|
|
177
|
+
<odac:input name="username" type="text">
|
|
178
178
|
<odac:validate
|
|
179
179
|
rule="minlen:4"
|
|
180
180
|
message="Username '{value}' is too short. Minimum {min} characters required"/>
|
|
181
|
-
</odac:
|
|
181
|
+
</odac:input>
|
|
182
182
|
```
|
|
183
183
|
|
|
184
184
|
**Available Placeholders:**
|
|
@@ -218,15 +218,15 @@ Or use content as button text:
|
|
|
218
218
|
<odac:login redirect="/dashboard">
|
|
219
219
|
|
|
220
220
|
<!-- Email Field -->
|
|
221
|
-
<odac:
|
|
221
|
+
<odac:input name="email" type="email" placeholder="Email Address">
|
|
222
222
|
<odac:validate rule="required" message="Email is required"/>
|
|
223
223
|
<odac:validate rule="email" message="Please enter a valid email address"/>
|
|
224
|
-
</odac:
|
|
224
|
+
</odac:input>
|
|
225
225
|
|
|
226
226
|
<!-- Password Field -->
|
|
227
|
-
<odac:
|
|
227
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
228
228
|
<odac:validate rule="required" message="Password is required"/>
|
|
229
|
-
</odac:
|
|
229
|
+
</odac:input>
|
|
230
230
|
|
|
231
231
|
<!-- Submit Button -->
|
|
232
232
|
<odac:submit text="Login" loading="Logging in..."/>
|
|
@@ -240,15 +240,15 @@ Or use content as button text:
|
|
|
240
240
|
<odac:login redirect="/dashboard">
|
|
241
241
|
|
|
242
242
|
<!-- Username Field -->
|
|
243
|
-
<odac:
|
|
243
|
+
<odac:input name="username" type="text" placeholder="Username">
|
|
244
244
|
<odac:validate rule="required" message="Username is required"/>
|
|
245
245
|
<odac:validate rule="minlen:4" message="Username must be at least {min} characters"/>
|
|
246
|
-
</odac:
|
|
246
|
+
</odac:input>
|
|
247
247
|
|
|
248
248
|
<!-- Password Field -->
|
|
249
|
-
<odac:
|
|
249
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
250
250
|
<odac:validate rule="required" message="Password is required"/>
|
|
251
|
-
</odac:
|
|
251
|
+
</odac:input>
|
|
252
252
|
|
|
253
253
|
<!-- Submit Button -->
|
|
254
254
|
<odac:submit>Login</odac:submit>
|
|
@@ -262,18 +262,18 @@ Or use content as button text:
|
|
|
262
262
|
<odac:login redirect="/dashboard">
|
|
263
263
|
|
|
264
264
|
<!-- Email Field -->
|
|
265
|
-
<odac:
|
|
265
|
+
<odac:input name="email" type="email" placeholder="Email">
|
|
266
266
|
<odac:validate rule="required|email" message="Please enter a valid email"/>
|
|
267
|
-
</odac:
|
|
267
|
+
</odac:input>
|
|
268
268
|
|
|
269
269
|
<!-- Password Field -->
|
|
270
|
-
<odac:
|
|
270
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
271
271
|
<odac:validate rule="required" message="Password is required"/>
|
|
272
|
-
</odac:
|
|
272
|
+
</odac:input>
|
|
273
273
|
|
|
274
274
|
<!-- Remember Me Checkbox -->
|
|
275
|
-
<odac:
|
|
276
|
-
</odac:
|
|
275
|
+
<odac:input name="remember" type="checkbox" label="Remember me">
|
|
276
|
+
</odac:input>
|
|
277
277
|
|
|
278
278
|
<!-- Submit Button -->
|
|
279
279
|
<odac:submit>Login</odac:submit>
|
|
@@ -290,30 +290,30 @@ Or use content as button text:
|
|
|
290
290
|
<odac:login redirect="/dashboard">
|
|
291
291
|
|
|
292
292
|
<div class="form-group">
|
|
293
|
-
<odac:
|
|
293
|
+
<odac:input
|
|
294
294
|
name="email"
|
|
295
295
|
type="email"
|
|
296
296
|
placeholder="Email Address"
|
|
297
297
|
class="form-control">
|
|
298
298
|
<odac:validate rule="required|email" message="Please enter a valid email"/>
|
|
299
|
-
</odac:
|
|
299
|
+
</odac:input>
|
|
300
300
|
<span class="odac-form-error" odac-form-error="email"></span>
|
|
301
301
|
</div>
|
|
302
302
|
|
|
303
303
|
<div class="form-group">
|
|
304
|
-
<odac:
|
|
304
|
+
<odac:input
|
|
305
305
|
name="password"
|
|
306
306
|
type="password"
|
|
307
307
|
placeholder="Password"
|
|
308
308
|
class="form-control">
|
|
309
309
|
<odac:validate rule="required" message="Password is required"/>
|
|
310
|
-
</odac:
|
|
310
|
+
</odac:input>
|
|
311
311
|
<span class="odac-form-error" odac-form-error="password"></span>
|
|
312
312
|
</div>
|
|
313
313
|
|
|
314
314
|
<div class="form-group">
|
|
315
|
-
<odac:
|
|
316
|
-
</odac:
|
|
315
|
+
<odac:input name="remember" type="checkbox" label="Remember me" class="form-check-input">
|
|
316
|
+
</odac:input>
|
|
317
317
|
</div>
|
|
318
318
|
|
|
319
319
|
<odac:submit class="btn btn-primary btn-block" text="Login" loading="Logging in..."/>
|
|
@@ -356,9 +356,9 @@ Odac automatically adds HTML5 validation attributes for better UX:
|
|
|
356
356
|
|
|
357
357
|
```html
|
|
358
358
|
<!-- This field -->
|
|
359
|
-
<odac:
|
|
359
|
+
<odac:input name="email" type="email">
|
|
360
360
|
<odac:validate rule="required|email"/>
|
|
361
|
-
</odac:
|
|
361
|
+
</odac:input>
|
|
362
362
|
|
|
363
363
|
<!-- Generates this HTML -->
|
|
364
364
|
<input
|
|
@@ -507,12 +507,12 @@ The login form supports multiple authentication methods:
|
|
|
507
507
|
|
|
508
508
|
```html
|
|
509
509
|
<odac:login redirect="/dashboard">
|
|
510
|
-
<odac:
|
|
510
|
+
<odac:input name="email" type="email" placeholder="Email">
|
|
511
511
|
<odac:validate rule="required|email"/>
|
|
512
|
-
</odac:
|
|
513
|
-
<odac:
|
|
512
|
+
</odac:input>
|
|
513
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
514
514
|
<odac:validate rule="required"/>
|
|
515
|
-
</odac:
|
|
515
|
+
</odac:input>
|
|
516
516
|
<odac:submit>Login</odac:submit>
|
|
517
517
|
</odac:login>
|
|
518
518
|
```
|
|
@@ -521,12 +521,12 @@ The login form supports multiple authentication methods:
|
|
|
521
521
|
|
|
522
522
|
```html
|
|
523
523
|
<odac:login redirect="/dashboard">
|
|
524
|
-
<odac:
|
|
524
|
+
<odac:input name="username" type="text" placeholder="Username">
|
|
525
525
|
<odac:validate rule="required"/>
|
|
526
|
-
</odac:
|
|
527
|
-
<odac:
|
|
526
|
+
</odac:input>
|
|
527
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
528
528
|
<odac:validate rule="required"/>
|
|
529
|
-
</odac:
|
|
529
|
+
</odac:input>
|
|
530
530
|
<odac:submit>Login</odac:submit>
|
|
531
531
|
</odac:login>
|
|
532
532
|
```
|
|
@@ -535,12 +535,12 @@ The login form supports multiple authentication methods:
|
|
|
535
535
|
|
|
536
536
|
```html
|
|
537
537
|
<odac:login redirect="/dashboard">
|
|
538
|
-
<odac:
|
|
538
|
+
<odac:input name="identifier" type="text" placeholder="Email or Username">
|
|
539
539
|
<odac:validate rule="required"/>
|
|
540
|
-
</odac:
|
|
541
|
-
<odac:
|
|
540
|
+
</odac:input>
|
|
541
|
+
<odac:input name="password" type="password" placeholder="Password">
|
|
542
542
|
<odac:validate rule="required"/>
|
|
543
|
-
</odac:
|
|
543
|
+
</odac:input>
|
|
544
544
|
<odac:submit>Login</odac:submit>
|
|
545
545
|
</odac:login>
|
|
546
546
|
```
|
|
@@ -559,7 +559,7 @@ The login form supports multiple authentication methods:
|
|
|
559
559
|
|
|
560
560
|
### Form Not Submitting
|
|
561
561
|
|
|
562
|
-
- Check that `
|
|
562
|
+
- Check that `odac.json` has MySQL configuration
|
|
563
563
|
- Verify database table exists
|
|
564
564
|
- Check browser console for JavaScript errors
|
|
565
565
|
- Ensure CSRF token is valid
|
|
@@ -567,7 +567,7 @@ The login form supports multiple authentication methods:
|
|
|
567
567
|
### Validation Not Working
|
|
568
568
|
|
|
569
569
|
- Ensure validation rules are spelled correctly
|
|
570
|
-
- Check that field names match between `<odac:
|
|
570
|
+
- Check that field names match between `<odac:input>` and validation
|
|
571
571
|
- Verify HTML5 validation isn't blocking submission
|
|
572
572
|
|
|
573
573
|
### Login Failing
|