-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* TOS, Privacy, Register, TODO: contact * Contact ability
- Loading branch information
1 parent
a5242e1
commit 22be3de
Showing
22 changed files
with
719 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import Contact from 'App/Models/Contact' | ||
import CreateContactValidator from 'App/Validators/CreateContactValidator' | ||
|
||
export default class ContactsController { | ||
// public async index({}: HttpContextContract) {} | ||
|
||
// public async create({}: HttpContextContract) {} | ||
|
||
public async store({ request, response }: HttpContextContract) { | ||
|
||
try { | ||
await request.validate(CreateContactValidator) | ||
} catch (error) { | ||
return response.status(400).send(error.messages) | ||
} | ||
const { email, reason, message } = request.all() | ||
|
||
const contact = await Contact.create({ | ||
email, | ||
reason, | ||
message | ||
}) | ||
|
||
return response.send({message: 'Created successfully', id: contact.id}) | ||
} | ||
|
||
// public async show({}: HttpContextContract) {} | ||
|
||
// public async edit({}: HttpContextContract) {} | ||
|
||
// public async update({}: HttpContextContract) {} | ||
|
||
// public async destroy({}: HttpContextContract) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' | ||
|
||
export default class Contact extends BaseModel { | ||
@column({ isPrimary: true }) | ||
public id: number | ||
|
||
@column({ serializeAs: null }) | ||
public email: string | ||
|
||
@column() | ||
public reason: string | ||
|
||
@column() | ||
public message: string | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
public createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
public updatedAt: DateTime | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { schema, CustomMessages, rules } from '@ioc:Adonis/Core/Validator' | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
|
||
export default class CreateContactValidator { | ||
constructor(protected ctx: HttpContextContract) {} | ||
|
||
public schema = schema.create({ | ||
email: schema.string({ trim: true },[ | ||
rules.email(), | ||
rules.required(), | ||
]), | ||
reason: schema.string({ trim: true }, [ | ||
rules.required(), | ||
]), | ||
message: schema.string({ trim: true }, [ | ||
rules.required(), | ||
]), | ||
}) | ||
|
||
public messages: CustomMessages = { | ||
'email.required': 'The email field is required', | ||
'email.email': 'Enter a valid email address', | ||
'reason.required': 'The reason field is required', | ||
'message.required': 'The message field is required', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class extends BaseSchema { | ||
protected tableName = 'users' | ||
|
||
public async up () { | ||
this.schema.table(this.tableName, (table) => { | ||
table.boolean('thirteen').defaultTo(false) | ||
table.boolean('tos').defaultTo(false) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.table(this.tableName, (table) => { | ||
table.dropColumn('thirteen') | ||
table.dropColumn('tos') | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class extends BaseSchema { | ||
protected tableName = 'contacts' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id') | ||
table.string('email') | ||
table.string('reason') | ||
table.text('message') | ||
|
||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { test } from '@japa/runner' | ||
import Contact from 'App/Models/Contact' | ||
import Database from '@ioc:Adonis/Lucid/Database' | ||
|
||
test.group('Contact', (group) => { | ||
group.each.setup(async () => { | ||
await Database.beginGlobalTransaction() | ||
return () => Database.rollbackGlobalTransaction() | ||
}) | ||
// group.setup(async () => { | ||
|
||
// }) | ||
|
||
// group.teardown(async () => { | ||
|
||
// }) | ||
|
||
test('Can submit a contact form request', async ({ client }) => { | ||
const response = await client.post('/contact').json({ | ||
email: '[email protected]', | ||
reason: 'general', | ||
message: 'stuff here' | ||
}) | ||
response.assertStatus(200) | ||
await Contact.findOrFail(response.body().id) | ||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,27 +11,19 @@ export default function Form({ | |
}) { | ||
return ( | ||
<> | ||
{/* | ||
This example requires updating your template: | ||
``` | ||
<html class="h-full bg-gray-50"> | ||
<body class="h-full"> | ||
``` | ||
*/} | ||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8"> | ||
<div className="w-full max-w-md space-y-8"> | ||
<div> | ||
|
||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900"> | ||
Sign in to your account | ||
</h2> | ||
{/* <p className="mt-2 text-center text-sm text-gray-600"> | ||
<p className="mt-2 text-center text-sm text-gray-600"> | ||
Or{' '} | ||
<Link href="/register" className="font-medium text-sky-600 hover:text-sky-500"> | ||
register your account | ||
register a new account | ||
</Link> | ||
</p> */} | ||
</p> | ||
</div> | ||
<form className="mt-8 space-y-6" onSubmit={onSubmit}> | ||
<input type="hidden" name="remember" defaultValue="true" /> | ||
|
@@ -48,7 +40,6 @@ export default function Form({ | |
required | ||
className="relative block w-full rounded-t-md border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-sky-600 sm:text-sm sm:leading-6" | ||
placeholder="Email address" | ||
defaultValue="[email protected]" | ||
/> | ||
</div> | ||
<div> | ||
|
@@ -63,7 +54,6 @@ export default function Form({ | |
required | ||
className="relative block w-full rounded-b-md border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-sky-600 sm:text-sm sm:leading-6" | ||
placeholder="Password" | ||
defaultValue="Test1234" | ||
/> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.