Skip to content

Commit

Permalink
Merge pull request #40 from fga-gpp-mds/US#06-EditAccount
Browse files Browse the repository at this point in the history
Us#06 edit account
  • Loading branch information
byronkamal authored Nov 25, 2017
2 parents 60f12f4 + ec9054b commit 8adac33
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DepuTinder_API/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from questionnaire.views import questionnaire
from parlamentarians.views import parlamentarians
from users.views import users
from users.views import updateUser
from candidateRanking.views import rankingIndex
from candidateRanking.views import answeredQuestions
from question.views import question
Expand All @@ -31,6 +32,7 @@
url(r'^ranking/', rankingIndex),
url(r'^questionnaire/', questionnaire),
url(r'^users/', users),
url(r'^updateUser/', updateUser),
url(r'^parlamentarians/', parlamentarians),
url(r'^sendAnsweredQuestions/', answeredQuestions),
url(r'^question/', question),
Expand Down
26 changes: 26 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@api_view(['GET', 'POST', 'PUT', 'DELETE'])
def users(request):

#method to GET all users from API
if request.method == 'GET':
users = User.objects.all()

Expand All @@ -24,6 +25,7 @@ def users(request):
else:
return JsonResponse(seri, safe=False)

#method to POST a new User in API
elif request.method == 'POST':
if request.data:

Expand All @@ -47,6 +49,7 @@ def users(request):
else:
return Response(status=status.HTTP_400_BAD_REQUEST)

#method to update an user from API
elif request.method == 'PUT':
u = User.objects.filter(email=request.data['userEmail'])

Expand Down Expand Up @@ -75,3 +78,26 @@ def users(request):
print(request.data)
deleteUser = User.objects.get(email=request.data['userEmail']).delete()
return Response(status=status.HTTP_200_OK)

@api_view(['PUT'])
def updateUser(request):
u = User.objects.filter(email=request.data['oldUserEmail'])

if not u:
return JsonResponse({"status":500, "message": "Email não existe!"}, status=status.HTTP_400_BAD_REQUEST)
else:
user_authenticate = authenticate(username=u[0].username, password=request.data['oldUserPassword'])
if user_authenticate is not None:
user = Users.objects.get(user=user_authenticate.id)
u[0].username = request.data['userName']
u[0].email = request.data['userEmail']
print(request.data['userPassword'])
if(request.data['userPassword'] != ''):
u[0].set_password(request.data['userPassword'])
u[0].save()
print(u[0].username)
print(u[0].email)
print(u[0].password)
return JsonResponse({"status":400, "message": "Email ou senha incorretos"}, status=status.HTTP_400_BAD_REQUEST)
else:
return JsonResponse({"status":400, "message": "Email ou senha incorretos"}, status=status.HTTP_400_BAD_REQUEST)

0 comments on commit 8adac33

Please sign in to comment.