def save_day(): req = request.get_json() title = req.get('title') data = req.get('data', '') if not title: abort(400) username = get_jwt_identity() if not username: abort(401) user = User.query.filter_by(username=username.lower()).first() if not user: abort(400) enc_date = aes_encrypt(title) note = user.notes.filter_by(title=enc_date).first() if not Note: # Check old encryption enc_date = aes_encrypt_old(title) note = user.notes.filter_by(title=enc_date).first() if not note: note = Note(user_id=user.uuid, name=title, text=data, is_date=True) else: note.text = data db.session.add(note) db.session.flush() db.session.commit() return jsonify(note=note.serialize), 200
def get_date(): date = request.args.get('date') if not date: abort(400) username = get_jwt_identity() user = User.query.filter_by(username=username.lower()).first() if not user: abort(400) ret_note = { 'title': date, 'data': '---\ntags: \nprojects: \n---\n\n', 'is_date': True, 'user_id': user.uuid } date_enc = aes_encrypt(date) note = user.notes.filter_by(title=date_enc, is_date=True).first() if not note: # Check old encryption date_enc = aes_encrypt_old(date) note = user.notes.filter_by(title=date_enc, is_date=True).first() if note: ret_note = note.serialize return jsonify(day=ret_note), 200