mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 07:21:35 +01:00
Add OAuth
This commit is contained in:
@@ -60,4 +60,55 @@ export default class AuthController {
|
||||
return { user }
|
||||
}
|
||||
|
||||
public async twitter ({ally, auth}: HttpContextContract) {
|
||||
const twitter = ally.use('twitter')
|
||||
const twitterUser = await twitter.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: twitterUser.email,
|
||||
}, {
|
||||
email: twitterUser.email,
|
||||
username: twitterUser.name,
|
||||
isConfirmed: twitterUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
await auth.use('web').login(user)
|
||||
|
||||
return { user }
|
||||
}
|
||||
|
||||
public async github ({ally, auth}: HttpContextContract) {
|
||||
const github = ally.use('github')
|
||||
const githubUser = await github.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: githubUser.email,
|
||||
}, {
|
||||
email: githubUser.email,
|
||||
username: githubUser.name,
|
||||
isConfirmed: githubUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
await auth.use('web').login(user)
|
||||
|
||||
return { user }
|
||||
}
|
||||
|
||||
public async google ({ally, auth}: HttpContextContract) {
|
||||
const google = ally.use('google')
|
||||
const googleUser = await google.user()
|
||||
|
||||
const user = await User.firstOrCreate({
|
||||
email: googleUser.email,
|
||||
}, {
|
||||
email: googleUser.email,
|
||||
username: googleUser.name,
|
||||
isConfirmed: googleUser.emailVerificationState === 'verified'
|
||||
})
|
||||
|
||||
await auth.use('web').login(user)
|
||||
|
||||
return { user }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
20
app/Controllers/Http/GoldenMessagesController.ts
Normal file
20
app/Controllers/Http/GoldenMessagesController.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import GoldenMessage from "../../Models/GoldenMessage";
|
||||
import StoreValidator from "../../Validators/goldenmessages/StoreValidator";
|
||||
|
||||
export default class GoldenMessagesController {
|
||||
|
||||
public async index () {
|
||||
return GoldenMessage.query().orderBy('created_at', 'desc')
|
||||
}
|
||||
|
||||
public async store ({request}: HttpContextContract) {
|
||||
const data = await request.validate(StoreValidator)
|
||||
return await GoldenMessage.create(data)
|
||||
}
|
||||
|
||||
public async show ({params}: HttpContextContract) {
|
||||
return await GoldenMessage.findOrFail(params.id)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user