def get(self): """Return the access token. User and password must be present in the headers via Basic Auth.""" self._log.debug('Authorization = {auth}'.format( auth=request.authorization)) if not request.authorization: raise TagalleryMissingLoginInformationException() auth = request.authorization if not auth.username or not auth.password: raise TagalleryMissingLoginInformationException() cyphered = crypto(auth.username, auth.password) user = User.objects(login=auth.username, password=cyphered).first() if not user: self._log.debug('Cant find the user') raise TagalleryNoSuchUserException() self._log.debug('User = {user}'.format(user=user)) token = str(uuid.uuid4()) user.token = token user.save() return jsonify(status='OK', token=token)
def get(self): """Return the access token. User and password must be present in the headers via Basic Auth.""" self._log.debug("Authorization = {auth}".format(auth=request.authorization)) if not request.authorization: raise TagalleryMissingLoginInformationException() auth = request.authorization if not auth.username or not auth.password: raise TagalleryMissingLoginInformationException() cyphered = crypto(auth.username, auth.password) user = User.objects(login=auth.username, password=cyphered).first() if not user: self._log.debug("Cant find the user") raise TagalleryNoSuchUserException() self._log.debug("User = {user}".format(user=user)) token = str(uuid.uuid4()) user.token = token user.save() return jsonify(status="OK", token=token)
def check_auth(*args, **kwargs): if not request.authorization: raise TagalleryMissingLoginInformationException() # request informatino requires that the user in the basic auth is, # actually, the token token = request.authorization.username user = User.objects(last_token=token).first() if not user: raise TagalleryInvalidTokenException() result = func(*args, **kwargs) user.last_token = str(uuid.uuid4()) result.headers.add('X-NextToken', user.last_token) return result