Forráskód Böngészése

Change location filed type and added registration mechanism

Mohidul Islam 4 éve
szülő
commit
6fac0ac94f
4 módosított fájl, 32 hozzáadás és 7 törlés
  1. 18 0
      gauth/migrations/0014_auto_20200825_0954.py
  2. 1 1
      gauth/models.py
  3. 3 1
      user/admin.py
  4. 10 5
      user/views.py

+ 18 - 0
gauth/migrations/0014_auto_20200825_0954.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0.4 on 2020-08-25 09:54
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('gauth', '0013_auto_20200727_0612'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='location',
+            name='recipient_email',
+            field=models.EmailField(blank=True, max_length=254, null=True),
+        ),
+    ]

+ 1 - 1
gauth/models.py

@@ -19,7 +19,7 @@ class Location(models.Model):
     location_name = models.CharField(max_length=120)
     website_url = models.URLField()
     review_site_url = models.URLField(null=True, blank=True)
-    recipient_email = models.URLField(null=True, blank=True)
+    recipient_email = models.EmailField(null=True, blank=True)
     owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
 
     def __str__(self):

+ 3 - 1
user/admin.py

@@ -1,3 +1,5 @@
 from django.contrib import admin
+from .models import UserAccount
 
-# Register your models here.
+
+admin.site.register(UserAccount)

+ 10 - 5
user/views.py

@@ -2,6 +2,8 @@ from django.shortcuts import render, redirect
 from django.views.generic import View
 from django.contrib import messages
 from .forms import UserRegisterForm
+from .models import UserAccount
+from gauth.models import Location
 
 
 class RegistrationView(View):
@@ -14,10 +16,13 @@ class RegistrationView(View):
         form = UserRegisterForm(request.POST)
         if form.is_valid():
             email = form.cleaned_data.get('email')
-            username = form.cleaned_data.get('username')
-            print(email, username)
-
-            messages.success(request, f'Your account has been created! You are now able to log in')
-            return redirect('login')
+            location = Location.objects.filter(recipient_email=email).first()
+            if location:
+                user = form.save()
+                UserAccount.objects.create(user=user, location=location)
+                messages.success(request, f'Your account has been created! You are now able to log in')
+                return redirect('login')
+            else:
+                messages.warning(request, f'Sorry, We don\'t have any location with this email!')
 
         return render(request, 'signup.html', {'form': form})