def post(self): post = request.form tel = post.get("tel") if not tel: return success(res={'r': 1, 'error_code': 4006, 'msg': '手机号不能为空'}) if not AdminAccount.objects(tel=tel): return success(res={'r': 1, 'error_code': 4006, 'msg': '用户不存在'}) key = model.CHECKCODE_KEY.format(tel=tel) code = cache.get(key) if not code: code = random.randint(100000, 999999) cache.incr(key, code) cache.expire(key, 300) if config.get("DEBUG"): print code, "CODEEE" ret = True else: ret = alidayu_tool.send_code(phone=tel, num=str(code)) if ret: return success(res={}) else: return success(res={'error_code': 4001, 'msg': u'验证码发送失败'})
def suggest(text): """给API用""" if isinstance(text, unicode): text = text.encode('utf-8') key = SUGGEST_KEY.format(text=text) rs = cache.get(key) if rs: return ast.literal_eval(rs) items = [] if not isinstance(text, unicode): text = text.decode('utf-8') artists = Artist.objects(name__contains=text) items.extend([{ 'id': artist.id, 'name': artist.name, 'avatar': artist.picture, 'type': 'artist' } for artist in artists]) songs = Song.objects(name__contains=text) items.extend([{ 'id': song.id, 'name': song.name, 'type': 'song' } for song in songs]) cache.set(key, items) return items
def get(cls, id): coll_name = cls._meta['collection'] key = OBJ_KEY.format(coll_name=coll_name, id=id) rs = cache.get(key) if rs: return cls.from_json(rs) rs = cls.objects.get(id=id) cache.set(key, rs.to_json()) return rs
def get(cls, id): coll_name = cls._meta['collection'] key = OBJ_KEY.format(coll_name=coll_name, id=id) rs = cache.get(key) if rs: return cls.from_json(rs) try: rs = cls.objects.get(id=id) except DoesNotExist, e: return False
def get(cls, id): coll_name = cls._meta['collection'] key = OBJ_KEY.format(coll_name=coll_name, id=id) rs = cache.get(key) if rs: return cls.from_json( rs) # Converts json data to an unsaved document instance rs = cls.objects.get(id=id) cache.set(key, rs.to_json()) # Convert this document to JSON. return rs
def search(subject_id, type): key = SEARCH_KEY.format(id=subject_id, type=type) if not subject_id: return [] comment_id = cache.get(key) if comment_id: return Comment.get(comment_id) movie = None if type == "movie": movie = Movie.get(id=subject_id) if movie == None: return [] comment = Comment.objects(movie=movie)[0] comment_id = comment.id if comment_id: cache.set(key, comment_id) return comment
def post(self): post = request.form tel = post.get("tel") recv_code = post.get("recv_code") if not tel: return success(res={'error_code': 4001, 'msg': '字段缺失'}) rn = AdminAccount.objects(tel=tel).first() if rn: key = model.CHECKCODE_KEY.format(tel=tel) code = cache.get(key) if recv_code == str(code): session['account_id'] = rn.id return success() else: print recv_code, str(code) return success(res={'error_code': 4001, 'msg': '验证码错误'}) else: return success(res={'error_code': 4002, 'msg': '手机号未注册'})
def suggest(text): if isinstance(text, unicode): text = text.encode('utf-8') key = SUGGEST_KEY.format(text=text) rs = cache.get(key) items = [] if rs: temp_rs = ast.literal_eval(rs) for t in temp_rs: items.append(t[0]) return items if not isinstance(text, unicode): text = text.decode('utf-8') movies = Movie.objects(name__contains=text) items.extend([{ 'id': movie.id, 'name': movie.name, 'type': 'movie' }] for movie in movies) cache.set(key, items) return items
def post(self): post = request.form tel = post.get("tel") name = post.get('name') code = post.get('code') passwd = post.get('passwd') if not code or not name or not passwd: return success(res={'error_code': 4001}) if Account.objects(tel=tel): return success(res={'error_code': 4001, 'msg': '手机已注册'}) if len(passwd) < 6: return success(res={'error_code': 4001}) key = model.CHECKCODE_KEY.format(tel=tel) passwd = str(passwd) hash_passwd = hmac.new(passwd) hash_passwd.update(passwd[1:5]) if code == cache.get(key): img_key = post.get('img_key') if not img_key: img_key = 'head.jpg' data = {'tel': tel, 'name': name, 'password': hash_passwd.hexdigest(), 'state': 100, 'head_img_key': img_key} rn = Account.create(**data) else: return success(res={'error_code': 4001, 'msg': '验证码错误'}) if not rn: return success(res={'error_code': 4001}) else: session['user_id'] = rn.id return success()