mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-19 04:49:37 +02:00
Toggle public profile from settings page.
This commit is contained in:
parent
c867494a17
commit
4d17484f86
4 changed files with 32 additions and 4 deletions
|
@ -142,7 +142,7 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
|||
return username
|
||||
|
||||
class Meta:
|
||||
extra_fields = ['profile_pic']
|
||||
extra_fields = ['profile_pic', 'uuid', 'public_profile']
|
||||
profile_pic = serializers.ImageField(required=False)
|
||||
# see https://github.com/iMerica/dj-rest-auth/issues/181
|
||||
# UserModel.XYZ causing attribute error while importing other
|
||||
|
@ -160,10 +160,12 @@ class UserDetailsSerializer(serializers.ModelSerializer):
|
|||
extra_fields.append('date_joined')
|
||||
if hasattr(UserModel, 'is_staff'):
|
||||
extra_fields.append('is_staff')
|
||||
if hasattr(UserModel, 'public_profile'):
|
||||
extra_fields.append('public_profile')
|
||||
|
||||
class Meta(UserDetailsSerializer.Meta):
|
||||
model = CustomUser
|
||||
fields = UserDetailsSerializer.Meta.fields + ('profile_pic',)
|
||||
fields = UserDetailsSerializer.Meta.fields + ('profile_pic', 'uuid', 'public_profile')
|
||||
|
||||
model = UserModel
|
||||
fields = ('pk', *extra_fields)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
export let appVersion = 'Web v0.6.0';
|
||||
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.5.2';
|
||||
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.6.0';
|
||||
export let appTitle = 'AdventureLog';
|
||||
export let copyrightYear = '2024';
|
||||
// config for the frontend
|
||||
|
|
|
@ -45,6 +45,7 @@ export const actions: Actions = {
|
|||
let first_name = formData.get('first_name') as string | null | undefined;
|
||||
let last_name = formData.get('last_name') as string | null | undefined;
|
||||
let profile_pic = formData.get('profile_pic') as File | null | undefined;
|
||||
let public_profile = formData.get('public_profile') as string | null | undefined | boolean;
|
||||
|
||||
const resCurrent = await fetch(`${endpoint}/auth/user/`, {
|
||||
headers: {
|
||||
|
@ -56,6 +57,13 @@ export const actions: Actions = {
|
|||
return fail(resCurrent.status, await resCurrent.json());
|
||||
}
|
||||
|
||||
if (public_profile === 'on') {
|
||||
public_profile = true;
|
||||
} else {
|
||||
public_profile = false;
|
||||
}
|
||||
console.log(public_profile);
|
||||
|
||||
let currentUser = (await resCurrent.json()) as User;
|
||||
|
||||
if (username === currentUser.username || !username) {
|
||||
|
@ -84,6 +92,7 @@ export const actions: Actions = {
|
|||
if (profile_pic) {
|
||||
formDataToSend.append('profile_pic', profile_pic);
|
||||
}
|
||||
formDataToSend.append('public_profile', public_profile.toString());
|
||||
|
||||
let res = await fetch(`${endpoint}/auth/user/`, {
|
||||
method: 'PATCH',
|
||||
|
|
|
@ -111,6 +111,24 @@
|
|||
id="profile_pic"
|
||||
class="file-input file-input-bordered w-full max-w-xs mb-2"
|
||||
/><br />
|
||||
<div class="form-control">
|
||||
<div
|
||||
class="tooltip tooltip-info"
|
||||
data-tip="With a public profile, users can share collections with you and view your profile on the users page."
|
||||
>
|
||||
<label class="label cursor-pointer">
|
||||
<span class="label-text">Public Profile</span>
|
||||
|
||||
<input
|
||||
id="public_profile"
|
||||
name="public_profile"
|
||||
type="checkbox"
|
||||
class="toggle"
|
||||
checked={user.public_profile}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<button class="py-2 mt-2 px-4 btn btn-primary">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue