From 0b2da889427244966994e06f127ac25ee3cb260b Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 19:21:30 +0100 Subject: [PATCH 1/8] SMART-42 implemented retrieve user profile view --- rest-app/db.sqlite3 | Bin 167936 -> 167936 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 167 -> 167 bytes .../__pycache__/settings.cpython-38.pyc | Bin 3500 -> 3500 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1015 -> 1015 bytes .../__pycache__/wsgi.cpython-38.pyc | Bin 580 -> 580 bytes .../user/__pycache__/__init__.cpython-38.pyc | Bin 176 -> 176 bytes .../app/user/__pycache__/admin.cpython-38.pyc | Bin 217 -> 217 bytes .../user/__pycache__/models.cpython-38.pyc | Bin 2416 -> 2416 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1028 -> 1028 bytes .../0002_auto_20201130_2119.cpython-38.pyc | Bin 545 -> 545 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 187 -> 187 bytes rest-app/smartpicasso/app/user/serializers.py | 3 +- .../__pycache__/__init__.cpython-38.pyc | Bin 184 -> 184 bytes .../__pycache__/admin.cpython-38.pyc | Bin 225 -> 225 bytes .../__pycache__/models.cpython-38.pyc | Bin 1060 -> 1060 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1055 -> 1055 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 195 -> 195 bytes .../smartpicasso/app/user_profile/models.py | 1 + .../smartpicasso/app/user_profile/views.py | 37 +++++++++++++++++- 19 files changed, 38 insertions(+), 3 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 0aeefde76f76489d795545caff8a5e92ce52c00a..3841dcd432ea01b0a42fbe197540b9d975e33331 100644 GIT binary patch delta 108 zcmV-y0F(cKpbCJX3XmHCFOeKW0WX1IwO|3E{|^qu00a!d01sCT!44S>ZLxu|30{|$|1gQW3 delta 19 ZcmZ3^xSWwYl$V!_0SG4a9Gl2J2LLKa1n&R< diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc index 5b5865037fe9425e9bf83e0e5d76b99d6948d776..8f74e3094d892ecb8ae9f48b7dc1ce49287c9758 100644 GIT binary patch delta 20 acmZ1@y+)cll$V!_0SM~-&u!#h$O`~6cLf;$ delta 20 acmZ1@y+)cll$V!_0SG4a9NWmfkQV?nGzDJ( diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 74b3fd52bd0832a495c073c74b9c2eb2b89b19cf..a7c2f9b2241829ed7dbf70406c61415ca40844da 100644 GIT binary patch delta 20 acmey){+*pWl$V!_0SM~-&u!#>!wdjBRRzcZ delta 20 acmey){+*pWl$V!_0SG4a9NWnKh8X}o5(W+c diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc index 269351cdcfc2ff197e546f0837801c5067288685..624cd2cd49421e1ae7d3ab06f995aea75f1d8b2e 100644 GIT binary patch delta 20 acmX@Ya)gCDl$V!_0SM~-&u!$kWC8#&@C2v; delta 20 acmX@Ya)gCDl$V!_0SG4a9NWlk$pip1tpx4> diff --git a/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc index 7a008fc13de5ed1c5ad00761da70068fc00e5ca8..72eb12b4eafa74b963799d6effcf364e0bf4a65b 100644 GIT binary patch delta 19 ZcmdnMxPg&7l$V!_0SM~-&rRfB3IHk|1jGOU delta 19 ZcmdnMxPg&7l$V!_0SG4a9Gl3!6aXug1quKF diff --git a/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc index 01cd26348969e76516a1d59a4483c163e0a13e48..dc5c2583a881bfa98316680e6b51aa8d967169e6 100644 GIT binary patch delta 19 Zcmcb~c$1Mkl$V!_0SM~-&rRe$2LLb&1wQ}) delta 19 Zcmcb~c$1Mkl$V!_0SG4a9Gl2}4gfKN1%&_r diff --git a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc index af422490e0d4d204c91c7a4ea15cb87dc094f022..66e537eb877091ef17f6feffde1897331eb846e8 100644 GIT binary patch delta 20 acmew$^g)O_l$V!_0SM~-&u!#RlpK0D^k|a~rvTG6MiAfdugY delta 20 acmZqSXyM=v<>lpK0D`@nk8R}s$qWE4V+D%< diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc index 34c4c8a626f4a77737187501670febe8e5d44858..00ad2b87204a0b20afd7f5b1091671b6db95a57d 100644 GIT binary patch delta 20 acmZ3;vXF&4l$V!_0SM~-&u!!uV*&sycmzKH delta 20 acmZ3;vXF&4l$V!_0SNYPKDLotj0pfRS_Ihu diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc index 62d8e5b70e88d3ed03a0201522c41878e50f7972..310f28ac9dd9255d172748e897fb136402d09c0e 100644 GIT binary patch delta 19 ZcmdnZxSNqXl$V!_0SM~-&rRgs001ks1myq# delta 19 ZcmdnZxSNqXl$V!_0SG4a9Gl3!0RSy51uFmm diff --git a/rest-app/smartpicasso/app/user/serializers.py b/rest-app/smartpicasso/app/user/serializers.py index cb69e9d..8ea3aaf 100644 --- a/rest-app/smartpicasso/app/user/serializers.py +++ b/rest-app/smartpicasso/app/user/serializers.py @@ -20,7 +20,7 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = UserProfile - fields = ('first_name', 'last_name') + fields = ('username', 'first_name', 'last_name') class UserRegistrationSerializer(serializers.ModelSerializer): @@ -39,6 +39,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer): user = User.objects.create_user(**validated_data) UserProfile.objects.create( user=user, + username=profile_data['username'], first_name=profile_data['first_name'], last_name=profile_data['last_name'] ) diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc index 6b25f622f576112f60d3465b4d8354ac09c3b4a4..f69046bef81ca4411b010344ca131db4652ee03d 100644 GIT binary patch delta 19 ZcmdnNxPy^9l$V!_0SM~-&rRfB3jixd1l#}s delta 19 ZcmdnNxPy^9l$V!_0SG4a9Gl3!762^01tI_d diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc index 08118cc5d5a0f51ce01cebee94ac4fc8b24ff034..975329643db64764625b762b10864b6cafc07357 100644 GIT binary patch delta 19 ZcmaFJ_>hr1l$V!_0SM~-&rRgM1^_WL1y=w7 delta 19 ZcmaFJ_>hr1l$V!_0SG4a9Gl2}4FEE#1)Tr@ diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index 1aa4d7255859d909c737419499fb3717e8bdf01b..bd1d7a14781d8050cba52cfe539a8ac9f71b0c50 100644 GIT binary patch delta 20 acmZ3&v4n#=l$V!_0SM~-&u!$EWB~vzf&@|k delta 20 acmZ3&v4n#=l$V!_0SMZ6AKS<+$pQc{8U(%o diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc index 94e7772ebae22bca859d004989044af2256d95ce..a792bc3bae0aa9f90a8e42d68858ab984c49fadf 100644 GIT binary patch delta 20 acmbQwF`t7wl$V!_0SM~-&u!!uVF3Uvx&%W2 delta 20 acmbQwF`t7wl$V!_0SG4a9NWk(!U6y;cLa$5 diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc index 48eab08fa8b1530035b9522ce27a0f16441013b1..0b6cc2bcbff79dfefbeeb1cbf6e4c5aede37a43c 100644 GIT binary patch delta 19 ZcmX@ic$kqpl$V!_0SM~-&rRgs0RSxB1pNR2 delta 19 ZcmX@ic$kqpl$V!_0SG4a9Gl3!0{|{m1w#M; diff --git a/rest-app/smartpicasso/app/user_profile/models.py b/rest-app/smartpicasso/app/user_profile/models.py index 4da1ccf..01908c7 100644 --- a/rest-app/smartpicasso/app/user_profile/models.py +++ b/rest-app/smartpicasso/app/user_profile/models.py @@ -13,6 +13,7 @@ class UserProfile(models.Model): """ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile') + username = models.CharField(max_length=50, unique=True) first_name = models.CharField(max_length=50, unique=False) last_name = models.CharField(max_length=50, unique=False) diff --git a/rest-app/smartpicasso/app/user_profile/views.py b/rest-app/smartpicasso/app/user_profile/views.py index 91ea44a..9835f6c 100644 --- a/rest-app/smartpicasso/app/user_profile/views.py +++ b/rest-app/smartpicasso/app/user_profile/views.py @@ -1,3 +1,36 @@ -from django.shortcuts import render +from rest_framework import status +from rest_framework.generics import RetrieveAPIView +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework_jwt.authentication import JSONWebTokenAuthentication -# Create your views here. +from smartpicasso.app.user_profile.models import UserProfile + + +class UserProfileView(RetrieveAPIView): + permission_classes = (IsAuthenticated,) + authentication_classes = JSONWebTokenAuthentication + + def get(self, request): + try: + user_profile = UserProfile.objects.get(user=request.user) + status_code = status.HTTP_200_OK + response = { + 'success': 'true', + 'status_code': status_code, + 'message': 'User profile fetched successfully', + 'data': { + 'username': user_profile.username, + 'first_name': user_profile.first_name, + 'last_name': user_profile.last_name + } + } + except Exception as e: + status_code = status.HTTP_400_BAD_REQUEST + response = { + 'success': 'false', + 'status_code': status_code, + 'message': 'User does not exist', + 'error': str(e) + } + return Response(response, status=status_code) -- 2.20.1 From 3c6736c98cfca5e7a449731518f354ebe6aa39b1 Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 19:24:41 +0100 Subject: [PATCH 2/8] SMART-42 registered retreive user profile endpoint --- rest-app/smartpicasso/app/user/views.py | 4 ++++ rest-app/smartpicasso/app/user_profile/urls.py | 11 +++++++++++ rest-app/smartpicasso/app/user_profile/views.py | 4 ++++ rest-app/smartpicasso/urls.py | 1 + 4 files changed, 20 insertions(+) create mode 100644 rest-app/smartpicasso/app/user_profile/urls.py diff --git a/rest-app/smartpicasso/app/user/views.py b/rest-app/smartpicasso/app/user/views.py index ecb0a57..1a5bfcf 100644 --- a/rest-app/smartpicasso/app/user/views.py +++ b/rest-app/smartpicasso/app/user/views.py @@ -1,3 +1,7 @@ +""" +@author: p.dolata +""" + from rest_framework import status from rest_framework.generics import RetrieveAPIView, CreateAPIView from rest_framework.permissions import AllowAny diff --git a/rest-app/smartpicasso/app/user_profile/urls.py b/rest-app/smartpicasso/app/user_profile/urls.py new file mode 100644 index 0000000..61d89f6 --- /dev/null +++ b/rest-app/smartpicasso/app/user_profile/urls.py @@ -0,0 +1,11 @@ +""" +@author: p.dolata +""" + +from django.conf.urls import url + +from smartpicasso.app.user_profile.views import UserProfileView + +urlpatterns = [ + url(r'^profile', UserProfileView.as_view(), name='profile') +] diff --git a/rest-app/smartpicasso/app/user_profile/views.py b/rest-app/smartpicasso/app/user_profile/views.py index 9835f6c..8cec569 100644 --- a/rest-app/smartpicasso/app/user_profile/views.py +++ b/rest-app/smartpicasso/app/user_profile/views.py @@ -1,3 +1,7 @@ +""" +@author: p.dolata +""" + from rest_framework import status from rest_framework.generics import RetrieveAPIView from rest_framework.permissions import IsAuthenticated diff --git a/rest-app/smartpicasso/urls.py b/rest-app/smartpicasso/urls.py index de1970c..bd27833 100644 --- a/rest-app/smartpicasso/urls.py +++ b/rest-app/smartpicasso/urls.py @@ -18,5 +18,6 @@ from django.urls import path, include urlpatterns = [ path('api/', include('smartpicasso.app.user.urls')), + path('api/', include('smartpicasso.app.user_profile.urls')), path('admin/', admin.site.urls), ] -- 2.20.1 From dae09902075a796227f9d8c1b36efb55d214b18b Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 19:36:14 +0100 Subject: [PATCH 3/8] SMART-42 added username field to UserProfile entity --- rest-app/db.sqlite3 | Bin 167936 -> 172032 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1015 -> 1065 bytes .../__pycache__/models.cpython-38.pyc | Bin 1060 -> 1086 bytes .../migrations/0003_userprofile_username.py | 20 ++++++++++++++++++ 4 files changed, 20 insertions(+) create mode 100644 rest-app/smartpicasso/app/user_profile/migrations/0003_userprofile_username.py diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 3841dcd432ea01b0a42fbe197540b9d975e33331..212aed72f7115830d37481d6ece05f9f1af015eb 100644 GIT binary patch delta 432 zcmZozz}0YoYl5_(F#`jG77%L!F*6VcPSi1GG~Sr7gr8ZQOL#K7fG!i4@W#fwoNg}S ztPHC5j-|z^Mezki`DvLssRjlH#_=ElC?CwuOUz9*GB7gGH8j#Suv9R#urfBaGBVdQ zwlK3aG2I*~wM>*ze3Jo-0ULt=0|S5V#>Qm+$+`K{A>4191smS*Z~j)#_kdA!I%@)> zDj%;D&qJOSJo$WHAULtHY5T4OMqMrzJ}<_Ojg2jgOy=&>3$htC1&op1re*F17M-4u z&B)8FX6_2&nQ^N&>AJ9stEw`#$WGsw%_z&LGW~ou<9%Hn1tpMfkmHpU$`Xr`GZKq5 zObs*@{QN@{{6c+v6hi$x14CUw;nW6l!-YIX!-@Pr9@rP*JO}wCd4Yb}$g}+*50f)9 z4_J5-{~iAAATP%9PtTQSnhp^?#lMz+0{`>Pf&~ry(6k=oyTp; zvmOK|HnwcvmB6UW#lo{5XhWkHlezQs!W>3T0i)95)S~!;qWrYXoK#J7C$Q*ro?J#= zO^qg2M|N>lRmNuDlEkE(RAiONZ1w3*xs3N&fu3Me+}J3~wEaRJqv1q;zM~8*JO>&0 z!+8$!N%8{SyOC%6K^`V&W*!!h2PW~~;olDOMlApITzRJHK+y>d{HOTW@=xG@zFDxK zfq(i0eWrr#f&onI3Y<*9kWmF<6%hXe|D*{l98COC3_#UU8yo%jjRTojeI+G*4J^`3 zQ_WH=4a|*AOcIk4lT6am3@nmUO)OJV4Gm0^0}@M$Dzjbka}rAur$6LnQZNo=1Zy-; zPD?bjNHj`GvowQfOg2hQOfyJIF-lHKF)%~X*vrSHz{3S}4HN%%2B0VI0G+#061}@u>b%7 diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index a7c2f9b2241829ed7dbf70406c61415ca40844da..e76a947179e147a2c61850b757b3ddb7016c40ce 100644 GIT binary patch delta 123 zcmey)zLG;bl$V!_0SJ7=F2SyI?j znX=fj*qfQsnWH#TID#28IX4#UVPaI8EXXX%5noW0pO%@EI$4eRumBIx02Y28Mge9X IMj-qP04`J(m;e9( delta 94 zcmZ3<@ts{el$V!_0SM~-&&8WCGcY^`agYHEkmCTv#SRm-jfB}!nX=fj*qfQsnW8vS f*n=4~IX2epVVWGnyq6DT4hugIqX07xBhNno-jTPr#ia zg)@b#g&~EjnJG$eGautsMo|%R! delta 113 zcmdnTv4n#+l$V!_0SM~-&&8)qDoYk`3VRBK$M4RN!kNO= z!jQt%%oHWCS%&c{qo^=YYcUIu;9z87E)oSY{4@n8voWVkE@8Ih=7CBGF$zuI#oPh_ Dv(Xma diff --git a/rest-app/smartpicasso/app/user_profile/migrations/0003_userprofile_username.py b/rest-app/smartpicasso/app/user_profile/migrations/0003_userprofile_username.py new file mode 100644 index 0000000..c0af2d1 --- /dev/null +++ b/rest-app/smartpicasso/app/user_profile/migrations/0003_userprofile_username.py @@ -0,0 +1,20 @@ +# Generated by Django 3.1.3 on 2020-12-09 18:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + atomic = False + + dependencies = [ + ('user_profile', '0002_remove_userprofile_phone_number'), + ] + + operations = [ + migrations.AddField( + model_name='userprofile', + name='username', + field=models.CharField(default='', max_length=50, unique=True), + preserve_default=False, + ), + ] -- 2.20.1 From f3e9c33034125500684e155c41f0a2869b1698cf Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 20:57:11 +0100 Subject: [PATCH 4/8] SMART-42 added tests for retrieve user profile endpoint --- rest-app/db.sqlite3 | Bin 172032 -> 172032 bytes rest-app/smartpicasso/app/user/tests.py | 46 ++++++++++-- .../__pycache__/models.cpython-38.pyc | Bin 1086 -> 1266 bytes .../smartpicasso/app/user_profile/models.py | 3 + .../smartpicasso/app/user_profile/tests.py | 66 +++++++++++++++++- .../smartpicasso/app/user_profile/views.py | 10 +-- 6 files changed, 112 insertions(+), 13 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 212aed72f7115830d37481d6ece05f9f1af015eb..9d5678dd7a84199d9edd14718c3b760603b67e1a 100644 GIT binary patch delta 873 zcmb7?Pj3=I9ENuXV+&asdy`;ejoeJ>?(FQ$EKL*FA_!qADl2~ylkV)F(qL2CVye9q zz5&KWzJQ)M5o5U4Yd?ai=QiFw8r_0T8V^MeGpEV>d*0_aouf$SDAJ3I%WrS5ip$;g z&+FocUlNE81XzgkcSd(@KGRAu~K} zUPKTC0FMQD3{PPXo_?BZbzr}@1lqFz<^=c==7!xBcvuJ5%~;Hw=g3Ax=N`t6gI$Ml z1$&x`6iyTcc{VDYD{Q96KBob;k`wPWahx5$f;Bysb2XT(WAK%m{}Ojbihv-?BPs+XYfZb;{@K4Li6HLlfNw6?5Fie`**f%|#pGmPkBF7}y!z&`(rNlE>C9o_bGRMR*Bq!g{SidN-%qiU2 zH9Xxvu|hw{Ju1k_GR;>zBss^`qrf!V*2uufK-bVn*T7K0(A>(<%*xb4&)C?^)YQnt z$Ra7lz}UhvG0E7(!X(Yo(8$=r+`!P%G|kK~G0D6ju_Prw$Jn8`L@#mj-F(hz0!%Cr zH&5cf!@r#$=;m1d>ACVue$!2PnG{T!l$m`w2^q=-^cC3Or})?MPvC#PS+JmifBFP{ krjpGp6aL6AS|G4pAc5(-{KN?Y+u0kK{_<~TY52nr06ZgH?*IS* diff --git a/rest-app/smartpicasso/app/user/tests.py b/rest-app/smartpicasso/app/user/tests.py index 9f664c1..be066f4 100644 --- a/rest-app/smartpicasso/app/user/tests.py +++ b/rest-app/smartpicasso/app/user/tests.py @@ -1,29 +1,63 @@ +""" +@author: p.dolata +""" + from django.test import TestCase from django.urls import reverse from rest_framework import serializers from rest_framework import status from rest_framework.test import APITestCase, APIClient -from smartpicasso.app.user.models import User, UserManager +from smartpicasso.app.user.models import User from smartpicasso.app.user.serializers import UserLoginSerializer, UserRegistrationSerializer +from smartpicasso.app.user_profile.models import UserProfile class UserApiTest(APITestCase): client = APIClient() + authenticate_url = reverse('authenticate') + register_url = reverse('register') + profile = {"username": 'test', "first_name": "test", "last_name": "test"} def test_login_when_user_non_exist(self): - url = reverse('authenticate') - response = self.client.post(url, {'email': 'non-exist', 'password': '123'}, format='json') + response = self.client.post(self.authenticate_url, {'email': 'non-exist', 'password': '123'}, format='json') assert response.status_code == 400 def test_login_when_user_exist(self): User.objects.create_user(email='test@test.com', password='test') - url = reverse('authenticate') - response = self.client.post(url, {'email': 'test@test.com', 'password': 'test'}, format='json') + response = self.client.post(self.authenticate_url, {'email': 'test@test.com', 'password': 'test'}, + format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['success'], 'True') self.assertIn('token', response.data) + def test_register_when_user_non_exist(self): + response = self.client.post(self.register_url, {'email': 'test@test.com', 'password': 'test', + 'profile': self.profile}, format='json') + self.assertEqual(response.status_code, status.HTTP_201_CREATED) + self.assertEqual(response.data['success'], 'True') + + def test_register_when_email_exist(self): + User.objects.create_user(email='test@test.com', password='test') + response = self.client.post(self.register_url, {'email': 'test@test.com', 'password': 'test', + 'profile': self.profile}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertIn('email', response.data) + + def test_register_when_username_exist(self): + user = User.objects.create_user(email='test2@test.com', password='test') + UserProfile.objects.create( + user=user, + username=self.profile['username'], + first_name=self.profile['first_name'], + last_name=self.profile['last_name'] + ) + response = self.client.post(self.register_url, {'email': 'test@test.com', 'password': 'test', + 'profile': self.profile}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertIn('profile', response.data) + self.assertIn('username', response.data['profile']) + class UserTest(TestCase): @@ -52,7 +86,7 @@ class UserRegistrationSerializerTest(TestCase): serializer = UserRegistrationSerializer() def test_create(self): - profile = {"first_name": "test", "last_name": "test"} + profile = {"username": 'test', "first_name": "test", "last_name": "test"} user = self.serializer.create({"email": "test@test.com", "password": "test", "profile": profile}) self.assertNotEqual(user, None) diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index 5a858c65eeea097f5cc339b424e611601c862687..4adad8b729c403c8ee77a749781a26f759aafb2c 100644 GIT binary patch delta 327 zcmdnT@rjc!l$V!_0SKg6s{JAC_#6I6z&wB7KRj_W~L~i z6y9J4O}@!WjPpVnL7Jcd#AXI!XCN+C0}>?+H4Isd&5S9G;t)1dGmw?S1m!VK1bQOLvDrmCYVlFNznw-h3$f?PAi={XTit3xEhg5FrX8WG448D=L8mK?Vph3NiA5AQK035y(_cjv^_LGP%iT GnF|4X0zYs7 delta 173 zcmeywxsQV{l$V!_0SKmxT#R49G?8x+W6s2lu_EpaDV!->Eet7K%}h~(Dcr#fnmm)W z80SsC!gPpjB}0)g1H)u@rW9=!-_(*s5upBJ79hdF$iiGC3S{_c3Kj7I=^}m*Apjx- zCtqU@nk>tt$W$ac`2dT!RuM=C$nIj0N|06|Mj=K%5M%<&X>t?^f^>>cZe%G001K@k A*8l(j diff --git a/rest-app/smartpicasso/app/user_profile/models.py b/rest-app/smartpicasso/app/user_profile/models.py index 01908c7..8f25c64 100644 --- a/rest-app/smartpicasso/app/user_profile/models.py +++ b/rest-app/smartpicasso/app/user_profile/models.py @@ -17,6 +17,9 @@ class UserProfile(models.Model): first_name = models.CharField(max_length=50, unique=False) last_name = models.CharField(max_length=50, unique=False) + def __str__(self): + return str(self.username) + ' - ' + str(self.first_name) + ' ' + str(self.last_name) + class Meta: """ Meta to se table name in database diff --git a/rest-app/smartpicasso/app/user_profile/tests.py b/rest-app/smartpicasso/app/user_profile/tests.py index 7ce503c..bc84121 100644 --- a/rest-app/smartpicasso/app/user_profile/tests.py +++ b/rest-app/smartpicasso/app/user_profile/tests.py @@ -1,3 +1,65 @@ -from django.test import TestCase +""" +@author: p.dolata +""" -# Create your tests here. +from django.test import TestCase +from django.urls import reverse +from rest_framework import status +from rest_framework.test import APITestCase, APIClient + +from smartpicasso.app.user.models import User +from smartpicasso.app.user_profile.models import UserProfile + + +class UserProfileApiTest(APITestCase): + client = APIClient() + profile_url = reverse('profile') + authenticate_url = reverse('authenticate') + profile = {"username": 'test_user', "first_name": "first", "last_name": "last"} + + def test_get_profile_without_auth(self): + response = self.client.get(self.profile_url, format='json') + self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) + + def test_get_profile_with_invalid_token(self): + self.client.force_authenticate(user=None) + response = self.client.get(self.profile_url, format='json') + self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) + + def test_get_profile_when_user_without_profile(self): + user = User.objects.create_user(email='test@test.com', password='test') + self.client.force_authenticate(user=user) + response = self.client.get(self.profile_url, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + self.assertEqual(response.data['success'], 'False') + + def test_get_profile(self): + user = User.objects.create_user(email='test@test.com', password='test') + UserProfile.objects.create( + user=user, + username=self.profile['username'], + first_name=self.profile['first_name'], + last_name=self.profile['last_name'] + ) + self.client.force_authenticate(user=user) + response = self.client.get(self.profile_url, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data['success'], 'True') + profile = response.data['profile'] + self.assertEqual(profile['username'], self.profile['username']) + self.assertEqual(profile['first_name'], self.profile['first_name']) + self.assertEqual(profile['last_name'], self.profile['last_name']) + + +class UserProfileTest(TestCase): + profile = {"username": 'test_user', "first_name": "first", "last_name": "last"} + + def test_user_profile_str(self): + user = User.objects.create_user(email='test@test.com', password='test') + user_profile = UserProfile.objects.create( + user=user, + username=self.profile['username'], + first_name=self.profile['first_name'], + last_name=self.profile['last_name'] + ) + self.assertEqual(str(user_profile), 'test_user - first last') diff --git a/rest-app/smartpicasso/app/user_profile/views.py b/rest-app/smartpicasso/app/user_profile/views.py index 8cec569..04758b4 100644 --- a/rest-app/smartpicasso/app/user_profile/views.py +++ b/rest-app/smartpicasso/app/user_profile/views.py @@ -13,17 +13,17 @@ from smartpicasso.app.user_profile.models import UserProfile class UserProfileView(RetrieveAPIView): permission_classes = (IsAuthenticated,) - authentication_classes = JSONWebTokenAuthentication + authentication_class = JSONWebTokenAuthentication def get(self, request): try: user_profile = UserProfile.objects.get(user=request.user) status_code = status.HTTP_200_OK response = { - 'success': 'true', + 'success': 'True', 'status_code': status_code, 'message': 'User profile fetched successfully', - 'data': { + 'profile': { 'username': user_profile.username, 'first_name': user_profile.first_name, 'last_name': user_profile.last_name @@ -32,9 +32,9 @@ class UserProfileView(RetrieveAPIView): except Exception as e: status_code = status.HTTP_400_BAD_REQUEST response = { - 'success': 'false', + 'success': 'False', 'status_code': status_code, - 'message': 'User does not exist', + 'message': 'User profile does not exist', 'error': str(e) } return Response(response, status=status_code) -- 2.20.1 From f061ad93feb642e243d32a09bc5e8a363f972cb4 Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 21:49:10 +0100 Subject: [PATCH 5/8] SMART-42 change status code in response when user profile does not exist --- rest-app/db.sqlite3 | Bin 172032 -> 172032 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1065 -> 1065 bytes .../__pycache__/models.cpython-38.pyc | Bin 1266 -> 1266 bytes .../smartpicasso/app/user_profile/tests.py | 2 +- .../smartpicasso/app/user_profile/views.py | 2 +- 5 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 9d5678dd7a84199d9edd14718c3b760603b67e1a..683cf594817d08386bf594a78edadb42d6b60fcf 100644 GIT binary patch delta 582 zcmaiwJxjw-6hM>rKrqBy+^kiqph6a#yu6U6pdu-LAVmv`RuO$k8$XSp zIXf_B?fA@*RUoC^>7uu|?$E5U5C#*WlL#$F^QP}OlrYP8P2Y4vW(GMcZ@NBj#8Dp? z2Z#BihEhO`Byp33jwf8=+76EadQ&mfC1}D6)IkVt0^g4zeY6uAkKnZ20u1qIu`eiB z5$3?);=Y;fO+k+QG3-kH*i-v5=qBQ!UD(4Q9@0NGJ_>pXxI*8 z#I+0>xc(BW92^%?r6Q}aPA28?Tzil3`6+a(v~%hrrztc}KyP_=I`BK?=q we#t+hlg9r;n$KHEHw5HKf)99tF9CUku^t?g|6H+(2mdCd;AnT5RYZsN11Z3z1poj5 delta 421 zcmZoTz}0YoYl1YR^+XwGM(f6etqF`v{_`;Lt!Cg4=UdGu$(y^eaU;+6gFH-;j7*x$ z(+hZ+A!wtPBjSjEwXQO^hrJ&5SHejZI7~&5exBj7`jv z%@PgG4bxJM43bhT42=yMHJLaYH649zIXO5AlBS>MVG^ExhL6dG-_XL!#LUXjRL|VP z)Y8IWx;#JAQywP%?F{_e`R@QR(DkwW({tsSG*$82U|`Cu!tBckGC*PaZJ>IfDW@3t zPw_wJpTPfovtU63|MUs^OeGvl{GJT_OZh!FHrnz}_q1o)4HN-d2eb^RXf;0z*pxtf zkSYF5nh;5#TaY9{R&2i=&!lMplzqX#|APN3Q1%YL1P`+;V}V{ueokUZA`=(0G-p9# I36N(D07z+cbN~PV diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index e76a947179e147a2c61850b757b3ddb7016c40ce..1e0968f9032eb5f779cf4ecaa43d3b76d1d3b828 100644 GIT binary patch delta 19 ZcmZ3MY~+$>0RSjC1FHZ4 delta 19 ZcmZ3MY~*^u0su5H1qc8D delta 19 Zcmeyw`H7P&l$V!_0SK Date: Mon, 14 Dec 2020 07:02:08 +0100 Subject: [PATCH 6/8] Updated client app with 2 new views --- client/app.py | 334 +++++++++++++++++++++++++++++++------------------- 1 file changed, 207 insertions(+), 127 deletions(-) diff --git a/client/app.py b/client/app.py index 22bca28..f36f084 100644 --- a/client/app.py +++ b/client/app.py @@ -1,128 +1,208 @@ -import tkinter as tk -import requests - -FONT= ("Verdana", 12) -FONT_LARGE= ("Verdana", 20) -URL = "http://localhost:8000/api/authenticate" -TOKEN = "" - -class SmartPicasso(tk.Tk): - - def __init__(self, *args, **kwargs): - - tk.Tk.__init__(self, *args, **kwargs) - container = tk.Frame(self) - self.title('SmartPicasso') - self.geometry('610x460') - - container.pack(side="top", fill="both", expand = True) - - container.grid_rowconfigure(0, weight=1) - container.grid_columnconfigure(0, weight=1) - - self.frames = {} - - for F in (LoginPage, MainView, RegisterView): - - frame = F(container, self) - - self.frames[F] = frame - - frame.grid(row=0, column=0, sticky="nsew") - - self.show_frame(LoginPage) - - def show_frame(self, cont): - - frame = self.frames[cont] - frame.tkraise() - - -class LoginPage(tk.Frame): - - def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) - label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) - - label1 = tk.Label(self, text='Login:', font=FONT) - label1.pack() - - input1 = tk.Entry(self) - input1.pack() - - label2 = tk.Label(self, text='Password:', font=FONT) - label2.pack() - - input2 = tk.Entry(self) - input2.pack() - - button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get())) - button.pack() - - button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) - button2.pack() - - def login(self, controller, login, passw,): - print(login) - print(passw) - data = { - "email": str(login), - "password": str(passw) - } - resp = requests.post(URL, json=data) - print(resp) - if (resp.status_code==200): - response=resp.json() - TOKEN = response['token'] - controller.show_frame(MainView) - else: - print("bad pass") - badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) - badPassLabel.pack() - return() - - -class MainView(tk.Frame): - - def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) - label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) - label_u = tk.Label(self, text="Main menu", font=FONT) - label_u.pack(pady=10,padx=10) - - -class RegisterView(tk.Frame): - - def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) - label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) - label_u = tk.Label(self, text="Register", font=FONT) - label_u.pack(pady=10,padx=10) - - label1 = tk.Label(self, text='Login:', font=FONT) - label1.pack() - - input1 = tk.Entry(self) - input1.pack() - - label2 = tk.Label(self, text='Password:', font=FONT) - label2.pack() - - input2 = tk.Entry(self) - input2.pack() - - label3 = tk.Label(self, text='Email:', font=FONT) - label3.pack() - - input3 = tk.Entry(self) - input3.pack() - - button = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) - button.pack() - - -app = SmartPicasso() +import tkinter as tk +import requests + +FONT= ("Verdana", 12) +FONT_B= ("Verdana", 12, 'bold') +FONT_LARGE= ("Verdana", 20) +URL = "http://localhost:8000/api/authenticate" +URL_REGISTER = "http://localhost:8000/api/register" +URL_PROFILE = "http://localhost:8000/api/profile" +TOKEN = "" +USERNAME = "" +FIRST_NAME = "" +LAST_NAME = "" + + +class SmartPicasso(tk.Tk): + + def __init__(self, *args, **kwargs): + + tk.Tk.__init__(self, *args, **kwargs) + container = tk.Frame(self) + self.title('SmartPicasso') + self.geometry('610x460') + + container.pack(side="top", fill="both", expand = True) + + container.grid_rowconfigure(0, weight=1) + container.grid_columnconfigure(0, weight=1) + + self.frames = {} + + for F in (LoginView, MainView, RegisterView, ProfileView): + + frame = F(container, self) + + self.frames[F] = frame + + frame.grid(row=0, column=0, sticky="nsew") + + self.show_frame(LoginView) + + def show_frame(self, cont): + + frame = self.frames[cont] + frame.tkraise() + + +class LoginView(tk.Frame): + + def __init__(self, parent, controller): + tk.Frame.__init__(self,parent) + label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) + label.pack(pady=10,padx=10) + + label1 = tk.Label(self, text='Login:', font=FONT) + label1.pack() + + input1 = tk.Entry(self) + input1.pack() + + label2 = tk.Label(self, text='Password:', font=FONT) + label2.pack() + + input2 = tk.Entry(self, show="*") + input2.pack() + + button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get())) + button.pack() + + button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) + button2.pack() + + def login(self, controller, login, passw,): + print(login) + print(passw) + data = { + "email": str(login), + "password": str(passw) + } + resp = requests.post(URL, json=data) + print(resp) + if (resp.status_code==200): + response=resp.json() + TOKEN = response['token'] + + hed = {'Authorization': 'Bearer ' + TOKEN} + resp = requests.get(URL_PROFILE, headers=hed) + response=resp.json() + USERNAME = response['profile']['username'] + FIRST_NAME = response['profile']['first_name'] + LAST_NAME = response['profile']['last_name'] + + controller.show_frame(MainView) + else: + print("bad pass") + badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) + badPassLabel.pack() + return() + + +class MainView(tk.Frame): + + def __init__(self, parent, controller): + tk.Frame.__init__(self,parent) + self.profile = ProfileView() + label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) + label.pack(pady=10,padx=10) + label_u = tk.Label(self, text="Main menu", font=FONT) + label_u.pack(pady=10,padx=10) + + button_profile = tk.Button(self, text="My profile", font=FONT, command=lambda: controller.show_frame(ProfileView)) + button_profile.pack() + + +class RegisterView(tk.Frame): + + def __init__(self, parent, controller): + tk.Frame.__init__(self,parent) + label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) + label.pack(pady=10,padx=10) + label_u = tk.Label(self, text="Register", font=FONT) + label_u.pack(pady=10,padx=10) + + label0 = tk.Label(self, text='Email:', font=FONT) + label0.pack() + + input0 = tk.Entry(self) + input0.pack() + + label1 = tk.Label(self, text='Login:', font=FONT) + label1.pack() + + input1 = tk.Entry(self) + input1.pack() + + label2 = tk.Label(self, text='Password:', font=FONT) + label2.pack() + + input2 = tk.Entry(self, show="*") + input2.pack() + + label3 = tk.Label(self, text='First name:', font=FONT) + label3.pack() + + input3 = tk.Entry(self) + input3.pack() + + label4 = tk.Label(self, text='Last name:', font=FONT) + label4.pack() + + input4 = tk.Entry(self) + input4.pack() + + button1 = tk.Button(self, text="Register", font=FONT, command=lambda: self.register(controller, input0.get(), input1.get(), input2.get(), input3.get(), input4.get())) + button1.pack() + + button2 = tk.Button(self, text="Cancel", font=FONT, command=lambda: controller.show_frame(LoginView)) + button2.pack() + def register(self, controller, email, login, passw, name, lastname): + data = { + "email": str(email), + "password": str(passw), + "profile": { + "username": str(login), + "first_name": str(name), + "last_name": str(lastname) + } + } + print(data) + resp = requests.post(URL_REGISTER, json=data) + print(resp) + if (resp.status_code==201): + response=resp.json() + controller.show_frame(LoginView) + else: + print("sth wrong") + badPassLabel = tk.Label(self, text='Something went wrong!', font=FONT) + badPassLabel.pack() + return() + + +class ProfileView(tk.Frame): + + def __init__(self, parent, controller): + + tk.Frame.__init__(self,parent) + label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) + label.pack(pady=10,padx=10) + label_l1 = tk.Label(self, text="Login:", font=FONT_B) + label_l1.pack(pady=10,padx=10) + label_l2 = tk.Label(self, text=USERNAME, font=FONT) + label_l2.pack(pady=10,padx=10) + label_n1 = tk.Label(self, text="Name:", font=FONT_B) + label_n1.pack(pady=10,padx=10) + label_n2 = tk.Label(self, text=FIRST_NAME, font=FONT) + label_n2.pack(pady=10,padx=10) + label_ln1 = tk.Label(self, text="Last name", font=FONT_B) + label_ln1.pack(pady=10,padx=10) + label_ln2 = tk.Label(self, text=LAST_NAME, font=FONT) + label_ln2.pack(pady=10,padx=10) + + + button_profile = tk.Button(self, text="Back", font=FONT, command=lambda: controller.show_frame(MainView)) + button_profile.pack() + + +app = SmartPicasso() app.mainloop() \ No newline at end of file -- 2.20.1 From fb65e04600c6ff4eff87321ae6f4fa76b881425d Mon Sep 17 00:00:00 2001 From: s460930 Date: Mon, 14 Dec 2020 13:24:23 +0100 Subject: [PATCH 7/8] SMART-43 implemented user profile view --- client/app.py | 194 ++++++++++-------- client/requirements.txt | 2 + rest-app/db.sqlite3 | Bin 172032 -> 172032 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1065 -> 1065 bytes .../__pycache__/models.cpython-38.pyc | Bin 1266 -> 1266 bytes 5 files changed, 109 insertions(+), 87 deletions(-) create mode 100644 client/requirements.txt diff --git a/client/app.py b/client/app.py index f36f084..d16504d 100644 --- a/client/app.py +++ b/client/app.py @@ -1,36 +1,31 @@ import tkinter as tk + import requests -FONT= ("Verdana", 12) -FONT_B= ("Verdana", 12, 'bold') -FONT_LARGE= ("Verdana", 20) +FONT = ("Verdana", 12) +FONT_B = ("Verdana", 12, 'bold') +FONT_LARGE = ("Verdana", 20) URL = "http://localhost:8000/api/authenticate" URL_REGISTER = "http://localhost:8000/api/register" URL_PROFILE = "http://localhost:8000/api/profile" -TOKEN = "" -USERNAME = "" -FIRST_NAME = "" -LAST_NAME = "" class SmartPicasso(tk.Tk): def __init__(self, *args, **kwargs): - tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) self.title('SmartPicasso') self.geometry('610x460') - container.pack(side="top", fill="both", expand = True) + container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} - for F in (LoginView, MainView, RegisterView, ProfileView): - + for F in (LoginView, MainView, RegisterView): frame = F(container, self) self.frames[F] = frame @@ -39,123 +34,139 @@ class SmartPicasso(tk.Tk): self.show_frame(LoginView) - def show_frame(self, cont): - - frame = self.frames[cont] + def show_frame(self, view, token=None): + frame = self.frames[view] frame.tkraise() - + if token: + frame.token = token + + class LoginView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) + tk.Frame.__init__(self, parent) label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) - + label.pack(pady=10, padx=10) + label1 = tk.Label(self, text='Login:', font=FONT) label1.pack() - + input1 = tk.Entry(self) input1.pack() - + label2 = tk.Label(self, text='Password:', font=FONT) label2.pack() - + input2 = tk.Entry(self, show="*") input2.pack() - - button = tk.Button(self, text="Login", font=FONT, command=lambda: self.login(controller, input1.get(), input2.get())) + + button = tk.Button(self, text="Login", font=FONT, + command=lambda: self.login(controller, input1.get(), input2.get())) button.pack() button2 = tk.Button(self, text="Register", font=FONT, command=lambda: controller.show_frame(RegisterView)) button2.pack() - def login(self, controller, login, passw,): + def login(self, controller, login, password): print(login) - print(passw) + print(password) data = { "email": str(login), - "password": str(passw) + "password": str(password) } resp = requests.post(URL, json=data) print(resp) - if (resp.status_code==200): - response=resp.json() - TOKEN = response['token'] - - hed = {'Authorization': 'Bearer ' + TOKEN} - resp = requests.get(URL_PROFILE, headers=hed) - response=resp.json() - USERNAME = response['profile']['username'] - FIRST_NAME = response['profile']['first_name'] - LAST_NAME = response['profile']['last_name'] - - controller.show_frame(MainView) + if resp.status_code == 200: + response = resp.json() + token = response['token'] + + controller.show_frame(MainView, token) else: print("bad pass") - badPassLabel = tk.Label(self, text='Wrong login/password!', font=FONT) - badPassLabel.pack() - return() + bad_pass_label = tk.Label(self, text='Wrong login/password!', font=FONT) + bad_pass_label.pack() + return () class MainView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) - self.profile = ProfileView() + tk.Frame.__init__(self, parent) + self.frames = {} + self.token = '' + for F in (ProfileView,): + frame = F(parent, controller) + + self.frames[F] = frame + + frame.grid(row=0, column=0, sticky="nsew") label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) + label.pack(pady=10, padx=10) label_u = tk.Label(self, text="Main menu", font=FONT) - label_u.pack(pady=10,padx=10) - - button_profile = tk.Button(self, text="My profile", font=FONT, command=lambda: controller.show_frame(ProfileView)) + label_u.pack(pady=10, padx=10) + + button_profile = tk.Button(self, text="My profile", font=FONT, + command=lambda: self.show_frame(ProfileView)) button_profile.pack() + def show_frame(self, view): + frame = self.frames[view] + frame.tkraise() + + if self.token: + print(self.token) + frame.token = self.token + frame.start() + class RegisterView(tk.Frame): def __init__(self, parent, controller): - tk.Frame.__init__(self,parent) + tk.Frame.__init__(self, parent) label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) + label.pack(pady=10, padx=10) label_u = tk.Label(self, text="Register", font=FONT) - label_u.pack(pady=10,padx=10) - + label_u.pack(pady=10, padx=10) + label0 = tk.Label(self, text='Email:', font=FONT) label0.pack() - + input0 = tk.Entry(self) input0.pack() - + label1 = tk.Label(self, text='Login:', font=FONT) label1.pack() - + input1 = tk.Entry(self) input1.pack() - + label2 = tk.Label(self, text='Password:', font=FONT) label2.pack() - + input2 = tk.Entry(self, show="*") input2.pack() label3 = tk.Label(self, text='First name:', font=FONT) label3.pack() - + input3 = tk.Entry(self) input3.pack() - + label4 = tk.Label(self, text='Last name:', font=FONT) label4.pack() - + input4 = tk.Entry(self) input4.pack() - - button1 = tk.Button(self, text="Register", font=FONT, command=lambda: self.register(controller, input0.get(), input1.get(), input2.get(), input3.get(), input4.get())) + + button1 = tk.Button(self, text="Register", font=FONT, + command=lambda: self.register(controller, input0.get(), input1.get(), input2.get(), + input3.get(), input4.get())) button1.pack() button2 = tk.Button(self, text="Cancel", font=FONT, command=lambda: controller.show_frame(LoginView)) button2.pack() + def register(self, controller, email, login, passw, name, lastname): data = { "email": str(email), @@ -164,45 +175,54 @@ class RegisterView(tk.Frame): "username": str(login), "first_name": str(name), "last_name": str(lastname) - } } + } print(data) - resp = requests.post(URL_REGISTER, json=data) - print(resp) - if (resp.status_code==201): - response=resp.json() + response = requests.post(URL_REGISTER, json=data) + print(response) + if response.status_code == 201: + response = response.json() controller.show_frame(LoginView) else: print("sth wrong") - badPassLabel = tk.Label(self, text='Something went wrong!', font=FONT) - badPassLabel.pack() - return() - - + bad_pass_label = tk.Label(self, text='Something went wrong!', font=FONT) + bad_pass_label.pack() + return () + + class ProfileView(tk.Frame): def __init__(self, parent, controller): - - tk.Frame.__init__(self,parent) + tk.Frame.__init__(self, parent) + self.token = '' label = tk.Label(self, text="SmartPicasso", font=FONT_LARGE) - label.pack(pady=10,padx=10) + label.pack(pady=10, padx=10) label_l1 = tk.Label(self, text="Login:", font=FONT_B) - label_l1.pack(pady=10,padx=10) - label_l2 = tk.Label(self, text=USERNAME, font=FONT) - label_l2.pack(pady=10,padx=10) + label_l1.pack(pady=10, padx=10) + self.label_username = tk.Label(self, text='', font=FONT) + self.label_username.pack(pady=10, padx=10) label_n1 = tk.Label(self, text="Name:", font=FONT_B) - label_n1.pack(pady=10,padx=10) - label_n2 = tk.Label(self, text=FIRST_NAME, font=FONT) - label_n2.pack(pady=10,padx=10) + label_n1.pack(pady=10, padx=10) + self.label_first_name = tk.Label(self, text='', font=FONT) + self.label_first_name.pack(pady=10, padx=10) label_ln1 = tk.Label(self, text="Last name", font=FONT_B) - label_ln1.pack(pady=10,padx=10) - label_ln2 = tk.Label(self, text=LAST_NAME, font=FONT) - label_ln2.pack(pady=10,padx=10) + label_ln1.pack(pady=10, padx=10) + self.label_last_name = tk.Label(self, text='', font=FONT) + self.label_last_name.pack(pady=10, padx=10) - - button_profile = tk.Button(self, text="Back", font=FONT, command=lambda: controller.show_frame(MainView)) + button_profile = tk.Button(self, text="Back", font=FONT, + command=lambda: controller.show_frame(MainView, self.token)) button_profile.pack() - + def start(self): + headers = {'Authorization': 'Bearer ' + self.token} + resp = requests.get(URL_PROFILE, headers=headers) + response = resp.json() + print(response) + self.label_username['text'] = response['profile']['username'] + self.label_first_name['text'] = response['profile']['first_name'] + self.label_last_name['text'] = response['profile']['last_name'] + + app = SmartPicasso() -app.mainloop() \ No newline at end of file +app.mainloop() diff --git a/client/requirements.txt b/client/requirements.txt new file mode 100644 index 0000000..7819b5f --- /dev/null +++ b/client/requirements.txt @@ -0,0 +1,2 @@ +tkinter +requests diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 683cf594817d08386bf594a78edadb42d6b60fcf..d864fe3c5e86be76a82c7f9267861324c9416e76 100644 GIT binary patch delta 584 zcmZoTz}0YoYl1YR$3z)tMvumXtqF`v{`0W#RxMUp2{}mia~QZlRI+ z8Rj85hRIoZQGppD5s5yTAkC+clal5Y>eesQDOFFL^24gInyV~GZh21&SBs`#lM#SIscr^ zf&~ry(6G<}UeQv?qS-&6+vrTm_JZ}_HeY;5HV4`pHV6_)iCH8eLj zNj6GKN=r>LF)=kUwoFVmH%Ut~NdX3#xn)wSS7M%betBX}adsvlXMt?p{>F|;0_v?v zK#$$w-wyJYD#%-etYVoy$)Bl+{28XBjWo0%jVnpvhA znI)y9S(sQF8e15pnxy3CB$g!V6(p7vRq|vTJEZ3(X6EQ6=jU#hn@~fyY`!W(TboxYjredJhwG8~H_}B73=YPIgu%Ll|`UHI@9s!U|$QDgs zqt6t<#mx7HfqyB#C*PZmjraJrzp-PIVB`W@J_%^~cA)+i{^^tanTjBSU>AV}SwIe& ju3*okuzg!Rlb-=l{uTrO3;tXDUxD&x_^02R&!h$bt{Ztd diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 1e0968f9032eb5f779cf4ecaa43d3b76d1d3b828..74531e51a90c6aab03055b11e1b628ef6f40e6ef 100644 GIT binary patch delta 20 acmZ3MT-?Yl#{vK^D+GN2 diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index f6fe6fc5f81ca8a878a11923aabea00bc4c40b8d..615a5950e9d2ebf7c76a343adbdb1d744eb65d7e 100644 GIT binary patch delta 20 acmeyw`H7P|l$V!_0SG2BT;It3oCN?mt_6z# delta 20 acmeyw`H7P|l$V!_0SI>MT-?b0oCN?ow*}e& -- 2.20.1 From 706b719be4ddcb2deb57b6f8d431de81df4c5612 Mon Sep 17 00:00:00 2001 From: s460930 Date: Mon, 14 Dec 2020 13:29:06 +0100 Subject: [PATCH 8/8] fixed client app python requirements --- client/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/requirements.txt b/client/requirements.txt index 7819b5f..dcaa7c6 100644 --- a/client/requirements.txt +++ b/client/requirements.txt @@ -1,2 +1,2 @@ -tkinter +tk requests -- 2.20.1