Skip to content

Commit

Permalink
feat: il est possible de modifier son nom
Browse files Browse the repository at this point in the history
fixes Il est possible de voir la révision déployée sur le site #7
  • Loading branch information
bachrc committed Oct 23, 2024
1 parent 1469bce commit adec441
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pb_migrations/1729661829_updated_users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("_pb_users_auth_")

collection.updateRule = "id = @request.auth.id && @request.data.username:isset = true && @request.data.verified:isset = false"

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("_pb_users_auth_")

collection.updateRule = "id = @request.auth.id"

return dao.saveCollection(collection)
})
16 changes: 16 additions & 0 deletions pb_migrations/1729662081_updated_users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("_pb_users_auth_")

collection.updateRule = "id = @request.auth.id && @request.data.username:isset = false && @request.data.verified:isset = false"

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("_pb_users_auth_")

collection.updateRule = "id = @request.auth.id && @request.data.username:isset = true && @request.data.verified:isset = false"

return dao.saveCollection(collection)
})
10 changes: 9 additions & 1 deletion src/routes/profil/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<script lang="ts">
import { pb } from '$lib/database';
import { currentUser } from '$lib/login.svelte';
import ChampEditable from '../../components/ChampEditable.svelte';
async function majNom(nouveau_nom: string) {
await pb.collection('users').update(currentUser.value.id, {
name: nouveau_nom
});
}
</script>

<div class="p-2">
<h1 class="text-2xl">Profil</h1>
<div class="flex flex-col gap-4">
<div class="flex flex-col">
<span class="text-xs font-bold">Nom</span>
<span>{currentUser.value?.name}</span>
<ChampEditable type="text" valeur={currentUser.value?.name} onupdate={majNom} />
</div>
<div class="flex flex-col">
<span class="text-xs font-bold">Pseudonyme</span>
Expand Down

0 comments on commit adec441

Please sign in to comment.