Create account.register function. It's currently not working because arguments is not validating

This commit is contained in:
vlados31 2022-09-17 22:03:31 +03:00
parent 58a19c7a41
commit 22da68b953
3 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponseRedirect
from .forms import SiteUserForm
from django.contrib.auth import login, authenticate

View File

@ -17,6 +17,9 @@ API_ERROR_INVALID_LOGIN = (501, 'invalid login')
API_ERROR_INVALID_PASSWORD = (502, 'invalid password')
API_ERROR_INVALID_TOKEN = (503, 'invalid token')
# времненное решение, позже нужно будет заменить на конкретные ошибки
API_ERROR_USER_REGISTER = (510, 'user register error')
def make_error_object(ex: Exception):
try:

View File

@ -1,6 +1,7 @@
from .api_errors import *
from .api_utils import *
from .models import *
from account.forms import UserCreationForm
def _reqire_access_token(params):
@ -22,7 +23,26 @@ def account_auth(params):
def account_register(params):
name = api_get_param_str(params, "name")
surname = api_get_param_str(params, "surname")
phone = api_get_param_str(params, "phone")
email = api_get_param_str(params, "email")
password = api_get_param_str(params, "password")
form = UserCreationForm({
"email": email,
"phone": phone,
"name": name,
"surname": surname,
"password1": password,
"password2": password,
})
form.validate_unique()
if form.is_valid():
pass
else:
raise Exception(API_ERROR_MISSING_ARGUMENT)
def account_get(params):