mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-30 11:27:50 +01:00
Update to v5
This commit is contained in:
@@ -25,9 +25,16 @@
|
|||||||
"@adonisjs/session",
|
"@adonisjs/session",
|
||||||
"@adonisjs/auth",
|
"@adonisjs/auth",
|
||||||
"@adonisjs/lucid",
|
"@adonisjs/lucid",
|
||||||
"@adonisjs/mail"
|
"@adonisjs/mail",
|
||||||
|
"@adonisjs/view"
|
||||||
],
|
],
|
||||||
"aceProviders": [
|
"aceProviders": [
|
||||||
"@adonisjs/repl"
|
"@adonisjs/repl"
|
||||||
|
],
|
||||||
|
"metaFiles": [
|
||||||
|
{
|
||||||
|
"pattern": "resources/views/**/*.edge",
|
||||||
|
"reloadServer": false
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
11
.env.example
11
.env.example
@@ -21,8 +21,11 @@ REDIS_HOST=
|
|||||||
REDIS_PASSWORD=
|
REDIS_PASSWORD=
|
||||||
|
|
||||||
GITHUB_TOKEN=
|
GITHUB_TOKEN=
|
||||||
|
GITHUB_SOURCE=
|
||||||
|
BASE_URL=
|
||||||
|
API_VERSION=
|
||||||
|
|
||||||
SMTP_HOST=
|
CACHE_VIEWS=
|
||||||
SMTP_PORT=
|
|
||||||
SMTP_USERNAME=
|
MAILGUN_API_KEY=
|
||||||
SMTP_PASSWORD=
|
MAILGUN_URL=
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
|||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
import FormValidator from "App/Validators/FormValidator";
|
import FormValidator from "App/Validators/FormValidator";
|
||||||
import Form from "App/Models/Form";
|
import Form from "App/Models/Form";
|
||||||
|
import FormConfirmation from "App/Mailers/FormConfirmation";
|
||||||
|
|
||||||
export default class FormsController {
|
export default class FormsController {
|
||||||
|
|
||||||
@@ -8,6 +9,8 @@ export default class FormsController {
|
|||||||
const data = await request.validate(FormValidator)
|
const data = await request.validate(FormValidator)
|
||||||
|
|
||||||
await Form.create(data)
|
await Form.create(data)
|
||||||
|
|
||||||
|
await new FormConfirmation(data.name, data.email).sendLater()
|
||||||
//todo send confirmation email + email to me
|
//todo send confirmation email + email to me
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
status: 200
|
status: 200
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import ProjectValidator from "App/Validators/project/ProjectValidator";
|
|||||||
export default class ProjectsController {
|
export default class ProjectsController {
|
||||||
|
|
||||||
public async get ({ response }: HttpContextContract) {
|
public async get ({ response }: HttpContextContract) {
|
||||||
const projects = await Project.query().orderBy('progress', 'desc')
|
const projects = await Project.query().orderBy('id', 'asc')
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
projects
|
projects
|
||||||
})
|
})
|
||||||
|
|||||||
22
app/Mailers/FormConfirmation.ts
Normal file
22
app/Mailers/FormConfirmation.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import mjml from 'mjml'
|
||||||
|
import { BaseMailer, MessageContract } from '@ioc:Adonis/Addons/Mail'
|
||||||
|
import View from "@ioc:Adonis/Core/View";
|
||||||
|
|
||||||
|
export default class FormConfirmation extends BaseMailer {
|
||||||
|
|
||||||
|
constructor (private name: string, private email: string) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
public html = mjml(View.render('emails/confirmation_form', {
|
||||||
|
name: this.name
|
||||||
|
})).html
|
||||||
|
|
||||||
|
public prepare(message: MessageContract) {
|
||||||
|
message
|
||||||
|
.from('contact@arthurdanjou.fr')
|
||||||
|
.to(this.email)
|
||||||
|
.subject('Confirmation Form')
|
||||||
|
.html(this.html)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Config source: https://git.io/JvyKy
|
* Config source: https://git.io/JY0mp
|
||||||
*
|
*
|
||||||
* Feel free to let us know via PR, if you find something broken in this config
|
* Feel free to let us know via PR, if you find something broken in this config
|
||||||
* file.
|
* file.
|
||||||
@@ -17,69 +17,8 @@ import { AuthConfig } from '@ioc:Adonis/Addons/Auth'
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
const authConfig: AuthConfig = {
|
const authConfig: AuthConfig = {
|
||||||
guard: 'web',
|
guard: 'api',
|
||||||
list: {
|
guards: {
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Web Guard
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Web guard uses classic old school sessions for authenticating users.
|
|
||||||
| If you are building a standard web application, it is recommended to
|
|
||||||
| use web guard with session driver
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
web: {
|
|
||||||
driver: 'session',
|
|
||||||
|
|
||||||
provider: {
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Driver
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Name of the driver
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
driver: 'lucid',
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Identifier key
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The identifier key is the unique key on the model. In most cases specifying
|
|
||||||
| the primary key is the right choice.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
identifierKey: 'id',
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Uids
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Uids are used to search a user against one of the mentioned columns. During
|
|
||||||
| login, the auth module will search the user mentioned value against one
|
|
||||||
| of the mentioned columns to find their user record.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
uids: ['email'],
|
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Model
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The model to use for fetching or finding users. The model is imported
|
|
||||||
| lazily since the config files are read way earlier in the lifecycle
|
|
||||||
| of booting the app and the models may not be in a usable state at
|
|
||||||
| that time.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
model: () => import('App/Models/User'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| OAT Guard
|
| OAT Guard
|
||||||
@@ -113,6 +52,7 @@ const authConfig: AuthConfig = {
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
tokenProvider: {
|
tokenProvider: {
|
||||||
|
type: 'api',
|
||||||
driver: 'redis',
|
driver: 'redis',
|
||||||
redisConnection: 'local',
|
redisConnection: 'local',
|
||||||
foreignKey: 'user_id',
|
foreignKey: 'user_id',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const mailConfig: MailConfig = {
|
|||||||
| a mailer
|
| a mailer
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
mailer: 'smtp',
|
mailer: 'mailgun',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -36,21 +36,16 @@ const mailConfig: MailConfig = {
|
|||||||
mailers: {
|
mailers: {
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Smtp
|
| Mailgun
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| Uses SMTP protocol for sending email
|
| Uses Mailgun service for sending emails.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
smtp: {
|
mailgun: {
|
||||||
driver: 'smtp',
|
driver: 'mailgun',
|
||||||
host: Env.get('SMTP_HOST'),
|
baseUrl: `https://api.mailgun.net/v3/${Env.get('MAILGUN_URL')}`,
|
||||||
port: Env.get('SMTP_PORT'),
|
key: Env.get('MAILGUN_API_KEY'),
|
||||||
auth: {
|
|
||||||
user: Env.get('SMTP_USERNAME'),
|
|
||||||
pass: Env.get('SMTP_PASSWORD'),
|
|
||||||
type: 'login',
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Contract source: https://git.io/JvyKD
|
* Contract source: https://git.io/JOdz5
|
||||||
*
|
*
|
||||||
* Feel free to let us know via PR, if you find something broken in this
|
* Feel free to let us know via PR, if you find something broken in this
|
||||||
* file.
|
* file.
|
||||||
@@ -45,30 +45,16 @@ declare module '@ioc:Adonis/Addons/Auth' {
|
|||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| The guards are used for authenticating users using different drivers.
|
| The guards are used for authenticating users using different drivers.
|
||||||
| The auth module comes with 4 different guards.
|
| The auth module comes with 3 different guards.
|
||||||
|
|
|
|
||||||
| - SessionGuardContract
|
| - SessionGuardContract
|
||||||
| - BasicAuthGuardContract
|
| - BasicAuthGuardContract
|
||||||
| - JwtGuardContract
|
|
||||||
| - OATGuardContract ( Opaque access token )
|
| - OATGuardContract ( Opaque access token )
|
||||||
|
|
|
|
||||||
| Every guard needs a provider for looking up users from the database.
|
| Every guard needs a provider for looking up users from the database.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
interface GuardsList {
|
interface GuardsList {
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Web Guard
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The web guard uses sessions for maintaining user login state. It uses
|
|
||||||
| the `user` provider for fetching user details.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
web: {
|
|
||||||
implementation: SessionGuardContract<'user', 'web'>,
|
|
||||||
config: SessionGuardConfig<'user'>,
|
|
||||||
},
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| OAT Guard
|
| OAT Guard
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ declare module '@ioc:Adonis/Addons/Mail' {
|
|||||||
import { MailDrivers } from '@ioc:Adonis/Addons/Mail'
|
import { MailDrivers } from '@ioc:Adonis/Addons/Mail'
|
||||||
|
|
||||||
interface MailersList {
|
interface MailersList {
|
||||||
smtp: MailDrivers['smtp'],
|
mailgun: MailDrivers['mailgun'],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
env.ts
18
env.ts
@@ -15,8 +15,9 @@
|
|||||||
import Env from '@ioc:Adonis/Core/Env'
|
import Env from '@ioc:Adonis/Core/Env'
|
||||||
|
|
||||||
export default Env.rules({
|
export default Env.rules({
|
||||||
|
|
||||||
//App
|
//App
|
||||||
HOST: Env.schema.string({ format: 'host' }),
|
HOST: Env.schema.string({ format: 'host' }),
|
||||||
PORT: Env.schema.number(),
|
PORT: Env.schema.number(),
|
||||||
APP_KEY: Env.schema.string(),
|
APP_KEY: Env.schema.string(),
|
||||||
APP_NAME: Env.schema.string(),
|
APP_NAME: Env.schema.string(),
|
||||||
@@ -38,5 +39,18 @@ export default Env.rules({
|
|||||||
MYSQL_DB_NAME: Env.schema.string(),
|
MYSQL_DB_NAME: Env.schema.string(),
|
||||||
|
|
||||||
//Session
|
//Session
|
||||||
SESSION_DRIVER: Env.schema.string()
|
SESSION_DRIVER: Env.schema.string(),
|
||||||
|
|
||||||
|
//Views
|
||||||
|
CACHE_VIEWS: Env.schema.boolean(),
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
GITHUB_TOKEN: Env.schema.string(),
|
||||||
|
GITHUB_SOURCE: Env.schema.string({ format: 'url' }),
|
||||||
|
BASE_URL: Env.schema.string({ format: 'url' }),
|
||||||
|
API_VERSION: Env.schema.string(),
|
||||||
|
|
||||||
|
//Mails
|
||||||
|
MAILGUN_API_KEY: Env.schema.string(),
|
||||||
|
MAILGUN_URL: Env.schema.string()
|
||||||
})
|
})
|
||||||
|
|||||||
28
package.json
28
package.json
@@ -11,27 +11,29 @@
|
|||||||
"lr": "node ace list:routes"
|
"lr": "node ace list:routes"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@adonisjs/assembler": "^3.0.0",
|
"@adonisjs/assembler": "^5.1.1",
|
||||||
"adonis-preset-ts": "^2.1.0",
|
"adonis-preset-ts": "^2.1.0",
|
||||||
"pino-pretty": "^4.7.1",
|
"pino-pretty": "^4.7.1",
|
||||||
"typescript": "^4.2.3",
|
"typescript": "^4.2.4",
|
||||||
"youch": "^2.2.1",
|
"youch": "^2.2.2",
|
||||||
"youch-terminal": "^1.1.0"
|
"youch-terminal": "^1.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adonisjs/auth": "^5.1.1",
|
"@adonisjs/auth": "^8.0.2",
|
||||||
"@adonisjs/core": "~5.0.4-preview-rc-2.1",
|
"@adonisjs/core": "~5.1.6",
|
||||||
"@adonisjs/lucid": "^10.0.0",
|
"@adonisjs/lucid": "^14.0.0",
|
||||||
"@adonisjs/mail": "^5.2.3",
|
"@adonisjs/mail": "^7.1.1",
|
||||||
"@adonisjs/redis": "^5.0.9",
|
"@adonisjs/redis": "^7.0.2",
|
||||||
"@adonisjs/repl": "^1.0.0",
|
"@adonisjs/repl": "^3.1.2",
|
||||||
"@adonisjs/session": "^4.0.5",
|
"@adonisjs/session": "^6.0.3",
|
||||||
|
"@adonisjs/view": "^6.0.1",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"luxon": "^1.26.0",
|
"luxon": "^1.26.0",
|
||||||
|
"mjml": "^4.9.3",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"phc-argon2": "^1.1.0",
|
"phc-argon2": "^1.1.1",
|
||||||
"proxy-addr": "^2.0.6",
|
"proxy-addr": "^2.0.6",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"tslib": "^2.1.0"
|
"tslib": "^2.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
resources/views/emails/confirmation_form.edge
Normal file
10
resources/views/emails/confirmation_form.edge
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<mjml>
|
||||||
|
<mj-body>
|
||||||
|
<mj-section>
|
||||||
|
<mj-column>
|
||||||
|
<mj-divider border-color="#F45E43"></mj-divider>
|
||||||
|
<mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text>
|
||||||
|
</mj-column>
|
||||||
|
</mj-section>
|
||||||
|
</mj-body>
|
||||||
|
</mjml>
|
||||||
@@ -21,8 +21,8 @@ import Server from "@ioc:Adonis/Core/Server";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Server.middleware.register([
|
Server.middleware.register([
|
||||||
'Adonis/Core/BodyParserMiddleware',
|
() => import('@ioc:Adonis/Core/BodyParser'),
|
||||||
'App/Middleware/SilentAuth',
|
() => import('App/Middleware/SilentAuth'),
|
||||||
])
|
])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -42,5 +42,5 @@ Server.middleware.register([
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
Server.middleware.registerNamed({
|
Server.middleware.registerNamed({
|
||||||
auth: 'App/Middleware/Auth',
|
auth: () => import('App/Middleware/Auth'),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,18 +2,19 @@ import Route from '@ioc:Adonis/Core/Route'
|
|||||||
import Application from "@ioc:Adonis/Core/Application";
|
import Application from "@ioc:Adonis/Core/Application";
|
||||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
import HealthCheck from "@ioc:Adonis/Core/HealthCheck";
|
import HealthCheck from "@ioc:Adonis/Core/HealthCheck";
|
||||||
|
import Env from '@ioc:Adonis/Core/Env'
|
||||||
|
|
||||||
const BASE_URL = "https://api.arthurdanjou.fr"
|
const BASE_URL = Env.get('BASE_URL')
|
||||||
|
|
||||||
Route.get('/', async ({response}: HttpContextContract) => {
|
Route.get('/', async ({response}: HttpContextContract) => {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
domain: BASE_URL,
|
domain: BASE_URL,
|
||||||
version: "2.0",
|
version: Env.get('API_VERSION'),
|
||||||
source: `${BASE_URL}/source`,
|
source: `${BASE_URL}/source`,
|
||||||
healthCheck: `${BASE_URL}/health`,
|
healthCheck: `${BASE_URL}/health`,
|
||||||
routes: {
|
routes: {
|
||||||
profile: `${BASE_URL}/profile`,
|
profile: `${BASE_URL}/profile`,
|
||||||
stats: `${BASE_URL}/stats`,
|
//stats: `${BASE_URL}/stats`,
|
||||||
states: `${BASE_URL}/states`,
|
states: `${BASE_URL}/states`,
|
||||||
locations: `${BASE_URL}/locations`,
|
locations: `${BASE_URL}/locations`,
|
||||||
projects: `${BASE_URL}/projects`
|
projects: `${BASE_URL}/projects`
|
||||||
@@ -22,7 +23,7 @@ Route.get('/', async ({response}: HttpContextContract) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Route.get('/source', async ({response}: HttpContextContract) => {
|
Route.get('/source', async ({response}: HttpContextContract) => {
|
||||||
return response.redirect('https://github.com/arthurdanjou/artapi')
|
return response.redirect(Env.get('GITHUB_SOURCE'))
|
||||||
})
|
})
|
||||||
|
|
||||||
Route.get('health', async ({response}: HttpContextContract) => {
|
Route.get('health', async ({response}: HttpContextContract) => {
|
||||||
@@ -35,7 +36,7 @@ Route.get('health', async ({response}: HttpContextContract) => {
|
|||||||
// ArtAPI
|
// ArtAPI
|
||||||
Route.get('/profile', 'ProfileController.me')
|
Route.get('/profile', 'ProfileController.me')
|
||||||
Route.get('/locations', 'LocationsController.get')
|
Route.get('/locations', 'LocationsController.get')
|
||||||
Route.get('/stats', 'StatsController.get')
|
//Route.get('/stats', 'StatsController.get')
|
||||||
Route.get('/states', 'StatesController.get')
|
Route.get('/states', 'StatesController.get')
|
||||||
Route.get('/projects', 'ProjectsController.get')
|
Route.get('/projects', 'ProjectsController.get')
|
||||||
|
|
||||||
@@ -57,9 +58,6 @@ Route.group(() => {
|
|||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
// ArtAPI
|
// ArtAPI
|
||||||
Route.post('form', 'FormsController.send')
|
Route.post('form', 'FormsController.send')
|
||||||
Route.post('/states/:state', 'StatesController.set')
|
|
||||||
Route.post('/stats/build', 'StatesController.incrementBuild')
|
|
||||||
Route.post('/stats/command', 'StatesController.incrementCommand')
|
|
||||||
// ArtSite
|
// ArtSite
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.get('/:slug', 'PostsController.getLikes')
|
Route.get('/:slug', 'PostsController.getLikes')
|
||||||
|
|||||||
@@ -27,12 +27,14 @@
|
|||||||
},
|
},
|
||||||
"types": [
|
"types": [
|
||||||
"@adonisjs/core",
|
"@adonisjs/core",
|
||||||
|
"@adonisjs/env",
|
||||||
"@adonisjs/repl",
|
"@adonisjs/repl",
|
||||||
"@adonisjs/redis",
|
"@adonisjs/redis",
|
||||||
"@adonisjs/session",
|
"@adonisjs/session",
|
||||||
"@adonisjs/auth",
|
"@adonisjs/auth",
|
||||||
"@adonisjs/lucid",
|
"@adonisjs/lucid",
|
||||||
"@adonisjs/mail"
|
"@adonisjs/mail",
|
||||||
|
"@adonisjs/view",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user