def api_signup(): email = request.json.get('email') password = request.json.get('password') code = request.json.get('code') if email is None or password is None: print('None...') abort(400) code = Code.objects(value=code).first() if not code: return jsonify({ 'code': 0, 'tip': "wrong code" }) if User.objects(email=email).first() is not None: return jsonify({ 'code': 0, 'tip': "email already registered" }) try: user = User(email=email) user.set_password(password) user.save() code.delete() return jsonify({ 'code': 1, 'data': {'id': str(user.id), 'email': user.email} }) except db.errors.ValidationError: return jsonify({ 'code': 0, 'tip': 'wrong email' })
def api_invite_code(num=1): if g.user.group != Group.admin: abort(400) codes = [] for i in range(num): codes.append(Code.generate_code().value) return jsonify({ 'code': 1, 'data': codes })