def post(self, request): username = request.POST.get('username', None) password = request.POST.get('password', None) user = authenticate(username=username, password=password) if settings.MOBILE_OAUTH_CLIENT_ID == '': response = HttpResponse( 'Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py', status=500) else: if user: if hasattr(user, 'userprofile') is not True: models.UserProfile.objects.create(user=user) is_reviewer = user.userprofile.is_reviewer() user = JSONSerializer().serializeToPython(user) user['password'] = None user['is_reviewer'] = is_reviewer response = JSONResponse({ 'user': user, 'clientid': settings.MOBILE_OAUTH_CLIENT_ID }) else: response = Http401Response() return response
def post(self, request): username = request.POST.get('username', None) password = request.POST.get('password', None) user = authenticate(username=username, password=password) if user: expiration = int(time.time()) + timedelta(days=settings.JWT_TOKEN_EXPIRATION).total_seconds() token = jws.sign({'username': user.username, 'expiration':expiration}, settings.JWT_KEY, algorithm=settings.JWT_ALGORITHM) response = HttpResponse(token, content_type='text/plain') else: response = Http401Response(www_auth_header='Bearer') return response
def post(self, request): if settings.MOBILE_OAUTH_CLIENT_ID == "": message = _("Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py") response = HttpResponse(message, status=500) logger.warning(message) else: username = request.POST.get("username", None) password = request.POST.get("password", None) user = authenticate(username=username, password=password) if user: response = JSONResponse({"clientid": settings.MOBILE_OAUTH_CLIENT_ID}) else: response = Http401Response() return response
def process_request(self, request): assert hasattr(request, 'token'), ( "The JSON authentication middleware requires token middleware " "to be installed. Edit your MIDDLEWARE setting to insert " "'arches.app.utils.middleware.TokenMiddleware' before " "'arches.app.utils.middleware.JWTAuthenticationMiddleware'.") # if there is a session and the user isn't anonymous then don't modify request.user if request.user.is_anonymous() and request.token is not '': # try to get the user info from the token if it exists try: user = self.get_user_from_token(request.token) request.user = SimpleLazyObject(lambda: user) except AuthenticationFailed as err: response = Http401Response(err.message, www_auth_header='Bearer', content_type='text/plain') return response except JWSError as err: response = Http401Response(err.message, www_auth_header='Bearer', content_type='text/plain') return response
def post(self, request): if settings.MOBILE_OAUTH_CLIENT_ID == "": message = _("Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py") logger.warning(message) username = request.POST.get("username", None) password = request.POST.get("password", None) user = authenticate(username=username, password=password) if user: server_settings = {"version": __version__, "clientid": settings.MOBILE_OAUTH_CLIENT_ID} response = JSONResponse(server_settings) else: response = Http401Response() return response
def post(self, request): username = request.POST.get('username', None) password = request.POST.get('password', None) user = authenticate(username=username, password=password) if settings.MOBILE_OAUTH_CLIENT_ID == '': response = HttpResponse( 'Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py', status=500) else: if user: response = HttpResponse(settings.MOBILE_OAUTH_CLIENT_ID, content_type='text/plain') else: response = Http401Response() return response
def post(self, request): username = request.POST.get("username", None) password = request.POST.get("password", None) user = authenticate(username=username, password=password) if user: if hasattr(user, "userprofile") is not True: models.UserProfile.objects.create(user=user) userDict = JSONSerializer().serializeToPython(user) userDict["password"] = None userDict["is_reviewer"] = user_is_resource_reviewer(user) userDict["viewable_nodegroups"] = user.userprofile.viewable_nodegroups userDict["editable_nodegroups"] = user.userprofile.editable_nodegroups userDict["deletable_nodegroups"] = user.userprofile.deletable_nodegroups response = JSONResponse(userDict) else: response = Http401Response() return response
def post(self, request): username = request.POST.get("username", None) password = request.POST.get("password", None) user = authenticate(username=username, password=password) if settings.MOBILE_OAUTH_CLIENT_ID == "": message = _("Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py") response = HttpResponse(message, status=500) logger.warning(message) else: if user: if hasattr(user, "userprofile") is not True: models.UserProfile.objects.create(user=user) is_reviewer = user_is_resource_reviewer(user) user = JSONSerializer().serializeToPython(user) user["password"] = None user["is_reviewer"] = is_reviewer response = JSONResponse({"user": user, "clientid": settings.MOBILE_OAUTH_CLIENT_ID}) else: response = Http401Response() return response
def post(self, request): username = request.POST.get('username', None) password = request.POST.get('password', None) user = authenticate(username=username, password=password) if user: if hasattr(user, 'userprofile') is not True: models.UserProfile.objects.create(user=user) userDict = JSONSerializer().serializeToPython(user) userDict['password'] = None userDict['is_reviewer'] = user.userprofile.is_reviewer() userDict[ 'viewable_nodegroups'] = user.userprofile.viewable_nodegroups userDict[ 'editable_nodegroups'] = user.userprofile.editable_nodegroups userDict[ 'deletable_nodegroups'] = user.userprofile.deletable_nodegroups response = JSONResponse(userDict) else: response = Http401Response() return response
def post(self, request): username = request.POST.get('username', None) password = request.POST.get('password', None) user = authenticate(username=username, password=password) if settings.MOBILE_OAUTH_CLIENT_ID == '': response = HttpResponse( 'Make sure to set your MOBILE_OAUTH_CLIENT_ID in settings.py', status=500) else: if user: user = JSONSerializer().serializeToPython(user) user['password'] = None response = JSONResponse({ 'user': user, 'clientid': settings.MOBILE_OAUTH_CLIENT_ID }) else: response = Http401Response() return response
def post(self, request): """ the above token need to be saved in database, and a one-to-one relation should exist with the username/user_pk """ username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user: expiration = int(time.time()) + timedelta( days=settings.JWT_TOKEN_EXPIRATION).total_seconds() token = jws.sign( { 'username': user.username, 'expiration': expiration }, settings.JWT_KEY, algorithm=settings.JWT_ALGORITHM) return HttpResponse(token) else: return Http401Response(www_auth_header='Bearer')