Created
May 20, 2015 22:15
-
-
Save shofetim/5e23c0391ccf63abb1ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def login(request): | |
try: | |
data = json.loads(request.body) | |
username = data.get('username') | |
password = data.get('password') | |
except ValueError as error: | |
return JsonResponse.bad_request(message=unicode(error)) | |
user = auth.authenticate(username=username, password=password) | |
if (user is not None) and user.is_active: | |
auth.login(request, user) | |
request.user = user | |
return session(request) | |
else: | |
return JsonResponse.bad_request(message=unicode('Login Failed')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment