-
Notifications
You must be signed in to change notification settings - Fork 0
Room passwords #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
7d8daad
a4293f1
9783d2d
bb2df5b
73ede4b
84dc044
4ef5167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 3.0.6 on 2020-05-20 17:23 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('chatter', '0004_auto_20200519_1651'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='room', | ||
| name='password_hash', | ||
| field=models.CharField(blank=True, default='', max_length=255), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 3.0.6 on 2020-05-20 17:24 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('chatter', '0005_room_password_hash'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RenameField( | ||
| model_name='room', | ||
| old_name='password_hash', | ||
| new_name='password', | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Generated by Django 3.0.6 on 2020-05-20 21:48 | ||
|
|
||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ('chatter', '0006_auto_20200520_1724'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='entry', | ||
| name='author', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='entry', | ||
| name='room', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chatter.Room'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| from rest_framework import serializers | ||
| from rest_framework.renderers import JSONRenderer | ||
| from django.contrib.auth import hashers | ||
|
|
||
| from .models import Room, Entry | ||
|
|
||
| class RoomSerializer(serializers.HyperlinkedModelSerializer): | ||
| class Meta: | ||
| model = Room | ||
| fields = ['id', 'name'] | ||
| fields = ['id', 'name', 'password'] | ||
|
|
||
| def create(self, validated_data): | ||
| if 'password' in validated_data: | ||
| password_hash = hashers.make_password(validated_data['password']) | ||
| validated_data['password'] = password_hash | ||
| else: | ||
| validated_data['password'] = '' | ||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you had |
||
| return Room.objects.create(**validated_data) | ||
|
|
||
| class EntrySerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
|
|
@@ -15,9 +24,10 @@ class Meta: | |
| extra_kwargs = {'author': {'read_only': True}} | ||
|
|
||
| class MessageSerializer(serializers.Serializer): | ||
| command = serializers.ChoiceField(choices=['INIT_CHAT', 'FETCH_ENTRIES', 'NEW_ENTRY', 'ENTRIES']) | ||
| command = serializers.ChoiceField(choices=['INIT_CHAT', 'FETCH_ENTRIES', 'NEW_ENTRY']) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if this should reference the constants on the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah! |
||
| token = serializers.CharField(required=False, min_length=40, max_length=40) | ||
| text = serializers.CharField(required=False, max_length=255) | ||
| password = serializers.CharField(max_length=255, allow_blank=True) | ||
| # Not necessary at this end of the API? | ||
| # entries = EntrySerializer(required=False, many=True) | ||
| success = serializers.CharField(required=False, max_length=100) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this can be simplified as
if not hased_password