core: simplified login and register, fix: me
This commit is contained in:
parent
1f41e62a86
commit
b5d73e59fd
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user