Skip to content

Commit eaeec47

Browse files
committed
UPdate new allauth settings
1 parent 1c7c0f9 commit eaeec47

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

user/serializers.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from allauth.account.adapter import get_adapter
2+
from allauth.account.models import EmailAddress
23
from allauth.account.utils import setup_user_email
3-
from allauth.utils import email_address_exists
44
from django.contrib.auth import authenticate, get_user_model
55
from django.core.mail import send_mail
66
from django.template.loader import render_to_string
@@ -106,10 +106,12 @@ def update(self, instance, validated_data):
106106

107107
# Update Profile
108108
# Nie všetky polia v modeloch User a Profile sú editovateľné cez API.
109-
instance.profile.nickname = profile_data.get(
110-
'nickname', instance.profile.nickname)
111109
instance.profile.phone = profile_data.get(
112110
'phone', instance.profile.phone)
111+
instance.profile.fisrt_name = profile_data.get(
112+
'first_name', instance.profile.first_name)
113+
instance.profile.last_name = profile_data.get(
114+
'last_name', instance.profile.last_name)
113115
instance.profile.parent_phone = profile_data.get(
114116
'parent_phone', instance.profile.parent_phone)
115117
instance.profile.gdpr = profile_data.get(
@@ -121,13 +123,17 @@ def update(self, instance, validated_data):
121123

122124
# User sa nikdy neupdatuje preto nie je potrebné volať instance.save()
123125
instance.profile.save()
124-
self.handle_other_school(validated_data.pop('new_school_description'))
126+
instance.save()
127+
self.handle_other_school(validated_data.pop(
128+
'new_school_description', None))
125129
return instance
126130

127131
def handle_other_school(self, school):
128132
'''
129133
Ak je zadana skola "ina skola" tak posle o tom mail.
130134
'''
135+
if school is None:
136+
return
131137
if school.code == self.OTHER_SCHOOL_CODE:
132138
email = self.validated_data['email']
133139
first_name = self.validated_data['profile']['first_name']
@@ -169,7 +175,7 @@ class Meta:
169175

170176
def validate_email(self, email):
171177
email = get_adapter().clean_email(email)
172-
if email and email_address_exists(email):
178+
if email and EmailAddress.objects.filter(email__iexact=email).exists():
173179
raise serializers.ValidationError(
174180
"Používateľ s danou emailovou adresou už existuje.")
175181
return email
@@ -215,7 +221,6 @@ def save(self, request):
215221
Profile.objects.create(user=user,
216222
first_name=profile_data['first_name'],
217223
last_name=profile_data['last_name'],
218-
nickname=profile_data['nickname'],
219224
school=profile_data['school'],
220225
year_of_graduation=grade.get_year_of_graduation_by_date(),
221226
phone=profile_data['phone'],
@@ -226,27 +231,3 @@ def save(self, request):
226231
setup_user_email(request, user, [])
227232

228233
return user
229-
230-
def handle_other_school(self, school):
231-
'''
232-
Ak je zadana skola "ina skola" tak posle o tom mail.
233-
'''
234-
if school.code == self.OTHER_SCHOOL_CODE:
235-
email = self.validated_data['email']
236-
first_name = self.validated_data['profile']['first_name']
237-
last_name = self.validated_data['profile']['last_name']
238-
school_info = self.validated_data['new_school_description']
239-
send_mail(
240-
'Žiadosť o pridanie novej školy',
241-
render_to_string(
242-
'user/emails/new_school_request.txt',
243-
{
244-
'email': email,
245-
'first_name': first_name,
246-
'last_name': last_name,
247-
'school_info': school_info
248-
},
249-
),
250-
EMAIL_NO_REPLY,
251-
[EMAIL_ALERT]
252-
)

user/urls.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
app_name = 'user'
44

5-
urlpatterns = [
6-
path('', include('dj_rest_auth.urls')),
7-
path('registration/', include('dj_rest_auth.registration.urls')),
8-
]
5+
urlpatterns = [path('', include('dj_rest_auth.urls')),
6+
path('registration/', include('dj_rest_auth.registration.urls')),
7+
]

webstrom/settings.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@
147147

148148
REST_SESSION_LOGIN = True
149149

150-
REST_AUTH_SERIALIZERS = {
151-
'LOGIN_SERIALIZER': 'user.serializers.LoginSerializer',
152-
'USER_DETAILS_SERIALIZER': 'user.serializers.UserDetailsSerializer'
153-
}
154150

155-
REST_AUTH_REGISTER_SERIALIZERS = {
151+
REST_AUTH = {
152+
'LOGIN_SERIALIZER': 'user.serializers.LoginSerializer',
153+
'USER_DETAILS_SERIALIZER': 'user.serializers.UserDetailsSerializer',
156154
'REGISTER_SERIALIZER': 'user.serializers.RegisterSerializer'
157155
}
158156

0 commit comments

Comments
 (0)