示例#1
0
 def authenticate(self):
     collection = self.connection['users']
     username = request.json.get('username')
     password = request.json.get('password')
     hasher = hashlib.md5()
     hasher.update(password)
     user = collection.find_one({
         'username': username,
         'password': hasher.hexdigest(),
     }) or abort(400, 'Wrong username or password')
     access_token = str(uuid.uuid4())
     self.connection['access_tokens'].insert({
         'access_token': access_token,
         'user_id': user.get('id')})
     user.pop('password')
     user.update({'access_token': access_token})
     return jsonify(user)
示例#2
0
文件: auth.py 项目: yutiansut/kule
 def authenticate(self):
     collection = self.connection['users']
     username = request.json.get('username')
     password = request.json.get('password')
     hasher = hashlib.md5()
     hasher.update(password)
     user = collection.find_one({
         'username': username,
         'password': hasher.hexdigest(),
     }) or abort(400, 'Wrong username or password')
     access_token = str(uuid.uuid4())
     self.connection['access_tokens'].insert({
         'access_token': access_token,
         'user_id': user.get('id')
     })
     user.pop('password')
     user.update({'access_token': access_token})
     return jsonify(user)
示例#3
0
 def register(self):
     collection = self.connection['users']
     password = request.json.get('password')
     username = request.json.get('username')
     email = request.json.get('email')
     if not username or not password:
         abort(400, 'Please give an username and password')
     if collection.find_one({'username': username}):
         abort(400, 'A user with that username already exists')
     if collection.find_one({'email': email}):
         abort(400, 'A user with that email already exists')
     hasher = hashlib.md5()
     hasher.update(password)
     response.status = 201
     return jsonify({"_id": collection.insert({
         'username': request.json.get('username'),
         'email': request.json.get('email'),
         'password': hasher.hexdigest()
     })})
示例#4
0
文件: auth.py 项目: yutiansut/kule
 def register(self):
     collection = self.connection['users']
     password = request.json.get('password')
     username = request.json.get('username')
     email = request.json.get('email')
     if not username or not password:
         abort(400, 'Please give an username and password')
     if collection.find_one({'username': username}):
         abort(400, 'A user with that username already exists')
     if collection.find_one({'email': email}):
         abort(400, 'A user with that email already exists')
     hasher = hashlib.md5()
     hasher.update(password)
     response.status = 201
     return jsonify({
         "_id":
         collection.insert({
             'username': request.json.get('username'),
             'email': request.json.get('email'),
             'password': hasher.hexdigest()
         })
     })
示例#5
0
 def not_implemented(self, *args, **kwargs):
     """Returns not implemented status."""
     abort(501)
示例#6
0
 def get_detail(self, collection, pk):
     """Returns a single document."""
     cursor = self.get_collection(collection)
     data = cursor.find_one({"_id": ObjectId(pk)}) or abort(404)
     return jsonify(self.get_bundler(cursor)(data))
示例#7
0
 def get_collection(self, collection):
     """Returns the given collection if it permitted"""
     if self.collections and collection not in self.collections:
         abort(403)
     return self.connection[collection]
示例#8
0
 def not_implemented(self, *args, **kwargs):
     """Returns not implemented status."""
     abort(501)
示例#9
0
 def get_detail(self, collection, pk):
     """Returns a single document."""
     cursor = self.get_collection(collection)
     data = cursor.find_one({"_id": ObjectId(pk)}) or abort(404)
     return jsonify(self.get_bundler(cursor)(data))
示例#10
0
 def get_collection(self, collection):
     """Returns the given collection if it permitted"""
     if self.collections and collection not in self.collections:
         abort(403)
     return self.connection[collection]