mirror of
https://github.com/arthur-pbty/portfolio2023.git
synced 2026-06-24 14:18:36 +02:00
add profile picture
This commit is contained in:
@@ -27,10 +27,15 @@ export default class AuthController {
|
||||
return view.render('auth/signup')
|
||||
}
|
||||
|
||||
async doSignup({ request, response }: HttpContextContract) {
|
||||
async doSignup({ request, response, auth }: HttpContextContract) {
|
||||
const playload = await request.validate(CreateUserValidator)
|
||||
await User.create(playload)
|
||||
return response.redirect().toRoute('home')
|
||||
try {
|
||||
await auth.use('web').attempt(playload.email, playload.password)
|
||||
response.redirect().toRoute('home')
|
||||
} catch {
|
||||
response.redirect().toRoute('login')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,4 +30,11 @@ export default class CompteController {
|
||||
response.redirect().back()
|
||||
}
|
||||
|
||||
async delete({ auth, response }: HttpContextContract) {
|
||||
const user = auth.user
|
||||
await user!.delete()
|
||||
await auth.logout()
|
||||
response.redirect().toRoute('home')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class AuthMiddleware {
|
||||
/**
|
||||
* The URL to redirect to when request is Unauthorized
|
||||
*/
|
||||
protected redirectTo = '/login'
|
||||
protected redirectTo = 'auth/login'
|
||||
|
||||
/**
|
||||
* Authenticates the current HTTP request against a custom set of defined
|
||||
|
||||
+13
-1
@@ -1,6 +1,7 @@
|
||||
import { DateTime } from 'luxon'
|
||||
import Hash from '@ioc:Adonis/Core/Hash'
|
||||
import { column, beforeSave, BaseModel } from '@ioc:Adonis/Lucid/Orm'
|
||||
import { column, beforeSave, BaseModel, computed } from '@ioc:Adonis/Lucid/Orm'
|
||||
import { responsiveAttachment, ResponsiveAttachmentContract } from '@ioc:Adonis/Addons/ResponsiveAttachment'
|
||||
|
||||
export default class User extends BaseModel {
|
||||
@column({ isPrimary: true })
|
||||
@@ -24,6 +25,17 @@ export default class User extends BaseModel {
|
||||
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
||||
public updatedAt: DateTime
|
||||
|
||||
@responsiveAttachment({ preComputeUrls: true })
|
||||
public avatar: ResponsiveAttachmentContract
|
||||
|
||||
@computed()
|
||||
public get avatarUrl() {
|
||||
if (this.avatar) {
|
||||
return '/uploads/'+this.avatar.breakpoints!.small.name
|
||||
}
|
||||
return 'https://source.boringavatars.com/beam/40/${this.email}?colors=001449,012677,005BC5,00B4FC,17F9FF'
|
||||
}
|
||||
|
||||
@beforeSave()
|
||||
public static async hashPassword (user: User) {
|
||||
if (user.$dirty.password) {
|
||||
|
||||
Reference in New Issue
Block a user