mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-02-01 20:37:49 +01:00
Working on new version of website
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"commands": {
|
"commands": {
|
||||||
"dump:rcfile": {
|
"dump:rcfile": {
|
||||||
"settings": {},
|
"settings": {},
|
||||||
"commandPath": "@adonisjs/core/build/commands/DumpRc",
|
"commandPath": "@adonisjs/core/commands/DumpRc",
|
||||||
"commandName": "dump:rcfile",
|
"commandName": "dump:rcfile",
|
||||||
"description": "Dump contents of .adonisrc.json file along with defaults",
|
"description": "Dump contents of .adonisrc.json file along with defaults",
|
||||||
"args": [],
|
"args": [],
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"loadApp": true
|
"loadApp": true
|
||||||
},
|
},
|
||||||
"commandPath": "@adonisjs/core/build/commands/ListRoutes",
|
"commandPath": "@adonisjs/core/commands/ListRoutes",
|
||||||
"commandName": "list:routes",
|
"commandName": "list:routes",
|
||||||
"description": "List application routes",
|
"description": "List application routes",
|
||||||
"args": [],
|
"args": [],
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
},
|
},
|
||||||
"generate:key": {
|
"generate:key": {
|
||||||
"settings": {},
|
"settings": {},
|
||||||
"commandPath": "@adonisjs/core/build/commands/GenerateKey",
|
"commandPath": "@adonisjs/core/commands/GenerateKey",
|
||||||
"commandName": "generate:key",
|
"commandName": "generate:key",
|
||||||
"description": "Generate a new APP_KEY secret",
|
"description": "Generate a new APP_KEY secret",
|
||||||
"args": [],
|
"args": [],
|
||||||
|
|||||||
63
app/Controllers/Http/AnnouncesController.ts
Normal file
63
app/Controllers/Http/AnnouncesController.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
|
import Announce from "App/Models/Announce";
|
||||||
|
import AnnounceStoreValidator from "App/Validators/announce/AnnounceStoreValidator";
|
||||||
|
import AnnounceUpdateValidator from "App/Validators/announce/AnnounceUpdateValidator";
|
||||||
|
import getTranslation from "App/Tasks/getTranslation";
|
||||||
|
import File from "App/Models/File";
|
||||||
|
|
||||||
|
export default class AnnouncesController {
|
||||||
|
|
||||||
|
public async index ({ response }: HttpContextContract) {
|
||||||
|
const announce = await Announce.query().orderBy('created_at', 'desc').first()
|
||||||
|
return response.status(200).send({
|
||||||
|
announce: announce
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
|
const data = await request.validate(AnnounceStoreValidator)
|
||||||
|
const announce = new Announce()
|
||||||
|
|
||||||
|
const translation = await getTranslation(data.code)
|
||||||
|
await announce.related('message').associate(translation)
|
||||||
|
|
||||||
|
const cover = await File.findBy('label', data.cover)
|
||||||
|
if (cover) await announce.related('cover').save(cover)
|
||||||
|
|
||||||
|
return response.status(200).send({
|
||||||
|
announce: announce.save()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
|
return response.status(200).send({
|
||||||
|
user: await Announce.findOrFail(params.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update({ request, params, response }: HttpContextContract) {
|
||||||
|
const data = await request.validate(AnnounceUpdateValidator)
|
||||||
|
const announce = await Announce.findOrFail(params.id)
|
||||||
|
|
||||||
|
if (data.code) {
|
||||||
|
const translation = await getTranslation(data.code)
|
||||||
|
await announce.related('message').associate(translation)
|
||||||
|
}
|
||||||
|
|
||||||
|
const cover = await File.findBy('label', data.cover)
|
||||||
|
if (cover) await announce.related('cover').save(cover)
|
||||||
|
|
||||||
|
return response.status(200).send({
|
||||||
|
announce
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async destroy ({ response, params }: HttpContextContract) {
|
||||||
|
const announce = await Announce.findOrFail(params.id)
|
||||||
|
await announce.delete()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'Announce successfully deleted!'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,13 +4,13 @@ import File from "App/Models/File";
|
|||||||
|
|
||||||
export default class FileController {
|
export default class FileController {
|
||||||
|
|
||||||
public async index({response}: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
files: File.query()
|
files: File.query()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store({request, response}: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const file = await request.file('file', {
|
const file = await request.file('file', {
|
||||||
extnames: ['jpg', 'png', 'jpeg']
|
extnames: ['jpg', 'png', 'jpeg']
|
||||||
})
|
})
|
||||||
@@ -35,7 +35,7 @@ export default class FileController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async destroy({params, response}: HttpContextContract) {
|
public async destroy ({ params, response }: HttpContextContract) {
|
||||||
const file = await File.findOrFail(params.id)
|
const file = await File.findOrFail(params.id)
|
||||||
await file.delete()
|
await file.delete()
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
|
|||||||
@@ -1,18 +1,34 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import FormValidator from "App/Validators/FormValidator";
|
import FormStoreValidator from "App/Validators/form/FormStoreValidator";
|
||||||
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 {
|
||||||
|
|
||||||
public async send({ request, response }: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
const data = await request.validate(FormValidator)
|
|
||||||
await Form.create(data)
|
|
||||||
|
|
||||||
await new FormConfirmation(data.name, data.email).preview()
|
|
||||||
//todo send confirmation email + email to me
|
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'Form successfully received !'
|
forms: Form.query().orderBy('created_at', 'asc')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
|
const data = await request.validate(FormStoreValidator)
|
||||||
|
//todo send confirmation email + email to me with FormConfirmation
|
||||||
|
return response.status(200).send({
|
||||||
|
form: await Form.create(data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
|
return response.status(200).send({
|
||||||
|
form: await Form.findOrFail(params.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async destroy ({ response, params }: HttpContextContract) {
|
||||||
|
const form = await Form.findOrFail(params.id)
|
||||||
|
await form.delete()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'Form successfully deleted!'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import User from "App/Models/User";
|
|||||||
|
|
||||||
export default class GuestBookController {
|
export default class GuestBookController {
|
||||||
|
|
||||||
public async index ({response}: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
const guestbook_messages = await GuestbookMessage
|
const guestbook_messages = await GuestbookMessage
|
||||||
.query()
|
.query()
|
||||||
.preload('user')
|
.preload('user')
|
||||||
@@ -15,7 +15,7 @@ export default class GuestBookController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store ({request, response}: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const data = await request.validate(GuestValidator)
|
const data = await request.validate(GuestValidator)
|
||||||
let user = await User.findBy('email', data.email)
|
let user = await User.findBy('email', data.email)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -34,7 +34,21 @@ export default class GuestBookController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async get ({params, response}: HttpContextContract) {
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
|
return response.status(200).send({
|
||||||
|
guestbook_message: await GuestbookMessage.findOrFail(params.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async destroy ({ params, response }: HttpContextContract) {
|
||||||
|
const guestbook_message = await GuestbookMessage.findOrFail(params.id)
|
||||||
|
await guestbook_message.delete()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'GuestBookMessage successfully deleted!'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async exists ({ params, response }: HttpContextContract) {
|
||||||
const email = await params.email
|
const email = await params.email
|
||||||
const guestbook_message = await GuestbookMessage.findBy('email', email)
|
const guestbook_message = await GuestbookMessage.findBy('email', email)
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import LocationValidator from "App/Validators/location/LocationValidator";
|
|||||||
|
|
||||||
export default class LocationsController {
|
export default class LocationsController {
|
||||||
|
|
||||||
public async get ({ response }: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
const location = await Location.query().orderBy('since', 'desc').first()
|
const location = await Location.query().orderBy('since', 'desc').first()
|
||||||
if (location) {
|
if (location) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
@@ -23,9 +23,9 @@ export default class LocationsController {
|
|||||||
|
|
||||||
public async store ({ request, response }: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const data = await request.validate(LocationValidator)
|
const data = await request.validate(LocationValidator)
|
||||||
await Location.create(data)
|
const location = await Location.create(data)
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'Location successfully added !'
|
location
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
|||||||
|
|
||||||
export default class PostsController {
|
export default class PostsController {
|
||||||
|
|
||||||
public async getLikes({params, response}: HttpContextContract) {
|
public async getLikes ({ params, response }: HttpContextContract) {
|
||||||
let post = await Post.findBy('slug', params.slug)
|
let post = await Post.findBy('slug', params.slug)
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
@@ -18,7 +18,7 @@ export default class PostsController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async like ({params, response}: HttpContextContract) {
|
public async like ({ params, response }: HttpContextContract) {
|
||||||
let post = await Post.findBy('slug', params.slug)
|
let post = await Post.findBy('slug', params.slug)
|
||||||
|
|
||||||
if (!post) {
|
if (!post) {
|
||||||
@@ -38,7 +38,7 @@ export default class PostsController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async unlike ({params, response}: HttpContextContract) {
|
public async unlike ({ params, response }: HttpContextContract) {
|
||||||
let post = await Post.findByOrFail('slug', params.slug)
|
let post = await Post.findByOrFail('slug', params.slug)
|
||||||
|
|
||||||
const getLikes = post.likes - 1
|
const getLikes = post.likes - 1
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export default class ProfileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//todo get discord Activity
|
//todo get discord Activity
|
||||||
public async discord({response}: HttpContextContract) {
|
public async discord ({ response }: HttpContextContract) {
|
||||||
const activity = await getDiscordActivity()
|
const activity = await getDiscordActivity()
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
status: activity
|
status: activity
|
||||||
|
|||||||
23
app/Controllers/Http/ProfilesController.ts
Normal file
23
app/Controllers/Http/ProfilesController.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
|
import Profile from "App/Models/Profile";
|
||||||
|
import ProfileUpdateValidator from "App/Validators/profile/ProfileUpdateValidator";
|
||||||
|
|
||||||
|
export default class ProfilesController {
|
||||||
|
|
||||||
|
public async index ( { response }: HttpContextContract ) {
|
||||||
|
return response.status(200).send({
|
||||||
|
profile: await Profile.first()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update ( { response, request }: HttpContextContract ) {
|
||||||
|
const profile = await Profile.firstOrFail()
|
||||||
|
const data = await request.validate(ProfileUpdateValidator)
|
||||||
|
await profile.merge(data).save()
|
||||||
|
|
||||||
|
return response.status(200).send({
|
||||||
|
profile
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +1,55 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import Project from "App/Models/Project";
|
import Project from "App/Models/Project";
|
||||||
import ProjectValidator from "App/Validators/project/ProjectValidator";
|
import ProjectStoreValidator from "App/Validators/project/ProjectStoreValidator";
|
||||||
|
import ProjectUpdateValidator from "App/Validators/project/ProjectUpdateValidator";
|
||||||
|
import File from "App/Models/File";
|
||||||
|
|
||||||
export default class ProjectsController {
|
export default class ProjectsController {
|
||||||
|
|
||||||
public async get ({ response }: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
projects: await Project.query().orderBy('id', 'asc')
|
projects: await Project.query()
|
||||||
|
.orderBy('id', 'asc')
|
||||||
|
.preload('cover')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store ({ request, response}: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const data = await request.validate(ProjectValidator)
|
const data = await request.validate(ProjectStoreValidator)
|
||||||
await Project.create(data)
|
const project = await Project.create(data)
|
||||||
|
const cover = await File.findByOrFail('label', data.cover)
|
||||||
|
|
||||||
|
await project.related('cover').save(cover)
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'Project successfully created'
|
project
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
|
const project = await Project.findOrFail(params.id)
|
||||||
|
await project.load('cover')
|
||||||
|
return response.status(200).send({
|
||||||
|
project
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update ({ request, params, response }: HttpContextContract) {
|
||||||
|
const project = await Project.findOrFail(params.id)
|
||||||
|
const data = await request.validate(ProjectUpdateValidator)
|
||||||
|
const cover = await File.findBy('label', data.cover)
|
||||||
|
|
||||||
|
await project.merge(data).save()
|
||||||
|
if (cover) await project.related('cover').save(cover)
|
||||||
|
return response.status(200).send({
|
||||||
|
project
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async destroy ({ response, params }: HttpContextContract) {
|
||||||
|
const project = await Project.findOrFail(params.id)
|
||||||
|
await project.delete()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'Project successfully deleted!'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
|
||||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
|
||||||
import {UpdateGitHubReadme} from "App/Tasks/UpdateGithubReadme";
|
|
||||||
|
|
||||||
export default class StatesController {
|
|
||||||
|
|
||||||
public async get({response}: HttpContextContract) {
|
|
||||||
|
|
||||||
return response.status(200).send({
|
|
||||||
states: {
|
|
||||||
"is_sleeping": this.getStatus(await Redis.get(`states:is_sleeping`)),
|
|
||||||
"is_developing": this.getStatus(await Redis.get(`states:is_developing`)),
|
|
||||||
"is_learning": this.getStatus(await Redis.get(`states:is_learning`)),
|
|
||||||
"is_listening_music": this.getStatus(await Redis.get(`states:is_listening_music`)),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public async set({request, response, params}: HttpContextContract) {
|
|
||||||
const state = params.state
|
|
||||||
const value = await request.input('value')
|
|
||||||
|
|
||||||
if (state && value) {
|
|
||||||
await Redis.set(`states:${state}`, value)
|
|
||||||
|
|
||||||
if (value === 'true') {
|
|
||||||
switch (state) {
|
|
||||||
case 'learning':
|
|
||||||
await Redis.set(`states:developing`, 'false')
|
|
||||||
await Redis.set(`states:sleeping`, 'false')
|
|
||||||
break
|
|
||||||
case 'developing':
|
|
||||||
await Redis.set(`states:learning`, 'false')
|
|
||||||
await Redis.set(`states:sleeping`, 'false')
|
|
||||||
break
|
|
||||||
case 'listening':
|
|
||||||
await Redis.set(`states:sleeping`, 'false')
|
|
||||||
break
|
|
||||||
case 'sleeping':
|
|
||||||
await Redis.set(`states:developing`, 'false')
|
|
||||||
await Redis.set(`states:listening`, 'false')
|
|
||||||
await Redis.set(`states:learning`, 'false')
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await UpdateGitHubReadme()
|
|
||||||
return response.status(200).send({
|
|
||||||
message: 'State successfully updated!'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getStatus(state: string | null): string {
|
|
||||||
if (state === null) return "No"
|
|
||||||
return state === 'true' ? "Yes" : "No"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +1,30 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import Subscriber from "App/Models/Subscriber";
|
import Subscriber from "App/Models/Subscriber";
|
||||||
import SubscriberValidator from "App/Validators/subscriber/SubscriberValidator";
|
import SubscriberStoreValidator from "App/Validators/subscriber/SubscriberStoreValidator";
|
||||||
|
|
||||||
export default class SubscribersController {
|
export default class SubscribersController {
|
||||||
|
|
||||||
public async get ({ response }: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
const subscribers = await Subscriber.query()
|
const subscribers = await Subscriber.query()
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
count: subscribers.length
|
count: subscribers.length,
|
||||||
|
subscribers: subscribers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store({request, response}: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const data = await request.validate(SubscriberValidator)
|
const data = await request.validate(SubscriberStoreValidator)
|
||||||
const email = await Subscriber.findBy('email', data.email)
|
|
||||||
if (email) {
|
|
||||||
return response.status(201).send({
|
|
||||||
message: 'Subscriber already exists'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
await Subscriber.create(data)
|
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'Subscriber successfully registered!'
|
subscriber: await Subscriber.create(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async delete({request, response}: HttpContextContract) {
|
public async destroy ({ params, response }: HttpContextContract) {
|
||||||
const data = await request.validate(SubscriberValidator)
|
const subscriber = await Subscriber.findOrFail(params.id)
|
||||||
const subscriber = await Subscriber.findBy('email', data.email)
|
await subscriber.delete()
|
||||||
if (subscriber) {
|
return response.status(200).send({
|
||||||
await subscriber.delete()
|
message: 'Subscriber successfully deleted!'
|
||||||
return response.status(200).send({
|
})
|
||||||
message: 'Subscriber successfully deleted!'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
45
app/Controllers/Http/TranslationsController.ts
Normal file
45
app/Controllers/Http/TranslationsController.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
|
import Translation from "App/Models/Translation";
|
||||||
|
import TranslationStoreValidator from "App/Validators/translation/TranslationStoreValidator";
|
||||||
|
import TranslationUpdateValidator from "App/Validators/translation/TranslationUpdateValidator";
|
||||||
|
|
||||||
|
export default class TranslationsController {
|
||||||
|
|
||||||
|
public async index ({ response }: HttpContextContract) {
|
||||||
|
return response.status(200).send({
|
||||||
|
translations: Translation.query()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
|
const data = await request.validate(TranslationStoreValidator)
|
||||||
|
return response.status(200).send({
|
||||||
|
translation: await Translation.create(data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
|
return response.status(200).send({
|
||||||
|
translation: await Translation.findOrFail(params.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update ({ request, params, response }: HttpContextContract) {
|
||||||
|
const translation = await Translation.findOrFail(params.id)
|
||||||
|
const data = await request.validate(TranslationUpdateValidator)
|
||||||
|
await translation.merge(data).save()
|
||||||
|
|
||||||
|
return response.status(200).send({
|
||||||
|
translation
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async destroy ({ response, params }: HttpContextContract) {
|
||||||
|
const translation = await Translation.findOrFail(params.id)
|
||||||
|
await translation.delete()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'Translation successfully deleted!'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import User from "App/Models/User";
|
import User from "App/Models/User";
|
||||||
import UserStoreValidator from "App/Validators/users/UserStoreValidator";
|
import UserStoreValidator from "App/Validators/user/UserStoreValidator";
|
||||||
import UserUpdateValidator from "App/Validators/users/UserUpdateValidator";
|
import UserUpdateValidator from "App/Validators/user/UserUpdateValidator";
|
||||||
|
|
||||||
export default class UsersController {
|
export default class UsersController {
|
||||||
|
|
||||||
public async index({response}: HttpContextContract) {
|
public async index ({ response }: HttpContextContract) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
users: User.query()
|
users: User.query()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async store({request, response}: HttpContextContract) {
|
public async store ({ request, response }: HttpContextContract) {
|
||||||
const data = await request.validate(UserStoreValidator)
|
const data = await request.validate(UserStoreValidator)
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
user: await User.create(data)
|
user: await User.create(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async show({params, response}: HttpContextContract) {
|
public async show ({ params, response }: HttpContextContract) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
user: await User.findOrFail(params.id)
|
user: await User.findOrFail(params.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update({request, params, response}: HttpContextContract) {
|
public async update ({ request, params, response }: HttpContextContract) {
|
||||||
const user = await User.findOrFail(params.id)
|
const user = await User.findOrFail(params.id)
|
||||||
const data = await request.validate(UserUpdateValidator)
|
const data = await request.validate(UserUpdateValidator)
|
||||||
await user.merge(data).save()
|
await user.merge(data).save()
|
||||||
|
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'User successfully updated!'
|
user
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async destroy({ response, params, auth }: HttpContextContract) {
|
public async destroy ({ response, params, auth }: HttpContextContract) {
|
||||||
const user = await User.findOrFail(params.id)
|
const user = await User.findOrFail(params.id)
|
||||||
const admin = await User.findBy('email', 'arthurdanjou@outlook.fr')
|
const admin = await User.findBy('email', 'arthurdanjou@outlook.fr')
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
|
||||||
import axios from 'axios'
|
|
||||||
import Env from "@ioc:Adonis/Core/Env";
|
|
||||||
|
|
||||||
export async function UpdateGitHubReadme(): Promise<void> {
|
|
||||||
const sleeping = await Redis.get('states:sleeping')
|
|
||||||
const learning = await Redis.get('states:learning')
|
|
||||||
const developing = await Redis.get('states:developing')
|
|
||||||
const listening_music = await Redis.get('states:listening')
|
|
||||||
|
|
||||||
const infos_table = `| Informations | State |
|
|
||||||
| ---------------------------: | ------: |
|
|
||||||
| :musical_note: Music Playing | **${getStatus(listening_music)}** |
|
|
||||||
| :bed: Sleeping | **${getStatus(sleeping)}** |
|
|
||||||
| :computer: Developing | **${getStatus(developing)}** |
|
|
||||||
| :books: Learning | **${getStatus(learning)}** |`
|
|
||||||
|
|
||||||
let change = true;
|
|
||||||
|
|
||||||
const {data: read_me} = await axios.get('https://api.github.com/repos/arthurdanjou/arthurdanjou/readme', {
|
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${Env.get('GITHUB_TOKEN')}`
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const content = Buffer.from(read_me.content, 'base64').toString()
|
|
||||||
|
|
||||||
const infos_table_check = '| Informations' + content.split('| Informations')[1]
|
|
||||||
if (!infos_table_check) change = true
|
|
||||||
const old_infos_table = infos_table_check.split('###### Curious')[0]
|
|
||||||
if (!old_infos_table) change = true
|
|
||||||
|
|
||||||
if (!change) return
|
|
||||||
|
|
||||||
await axios.put('https://api.github.com/repos/ArthurDanjou/ArthurDanjou/contents/README.md',
|
|
||||||
{
|
|
||||||
message: 'Updating recent statistics & informations',
|
|
||||||
content: Buffer.from(content.replace(old_infos_table, infos_table + '\n\n'), 'utf8').toString('base64'),
|
|
||||||
sha: read_me.sha,
|
|
||||||
author: {
|
|
||||||
name: 'api.arthurdanjou.fr - API Automation',
|
|
||||||
email: 'me@arthurdanjou.fr'
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${Env.get('GITHUB_TOKEN')}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStatus(state): string {
|
|
||||||
if (state === null) return "No"
|
|
||||||
return state === "true" ? "Yes" : "No"
|
|
||||||
}
|
|
||||||
9
app/Tasks/getTranslation.ts
Normal file
9
app/Tasks/getTranslation.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import Translation from "App/Models/Translation";
|
||||||
|
|
||||||
|
export default async function getTranslation(code: string): Promise<Translation> {
|
||||||
|
let translation = await Translation.findBy('code', code)
|
||||||
|
if (!translation) {
|
||||||
|
translation = await Translation.create({code: code})
|
||||||
|
}
|
||||||
|
return translation
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
export default class AuthValidator {
|
export default class AuthValidator {
|
||||||
constructor (private ctx: HttpContextContract) {
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
}
|
}
|
||||||
|
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
@@ -16,11 +17,6 @@ export default class AuthValidator {
|
|||||||
remember_me: schema.boolean()
|
remember_me: schema.boolean()
|
||||||
})
|
})
|
||||||
|
|
||||||
public cacheKey = this.ctx.routeKey
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
|
||||||
public messages = {
|
|
||||||
'email.email': 'L\'adresse mail n\'est pas valide !',
|
|
||||||
'email.required': 'Veuillez renseigner une adresse mail !',
|
|
||||||
'password.required': 'Veuillez renseigner un mot de passe !',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { schema } from '@ioc:Adonis/Core/Validator'
|
|
||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
||||||
|
|
||||||
export default class FormValidator {
|
|
||||||
constructor (protected ctx: HttpContextContract) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public schema = schema.create({
|
|
||||||
name: schema.string(),
|
|
||||||
email: schema.string(),
|
|
||||||
subject: schema.string(),
|
|
||||||
content: schema.string()
|
|
||||||
})
|
|
||||||
|
|
||||||
public messages = {}
|
|
||||||
}
|
|
||||||
15
app/Validators/announce/AnnounceStoreValidator.ts
Normal file
15
app/Validators/announce/AnnounceStoreValidator.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class AnnounceStoreValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
code: schema.string(),
|
||||||
|
cover: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{ field }} is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
15
app/Validators/announce/AnnounceUpdateValidator.ts
Normal file
15
app/Validators/announce/AnnounceUpdateValidator.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class AnnounceUpdateValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
code: schema.string.optional(),
|
||||||
|
cover: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Validators/form/FormStoreValidator.ts
Executable file
18
app/Validators/form/FormStoreValidator.ts
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class FormStoreValidator {
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public schema = schema.create({
|
||||||
|
name: schema.string(),
|
||||||
|
email: schema.string(),
|
||||||
|
subject: schema.string(),
|
||||||
|
content: schema.string()
|
||||||
|
})
|
||||||
|
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@ import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
|||||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
export default class GuestValidator {
|
export default class GuestValidator {
|
||||||
constructor (private ctx: HttpContextContract) {
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required',
|
||||||
|
'email.email': 'The email is not correct'
|
||||||
}
|
}
|
||||||
|
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
@@ -14,9 +16,6 @@ export default class GuestValidator {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
public cacheKey = this.ctx.routeKey
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
|
||||||
public messages = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
import {schema} from '@ioc:Adonis/Core/Validator'
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
export default class LocationValidator {
|
export default class LocationValidator {
|
||||||
@@ -14,6 +14,6 @@ export default class LocationValidator {
|
|||||||
public cacheKey = this.ctx.routeKey
|
public cacheKey = this.ctx.routeKey
|
||||||
|
|
||||||
public messages = {
|
public messages = {
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
required: 'The field {{field}} is required'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
app/Validators/profile/ProfileUpdateValidator.ts
Normal file
16
app/Validators/profile/ProfileUpdateValidator.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class ProfileUpdateValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
age: schema.number.optional(),
|
||||||
|
hiring_status: schema.string.optional(),
|
||||||
|
hiring_color: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Validators/project/ProjectStoreValidator.ts
Executable file
19
app/Validators/project/ProjectStoreValidator.ts
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class ProjectStoreValidator {
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public schema = schema.create({
|
||||||
|
name: schema.string(),
|
||||||
|
description: schema.string(),
|
||||||
|
progress: schema.number(),
|
||||||
|
url: schema.string(),
|
||||||
|
cover: schema.string()
|
||||||
|
})
|
||||||
|
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Validators/project/ProjectUpdateValidator.ts
Normal file
18
app/Validators/project/ProjectUpdateValidator.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class ProjectUpdateValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
name: schema.string.optional(),
|
||||||
|
description: schema.string.optional(),
|
||||||
|
progress: schema.number.optional(),
|
||||||
|
url: schema.string.optional(),
|
||||||
|
cover: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { schema } from '@ioc:Adonis/Core/Validator'
|
|
||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
||||||
|
|
||||||
export default class ProjectValidator {
|
|
||||||
constructor (protected ctx: HttpContextContract) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public schema = schema.create({
|
|
||||||
name: schema.string(),
|
|
||||||
description: schema.string(),
|
|
||||||
progress: schema.number(),
|
|
||||||
url: schema.string()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
public messages = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
20
app/Validators/subscriber/SubscriberStoreValidator.ts
Executable file
20
app/Validators/subscriber/SubscriberStoreValidator.ts
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
|
export default class SubscriberStoreValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
email: schema.string({ trim: true }, [
|
||||||
|
rules.email(),
|
||||||
|
rules.unique({
|
||||||
|
table: 'subscribers',
|
||||||
|
column: 'email'
|
||||||
|
})
|
||||||
|
])
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
|
||||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
|
||||||
|
|
||||||
export default class SubscriberValidator {
|
|
||||||
constructor (private ctx: HttpContextContract) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public schema = schema.create({
|
|
||||||
email: schema.string({ trim: true }, [
|
|
||||||
rules.email()
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
public cacheKey = this.ctx.routeKey
|
|
||||||
|
|
||||||
public messages = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
22
app/Validators/translation/TranslationStoreValidator.ts
Normal file
22
app/Validators/translation/TranslationStoreValidator.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class TranslationStoreValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
code: schema.string({}, [
|
||||||
|
rules.unique({
|
||||||
|
table: 'translations',
|
||||||
|
column: 'code'
|
||||||
|
})
|
||||||
|
]),
|
||||||
|
english: schema.string.optional(),
|
||||||
|
french: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required',
|
||||||
|
'code.unique': 'The translation code is not unique !'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Validators/translation/TranslationUpdateValidator.ts
Normal file
22
app/Validators/translation/TranslationUpdateValidator.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
|
export default class TranslationUpdateValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
code: schema.string({}, [
|
||||||
|
rules.unique({
|
||||||
|
table: 'translations',
|
||||||
|
column: 'code'
|
||||||
|
})
|
||||||
|
]),
|
||||||
|
english: schema.string.optional(),
|
||||||
|
french: schema.string.optional()
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required',
|
||||||
|
'code.unique': 'The translation code is not unique !'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Validators/user/UserStoreValidator.ts
Executable file
23
app/Validators/user/UserStoreValidator.ts
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
|
export default class UserStoreValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
email: schema.string({ trim: true, escape: true }, [
|
||||||
|
rules.email(),
|
||||||
|
rules.required(),
|
||||||
|
rules.unique({
|
||||||
|
table: 'users',
|
||||||
|
column: 'email'
|
||||||
|
})
|
||||||
|
])
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required',
|
||||||
|
'email.email': 'The email must be valid',
|
||||||
|
'email.unique': 'The email is not unique'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Validators/user/UserUpdateValidator.ts
Executable file
33
app/Validators/user/UserUpdateValidator.ts
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
|
export default class UserUpdateValidator {
|
||||||
|
public schema = schema.create({
|
||||||
|
email: schema.string.optional({ trim: true, escape: true },
|
||||||
|
[
|
||||||
|
rules.email(),
|
||||||
|
rules.unique(
|
||||||
|
{
|
||||||
|
table: 'users',
|
||||||
|
column: 'email'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
),
|
||||||
|
password: schema.string.optional({ trim: true, escape: true },
|
||||||
|
[
|
||||||
|
rules.confirmed()
|
||||||
|
]
|
||||||
|
),
|
||||||
|
is_confirmed: schema.boolean.optional(),
|
||||||
|
confirmation_token: schema.string.optional({ trim: true, escape: true }),
|
||||||
|
remember_me: schema.string.optional({ trim: true, escape: true }),
|
||||||
|
})
|
||||||
|
public messages = {
|
||||||
|
required: 'The field {{field}} is required',
|
||||||
|
'email.email': 'The email must be valid',
|
||||||
|
'password.confirmation': 'Passwords are not the same'
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (protected ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
||||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
|
||||||
|
|
||||||
export default class UserStoreValidator {
|
|
||||||
constructor (private ctx: HttpContextContract) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public schema = schema.create({
|
|
||||||
email: schema.string({ trim: true, escape: true }, [
|
|
||||||
rules.email(),
|
|
||||||
rules.required(),
|
|
||||||
rules.unique({table: 'users', column: 'email'})
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
public cacheKey = this.ctx.routeKey
|
|
||||||
|
|
||||||
public messages = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
'email.email': 'L\'adresse mail doit être valide !',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
|
||||||
import {rules, schema} from '@ioc:Adonis/Core/Validator'
|
|
||||||
|
|
||||||
export default class UserUpdateValidator {
|
|
||||||
constructor (private ctx: HttpContextContract) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public schema = schema.create({
|
|
||||||
email: schema.string.optional({trim: true, escape: true}, [rules.email(), rules.unique({
|
|
||||||
table: 'users', column: 'email'
|
|
||||||
})]),
|
|
||||||
password: schema.string.optional({trim: true, escape: true}, [rules.confirmed()]),
|
|
||||||
is_confirmed: schema.boolean.optional(),
|
|
||||||
confirmation_token: schema.string.optional({trim: true, escape: true}),
|
|
||||||
remember_me: schema.string.optional({trim: true, escape: true}),
|
|
||||||
})
|
|
||||||
|
|
||||||
public cacheKey = this.ctx.routeKey
|
|
||||||
|
|
||||||
public messages = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
'email.email': 'L\'adresse mail doit être valide !',
|
|
||||||
'password.confirmation': 'Les mots de passe ne correspondent pas !'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,7 @@ const authConfig: AuthConfig = {
|
|||||||
| Web Guard
|
| Web Guard
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| Web guard uses classic old school sessions for authenticating users.
|
| Web guard uses classic old school sessions for authenticating user.
|
||||||
| If you are building a standard web application, it is recommended to
|
| If you are building a standard web application, it is recommended to
|
||||||
| use web guard with session driver
|
| use web guard with session driver
|
||||||
|
|
|
|
||||||
@@ -71,7 +71,7 @@ const authConfig: AuthConfig = {
|
|||||||
| Model
|
| Model
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| The model to use for fetching or finding users. The model is imported
|
| The model to use for fetching or finding user. The model is imported
|
||||||
| lazily since the config files are read way earlier in the lifecycle
|
| 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
|
| of booting the app and the models may not be in a usable state at
|
||||||
| that time.
|
| that time.
|
||||||
@@ -158,7 +158,7 @@ const authConfig: AuthConfig = {
|
|||||||
| Model
|
| Model
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| The model to use for fetching or finding users. The model is imported
|
| The model to use for fetching or finding user. The model is imported
|
||||||
| lazily since the config files are read way earlier in the lifecycle
|
| 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
|
| of booting the app and the models may not be in a usable state at
|
||||||
| that time.
|
| that time.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* file.
|
* file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BodyParserConfig } from '@ioc:Adonis/Core/BodyParser'
|
import {BodyParserConfig} from '@ioc:Adonis/Core/BodyParser'
|
||||||
|
|
||||||
const bodyParserConfig: BodyParserConfig = {
|
const bodyParserConfig: BodyParserConfig = {
|
||||||
/*
|
/*
|
||||||
@@ -153,7 +153,7 @@ const bodyParserConfig: BodyParserConfig = {
|
|||||||
| Convert empty strings to null
|
| Convert empty strings to null
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| Convert empty form fields to null. HTML forms results in field string
|
| Convert empty form fields to null. HTML form results in field string
|
||||||
| value when the field is left blank. This option normalizes all the blank
|
| value when the field is left blank. This option normalizes all the blank
|
||||||
| field values to "null"
|
| field values to "null"
|
||||||
|
|
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ declare module '@ioc:Adonis/Addons/Auth' {
|
|||||||
| Providers
|
| Providers
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| The providers are used to fetch users. The Auth module comes pre-bundled
|
| The providers are used to fetch user. The Auth module comes pre-bundled
|
||||||
| with two providers that are `Lucid` and `Database`. Both uses database
|
| with two providers that are `Lucid` and `Database`. Both uses database
|
||||||
| to fetch user details.
|
| to fetch user details.
|
||||||
|
|
|
|
||||||
@@ -44,14 +44,14 @@ declare module '@ioc:Adonis/Addons/Auth' {
|
|||||||
| Guards
|
| Guards
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
|
||||||
| The guards are used for authenticating users using different drivers.
|
| The guards are used for authenticating user using different drivers.
|
||||||
| The auth module comes with 3 different guards.
|
| The auth module comes with 3 different guards.
|
||||||
|
|
|
|
||||||
| - SessionGuardContract
|
| - SessionGuardContract
|
||||||
| - BasicAuthGuardContract
|
| - BasicAuthGuardContract
|
||||||
| - 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 user from the database.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
interface GuardsList {
|
interface GuardsList {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default class GuestbookMessages extends BaseSchema {
|
|||||||
table
|
table
|
||||||
.integer('user_id')
|
.integer('user_id')
|
||||||
.unsigned()
|
.unsigned()
|
||||||
.references('users.id')
|
.references('user.id')
|
||||||
.onDelete('CASCADE')
|
.onDelete('CASCADE')
|
||||||
table.text('message')
|
table.text('message')
|
||||||
table.timestamps(true, true)
|
table.timestamps(true, true)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||||
|
|
||||||
export default class Translations extends BaseSchema {
|
export default class Translations extends BaseSchema {
|
||||||
protected tableName = 'translations'
|
protected tableName = 'translation'
|
||||||
|
|
||||||
public async up () {
|
public async up () {
|
||||||
this.schema.createTable(this.tableName, (table) => {
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
|
|||||||
@@ -3,15 +3,21 @@ import Application from "@ioc:Adonis/Core/Application";
|
|||||||
|
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.get('/discord', 'ProfileController.discord')
|
Route.get('/discord', 'ProfileController.discord')
|
||||||
Route.post('/states/:state', 'StatesController.set')
|
Route.get('/me', 'ProfileController.me')
|
||||||
Route.resource('/users', 'UsersController')
|
|
||||||
Route.post('/locations', 'LocationsController.store')
|
Route.resource('/users', 'UsersController').except(['edit', 'create'])
|
||||||
Route.post('/projects', 'ProjectsController.store')
|
|
||||||
Route.resource('/files', 'FileController').only(['store', 'destroy'])
|
Route.resource('/translations', 'TranslationsController').except(['edit', 'create'])
|
||||||
|
|
||||||
|
Route.resource('/locations', 'LocationsController').only(['index', 'store'])
|
||||||
|
|
||||||
|
Route.resource('/files', 'FileController').only(['index', 'store', 'destroy'])
|
||||||
|
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.get('/', 'FileController.index')
|
Route.get('/', 'FileController.index')
|
||||||
Route.get('/:filename', async ({response, params}) => {
|
Route.get('/:filename', async ({response, params}) => {
|
||||||
response.download(Application.makePath('storage', params.filename))
|
response.download(Application.makePath('storage', params.filename))
|
||||||
})
|
})
|
||||||
}).prefix('/files')
|
}).prefix('/files')
|
||||||
|
|
||||||
}).middleware('auth')
|
}).middleware('auth')
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import Route from "@ioc:Adonis/Core/Route";
|
import Route from "@ioc:Adonis/Core/Route";
|
||||||
|
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.post('/form', 'FormsController.send')
|
Route.resource('/form', 'FormsController').except(['edit', 'create', 'update'])
|
||||||
|
|
||||||
|
Route.resource('/announces', 'AnnouncesController').except(['edit', 'create'])
|
||||||
|
|
||||||
|
Route.resource('/projects', 'ProjectsController').except(['edit', 'create'])
|
||||||
|
|
||||||
|
Route.resource('/profile', 'ProfilesController').only(['index', 'update'])
|
||||||
|
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.get('/:slug', 'PostsController.getLikes')
|
Route.get('/:slug', 'PostsController.getLikes')
|
||||||
Route.post('/:slug/like', 'PostsController.like')
|
Route.post('/:slug/like', 'PostsController.like')
|
||||||
Route.post('/:slug/unlike', 'PostsController.unlike')
|
Route.post('/:slug/unlike', 'PostsController.unlike')
|
||||||
}).prefix('/posts')
|
}).prefix('/posts')
|
||||||
Route.get('/subscribers', 'SubscribersController.get')
|
|
||||||
Route.post('/subscribers', 'SubscribersController.store')
|
Route.resource('/subscribers', 'SubscribersController').only(['index', 'store', 'destroy'])
|
||||||
Route.delete('/subscribers', 'SubscribersController.delete')
|
|
||||||
Route.get('/guestbook', 'GuestBookController.index')
|
Route.resource('/guestbook', 'GuestBookController').except(['edit', 'create', 'destroy'])
|
||||||
Route.post('/guestbook', 'GuestBookController.store')
|
Route.get('/guestbook/:email', 'GuestBookController.exists')
|
||||||
Route.post('/guestbook/:email', 'GuestBookController.store')
|
|
||||||
}).middleware('auth')
|
}).middleware('auth')
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ Route.get('/', async ({response}: HttpContextContract) => {
|
|||||||
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}/me`,
|
||||||
//stats: `${BASE_URL}/stats`,
|
//stats: `${BASE_URL}/stats`,
|
||||||
states: `${BASE_URL}/states`,
|
|
||||||
locations: `${BASE_URL}/locations`,
|
locations: `${BASE_URL}/locations`,
|
||||||
projects: `${BASE_URL}/projects`
|
projects: `${BASE_URL}/projects`
|
||||||
}
|
}
|
||||||
@@ -36,8 +35,4 @@ Route.get('/health', async ({response}: HttpContextContract) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Route.get('/profile', 'ProfileController.me')
|
|
||||||
Route.get('/locations', 'LocationsController.get')
|
|
||||||
Route.get('/stats', 'StatsController.get')
|
Route.get('/stats', 'StatsController.get')
|
||||||
Route.get('/states', 'StatesController.get')
|
|
||||||
Route.get('/projects', 'ProjectsController.get')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user