fix, add auto login when register
This commit is contained in:
parent
25f315c24f
commit
910644a804
@ -3,6 +3,7 @@ from ..serializers.register import RegisterSerialiser
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from django.http import HttpRequest
|
||||
from django.contrib.auth import login
|
||||
|
||||
class RegisterView(APIView):
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
@ -12,5 +13,6 @@ class RegisterView(APIView):
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
user = serializer.create(data)
|
||||
if user:
|
||||
login(request, user)
|
||||
return Response("user created", status=status.HTTP_201_CREATED)
|
||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
@ -23,7 +23,13 @@ class Account
|
||||
let response = await this.client._delete("/api/accounts/delete", {password: password});
|
||||
let response_data = await response.json();
|
||||
|
||||
if (response_data === "user deleted")
|
||||
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
||||
{
|
||||
this.client._logged = false;
|
||||
return null;
|
||||
}
|
||||
console.log(response_data)
|
||||
if (response_data == "user deleted")
|
||||
this.client._logged = false;
|
||||
return response_data;
|
||||
}
|
||||
@ -35,7 +41,7 @@ class Account
|
||||
|
||||
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
||||
{
|
||||
console.log("error, client is not logged");
|
||||
this.client._logged = false;
|
||||
return null;
|
||||
}
|
||||
return response_data;
|
||||
@ -43,13 +49,13 @@ class Account
|
||||
|
||||
async update(data, password)
|
||||
{
|
||||
data.password = password;
|
||||
data.current_password = password;
|
||||
let response = await this.client._patch_json("/api/accounts/edit", data);
|
||||
let response_data = await response.json();
|
||||
|
||||
if (JSON.stringify(response_data) == JSON.stringify({'detail': 'Authentication credentials were not provided.'}))
|
||||
{
|
||||
console.log("error, client is not logged");
|
||||
this.client._logged = false;
|
||||
return null;
|
||||
}
|
||||
return response_data;
|
||||
|
@ -4,8 +4,8 @@ function getCookie(name)
|
||||
{
|
||||
let cookie = {};
|
||||
document.cookie.split(';').forEach(function(el) {
|
||||
let split = el.split('=');
|
||||
cookie[split[0].trim()] = split.slice(1).join("=");
|
||||
let split = el.split('=');
|
||||
cookie[split[0].trim()] = split.slice(1).join("=");
|
||||
})
|
||||
return cookie[name];
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { client } from "../index.js";
|
||||
import AbstractAuthentificateView from "./AbstractAuthentifiedView.js";
|
||||
|
||||
export default class extends AbstractAuthentificateView {
|
||||
|
@ -20,6 +20,11 @@ export default class extends AbstractAuthentificateView
|
||||
{
|
||||
let data = await client.account.get();
|
||||
|
||||
if (data === null)
|
||||
{
|
||||
navigateTo("/login")
|
||||
return;
|
||||
}
|
||||
document.getElementById("username").value = data.username;
|
||||
}
|
||||
|
||||
@ -66,7 +71,12 @@ export default class extends AbstractAuthentificateView
|
||||
|
||||
if (response_data === null)
|
||||
{
|
||||
navigateTo(super.redirect_url);
|
||||
navigateTo("/login");
|
||||
return;
|
||||
}
|
||||
else if (response_data === "data has been alterate")
|
||||
{
|
||||
navigateTo("/me");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { client, navigateTo } from "../../index.js";
|
||||
import AbstractAuthentifiedView from "../AbstractNonAuthentified.js";
|
||||
import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js";
|
||||
|
||||
async function register()
|
||||
{
|
||||
@ -14,7 +14,6 @@ async function register()
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
["username", "user", "password"].forEach(error_field => {
|
||||
let error_display = document.getElementById(`error_${error_field}`);
|
||||
if (error_display != null)
|
||||
@ -28,7 +27,7 @@ async function register()
|
||||
});
|
||||
}
|
||||
|
||||
export default class extends AbstractAuthentifiedView {
|
||||
export default class extends AbstractNonAuthentifiedView {
|
||||
constructor(params) {
|
||||
super(params, "Register", "/home");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user