mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
Fix account
This commit is contained in:
parent
927e46dfee
commit
4ab45b4347
@ -3,9 +3,14 @@ from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class RegisterForm(UserCreationForm):
|
||||
email = forms.EmailField(required=True)
|
||||
class SignUpForm(UserCreationForm):
|
||||
email = forms.EmailField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["username", "email", "password1", "password2"]
|
||||
fields = (
|
||||
"username",
|
||||
"email",
|
||||
"password1",
|
||||
"password2",
|
||||
)
|
||||
|
||||
0
FOSSDB/apps/account/models.py
Normal file
0
FOSSDB/apps/account/models.py
Normal file
@ -3,7 +3,6 @@ from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.sign_up, name="singup"),
|
||||
path("signup", views.sign_up, name="signup"),
|
||||
path("login", views.login_, name="login"),
|
||||
path("signup/", views.signup_view, name="signup"),
|
||||
path("login/", views.login_view, name="login"),
|
||||
]
|
||||
|
||||
@ -1,20 +1,40 @@
|
||||
from django.contrib.auth import login
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from .forms import RegisterForm
|
||||
from .forms import SignUpForm
|
||||
|
||||
|
||||
def sign_up(request):
|
||||
def signup_view(request):
|
||||
form = SignUpForm(request.POST or None)
|
||||
if request.method == "POST":
|
||||
form = RegisterForm(request.POST)
|
||||
if form.is_valid():
|
||||
user = form.save()
|
||||
raw_password = form.cleaned_data.get("password1")
|
||||
user = authenticate(
|
||||
username=user.username,
|
||||
password=raw_password,
|
||||
)
|
||||
login(request, user)
|
||||
return redirect("")
|
||||
else:
|
||||
form = RegisterForm()
|
||||
return render(request, "registration/sign_up.html", {"title": "Sign Up", "form": form})
|
||||
return redirect("index")
|
||||
|
||||
context = {
|
||||
"title": "Sign Up",
|
||||
"form": form,
|
||||
}
|
||||
return render(request, "registration/signup.html", context)
|
||||
|
||||
|
||||
def login_(request):
|
||||
return render(request, "registration/login.html", {"title": "Login"})
|
||||
def login_view(request):
|
||||
form = AuthenticationForm(data=request.POST or None)
|
||||
if request.method == "POST":
|
||||
if form.is_valid():
|
||||
user = form.get_user()
|
||||
login(request, user)
|
||||
return redirect("index")
|
||||
|
||||
context = {
|
||||
"title": "Login",
|
||||
"form": form,
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user