mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Remove GuestBook
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from "App/Models/User";
|
||||
import {AllyUserContract} from "@ioc:Adonis/Addons/Ally";
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
@@ -42,132 +41,4 @@ export default class AuthController {
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async twitter ({ ally, auth, response }: HttpContextContract) {
|
||||
const twitter = ally.use('twitter')
|
||||
|
||||
if (twitter.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (twitter.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (twitter.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: twitter.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const twitterUser = await twitter.user()
|
||||
const user = await this.createUser(twitterUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async discord ({ ally, auth, response }: HttpContextContract) {
|
||||
const discord = ally.use('discord')
|
||||
|
||||
if (discord.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (discord.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (discord.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: discord.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const discordUser = await discord.user()
|
||||
const user = await this.createUser(discordUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async github ({ ally, auth, response }: HttpContextContract) {
|
||||
const github = ally.use('github').stateless()
|
||||
|
||||
if (github.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (github.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (github.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: github.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const githubUser = await github.user()
|
||||
const user = await this.createUser(githubUser)
|
||||
const authUser: User = await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
authUser: authUser,
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async google ({ ally, auth, response, }: HttpContextContract) {
|
||||
const google = ally.use('google')
|
||||
|
||||
if (google.accessDenied()) {
|
||||
return response.status(403).send({
|
||||
message: 'Access Denied!'
|
||||
})
|
||||
}
|
||||
|
||||
if (google.stateMisMatch()) {
|
||||
return response.status(405).send({
|
||||
message: 'Request expired. Retry again!'
|
||||
})
|
||||
}
|
||||
|
||||
if (google.hasError()) {
|
||||
return response.status(500).send({
|
||||
message: google.getError()
|
||||
})
|
||||
}
|
||||
|
||||
const googleUser = await google.user()
|
||||
const user = await this.createUser(googleUser)
|
||||
await auth.use('web').login(user, true)
|
||||
return response.status(200).send({
|
||||
user: user
|
||||
})
|
||||
}
|
||||
|
||||
public async createUser (allyUser: AllyUserContract<any>): Promise<User> {
|
||||
return await User.firstOrCreate({
|
||||
email: allyUser.email!,
|
||||
}, {
|
||||
email: allyUser.email!,
|
||||
username: allyUser.name,
|
||||
isConfirmed: allyUser.emailVerificationState === 'verified'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import GuestValidator from "App/Validators/guestbook/GuestValidator";
|
||||
import GuestbookMessage from "App/Models/GuestbookMessage";
|
||||
import User from "App/Models/User";
|
||||
|
||||
export default class GuestBookController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const guestbook_messages = await GuestbookMessage
|
||||
.query()
|
||||
.preload('user')
|
||||
.orderBy('created_at', 'desc')
|
||||
return response.status(200).send({
|
||||
guestbook_messages
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(GuestValidator)
|
||||
let user = await User.findByOrFail('email', data.email)
|
||||
const guestbook_message = user.related('guestbook_message').updateOrCreate({
|
||||
userId: user.id,
|
||||
message: data.message
|
||||
}, {
|
||||
userId: user.id,
|
||||
message: data.message
|
||||
})
|
||||
return response.status(200).send({
|
||||
guestbook_message
|
||||
})
|
||||
}
|
||||
|
||||
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 guestbook_message = await GuestbookMessage.findBy('email', email)
|
||||
return response.status(200).send({
|
||||
signed: guestbook_message !== null
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user