tentative de merge
This commit is contained in:
		| @ -1,10 +1,11 @@ | |||||||
| import { client, navigateTo } from "../../index.js"; | import { client, navigateTo } from "../../index.js"; | ||||||
|  | import { clear, fill_errors } from "../../utils/formUtils.js"; | ||||||
| import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js"; | import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js"; | ||||||
|  |  | ||||||
| async function login() | async function login() | ||||||
| { | { | ||||||
| 	let username = document.getElementById("username").value; | 	let username = document.getElementById("username-input").value; | ||||||
| 	let password = document.getElementById("password").value; | 	let password = document.getElementById("password-input").value; | ||||||
| 	 | 	 | ||||||
| 	let response_data = await client.login(username, password); | 	let response_data = await client.login(username, password); | ||||||
|  |  | ||||||
| @ -14,17 +15,8 @@ async function login() | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	["username", "user", "password"].forEach(error_field => { | 	clear("innerHTML", ["username", "user", "password"]); | ||||||
| 		let error_display = document.getElementById(`error_${error_field}`); | 	fill_errors(response_data, "innerHTML"); | ||||||
| 		if (error_display != null) |  | ||||||
| 			error_display.innerHTML = ""; |  | ||||||
| 	}); |  | ||||||
|  |  | ||||||
| 	Object.keys(response_data).forEach(error_field => { |  | ||||||
| 		let error_display = document.getElementById(`error_${error_field}`); |  | ||||||
| 		if (error_display != null) |  | ||||||
| 			error_display.innerHTML = response_data[error_field]; |  | ||||||
| 	}); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| export default class extends AbstractNonAuthentifiedView { | export default class extends AbstractNonAuthentifiedView { | ||||||
| @ -34,7 +26,7 @@ export default class extends AbstractNonAuthentifiedView { | |||||||
|  |  | ||||||
| 	async postInit() | 	async postInit() | ||||||
| 	{ | 	{ | ||||||
| 		document.getElementById("button").onclick = login; | 		document.getElementById("login-button").onclick = login; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|     async getHtml() { |     async getHtml() { | ||||||
| @ -42,12 +34,12 @@ export default class extends AbstractNonAuthentifiedView { | |||||||
| 			<div class=form> | 			<div class=form> | ||||||
| 				<label>Login</label> | 				<label>Login</label> | ||||||
| 				<link rel="stylesheet" href="/static/css/accounts/login.css"> | 				<link rel="stylesheet" href="/static/css/accounts/login.css"> | ||||||
| 				<input type="text" id="username" placeholder="username"> | 				<input type="text" id="username-input" placeholder="username"> | ||||||
| 				<span id="error_username"></span> | 				<span id="username"></span> | ||||||
| 				<input type="password" id="password" placeholder="password"> | 				<input type="password" id="password-input" placeholder="password"> | ||||||
| 				<span id="error_password"></span> | 				<span id="password"></span> | ||||||
| 				<input type="button" value="login" id="button"> | 				<input type="button" value="Login" id="login-button"> | ||||||
| 				<span id="error_user"></span> | 				<span id="user"></span> | ||||||
| 				<a href="/register" class="nav__link" data-link>Register</a> | 				<a href="/register" class="nav__link" data-link>Register</a> | ||||||
| 			</div> | 			</div> | ||||||
|         `; |         `; | ||||||
|  | |||||||
| @ -14,17 +14,8 @@ async function register() | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	["username", "user", "password"].forEach(error_field => { | 	clear("innerHTML", ["username", "user", "password"]); | ||||||
| 		let error_display = document.getElementById(`error_${error_field}`); | 	fill_errors(response_data, "innerHTML"); | ||||||
| 		if (error_display != null) |  | ||||||
| 			error_display.innerHTML = ""; |  | ||||||
| 	}); |  | ||||||
|  |  | ||||||
| 	Object.keys(response_data).forEach(error_field => { |  | ||||||
| 		let error_display = document.getElementById(`error_${error_field}`); |  | ||||||
| 		if (error_display != null) |  | ||||||
| 			error_display.innerHTML = response_data[error_field]; |  | ||||||
| 	}); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| export default class extends AbstractNonAuthentifiedView { | export default class extends AbstractNonAuthentifiedView { | ||||||
| @ -34,7 +25,7 @@ export default class extends AbstractNonAuthentifiedView { | |||||||
|  |  | ||||||
| 	async postInit() | 	async postInit() | ||||||
| 	{ | 	{ | ||||||
| 		document.getElementById("button").onclick = register; | 		document.getElementById("register-button").onclick = register; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|     async getHtml() { |     async getHtml() { | ||||||
| @ -42,12 +33,12 @@ export default class extends AbstractNonAuthentifiedView { | |||||||
| 			<div class=form> | 			<div class=form> | ||||||
| 				<label>Register</label> | 				<label>Register</label> | ||||||
| 				<link rel="stylesheet" href="/static/css/accounts/register.css"> | 				<link rel="stylesheet" href="/static/css/accounts/register.css"> | ||||||
| 				<input type="text" id="username" placeholder="username"> | 				<input type="text" id="username-input" placeholder="username"> | ||||||
| 				<span id="error_username"></span> | 				<span id="username"></span> | ||||||
| 				<input type="password" id="password" placeholder="password"> | 				<input type="password" id="password-input" placeholder="password"> | ||||||
| 				<span id="error_password"></span> | 				<span id="password"></span> | ||||||
| 				<input type="button" value="register" id="button"> | 				<input type="button" value="Register" id="register-button"> | ||||||
| 				<span id="error_user"></span> | 				<span id="user"></span> | ||||||
| 				<a href="/login" class="nav__link" data-link>Login</a> | 				<a href="/login" class="nav__link" data-link>Login</a> | ||||||
| 			</div> | 			</div> | ||||||
|         `; |         `; | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ from rest_framework.parsers import MultiPartParser, FormParser | |||||||
| from rest_framework import permissions, status | from rest_framework import permissions, status | ||||||
| from rest_framework import viewsets | from rest_framework import viewsets | ||||||
| from rest_framework.response import Response | from rest_framework.response import Response | ||||||
|  | from rest_framework.authentication import SessionAuthentication | ||||||
|  |  | ||||||
| from django.http import HttpRequest | from django.http import HttpRequest | ||||||
| from django.db.models import QuerySet | from django.db.models import QuerySet | ||||||
| @ -33,6 +34,8 @@ class ProfileViewSet(viewsets.ModelViewSet): | |||||||
|  |  | ||||||
| class MyProfileViewSet(viewsets.ModelViewSet): | class MyProfileViewSet(viewsets.ModelViewSet): | ||||||
|  |  | ||||||
|  |     permission_classes = (permissions.IsAuthenticated,) | ||||||
|  |     authentication_classes = (SessionAuthentication,) | ||||||
|     serializer_class = ProfileSerializer |     serializer_class = ProfileSerializer | ||||||
|     queryset = ProfileModel.objects.all |     queryset = ProfileModel.objects.all | ||||||
|  |  | ||||||
| @ -54,4 +57,4 @@ class MyProfileViewSet(viewsets.ModelViewSet): | |||||||
|         instance: ProfileModel = self.get_object() |         instance: ProfileModel = self.get_object() | ||||||
|         instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:] |         instance.avatar_url.name = instance.avatar_url.name[instance.avatar_url.name.find("static") - 1:] | ||||||
|         return Response(self.serializer_class(instance).data, |         return Response(self.serializer_class(instance).data, | ||||||
|                         status=status.HTTP_200_OK) |                         status=status.HTTP_200_OK) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user