Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ website/db.sqlit
.venv
env/
myEnv/
myenv/
venv/
ENV/
env.bak/
Expand Down
64 changes: 50 additions & 14 deletions website/user_profile/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,43 @@
from user_profile.utils import LowerEmailField


# class RegistrationSerializer(serializers.ModelSerializer):
# password2 = serializers.CharField(style={'input_type': 'password'}, write_only=True)
# email = LowerEmailField(
# required=True,
# allow_blank=False,
# label='Email address',
# max_length=30,
# validators=[UniqueValidator(queryset=User.objects.all())],
# )

# class Meta:
# model = User
# fields = ['username', 'email', 'password', 'password2']
# extra_kwargs = {
# 'password': {'write_only': True}
# }

# def save(self):
# password = self.validated_data['password']
# password2 = self.validated_data['password2']
# if password != password2:
# raise serializers.ValidationError({'confirm_password': 'Passwords must match!'})
# account = User(
# username=self.validated_data['username'],
# email=self.validated_data['email'].lower(),
# is_active=False # TO BE CHANGED TO FALSE
# )
# account.set_password(password)
# account.save()
# return account

class RegistrationSerializer(serializers.ModelSerializer):
password2 = serializers.CharField(style={'input_type': 'password'}, write_only=True)
password2 = serializers.CharField(write_only=True)

email = LowerEmailField(
required=True,
allow_blank=False,
label='Email address',
max_length=30,
validators=[UniqueValidator(queryset=User.objects.all())],
)
Expand All @@ -23,19 +54,24 @@ class Meta:
'password': {'write_only': True}
}

def save(self):
password = self.validated_data['password']
password2 = self.validated_data['password2']
if password != password2:
raise serializers.ValidationError({'confirm_password': 'Passwords must match!'})
account = User(
username=self.validated_data['username'],
email=self.validated_data['email'].lower(),
is_active=False # TO BE CHANGED TO FALSE
def validate(self, attrs):
if attrs['password'] != attrs['password2']:
raise serializers.ValidationError({
'password2': 'Passwords must match!'
})
return attrs

def create(self, validated_data):
validated_data.pop('password2')

user = User.objects.create_user(
username=validated_data['username'],
email=validated_data['email'].lower(),
password=validated_data['password'],
is_active=False
)
account.set_password(password)
account.save()
return account
return user



class UserSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion website/user_profile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def activate(request, uidb64, token, backend='django.contrib.auth.backends.Model
profile.save()

if profile.user == request.user:
return redirect('user_profile:edit_profile')
return redirect('http://localhost:3000/login')
return redirect('user_profile:edit_profile')
else:
return render(request, 'account_activation_invalid.html')
Expand Down
8 changes: 7 additions & 1 deletion website/website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@

ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='127.0.0.1,localhost', cast=Csv())

CORS_ALLOW_ALL_ORIGINS = True
# CORS_ALLOW_ALL_ORIGINS = True

CORS_ALLOWED_ORIGINS = [
"http://localhost:3000"
]

CORS_ALLOW_CREDENTIALS = True

# Application definition

Expand Down