mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 20:19:26 +01:00
Working and fixing form
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from "App/Models/User";
|
||||
import AuthValidator from "App/Validators/AuthValidator";
|
||||
import {AllyUserContract} from "@ioc:Adonis/Addons/Ally";
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
@@ -54,61 +55,82 @@ export default class AuthController {
|
||||
|
||||
public async user ({auth}: HttpContextContract) {
|
||||
await auth.authenticate()
|
||||
const user = await User.query()
|
||||
return await User.query()
|
||||
.where('id', auth.user!.id)
|
||||
.firstOrFail()
|
||||
return { user }
|
||||
}
|
||||
|
||||
public async twitter ({ally, auth}: HttpContextContract) {
|
||||
const twitter = ally.use('twitter')
|
||||
|
||||
if (twitter.accessDenied()) {
|
||||
return 'Access Denied'
|
||||
}
|
||||
|
||||
if (twitter.stateMisMatch()) {
|
||||
return 'Request expired. Retry again'
|
||||
}
|
||||
|
||||
if (twitter.hasError()) {
|
||||
return twitter.getError()
|
||||
}
|
||||
|
||||
const twitterUser = await twitter.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: twitterUser.email,
|
||||
}, {
|
||||
email: twitterUser.email,
|
||||
username: twitterUser.name,
|
||||
isConfirmed: twitterUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
const user = await this.createUser(twitterUser)
|
||||
await auth.use('web').login(user)
|
||||
|
||||
return { user }
|
||||
return user
|
||||
}
|
||||
|
||||
public async github ({ally, auth}: HttpContextContract) {
|
||||
const github = ally.use('github')
|
||||
|
||||
if (github.accessDenied()) {
|
||||
return 'Access Denied'
|
||||
}
|
||||
|
||||
if (github.stateMisMatch()) {
|
||||
return 'Request expired. Retry again'
|
||||
}
|
||||
|
||||
if (github.hasError()) {
|
||||
return github.getError()
|
||||
}
|
||||
|
||||
const githubUser = await github.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: githubUser.email,
|
||||
}, {
|
||||
email: githubUser.email,
|
||||
username: githubUser.name,
|
||||
isConfirmed: githubUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
const user = await this.createUser(githubUser)
|
||||
await auth.use('web').login(user)
|
||||
|
||||
return { user }
|
||||
return user
|
||||
}
|
||||
|
||||
public async google ({ally, auth}: HttpContextContract) {
|
||||
const google = ally.use('google')
|
||||
|
||||
if (google.accessDenied()) {
|
||||
return 'Access Denied'
|
||||
}
|
||||
|
||||
if (google.stateMisMatch()) {
|
||||
return 'Request expired. Retry again'
|
||||
}
|
||||
|
||||
if (google.hasError()) {
|
||||
return google.getError()
|
||||
}
|
||||
|
||||
const googleUser = await google.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: googleUser.email,
|
||||
}, {
|
||||
email: googleUser.email,
|
||||
username: googleUser.name,
|
||||
isConfirmed: googleUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
const user = await this.createUser(googleUser)
|
||||
await auth.use('web').login(user)
|
||||
return user
|
||||
}
|
||||
|
||||
return { 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,7 +1,7 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormValidator from "App/Validators/FormValidator";
|
||||
import Form from "App/Models/Form";
|
||||
import FormConfirmation from "App/Mailers/FormConfirmation";
|
||||
//import FormConfirmation from "App/Mailers/FormConfirmation";
|
||||
|
||||
export default class FormsController {
|
||||
|
||||
@@ -10,7 +10,7 @@ export default class FormsController {
|
||||
|
||||
await Form.create(data)
|
||||
|
||||
await new FormConfirmation(data.name, data.email).sendLater()
|
||||
//await new FormConfirmation(data.name, data.email).sendLater()
|
||||
//todo send confirmation email + email to me
|
||||
return response.status(200).send({
|
||||
status: 200
|
||||
|
||||
Reference in New Issue
Block a user