def get_default_setting(cred_db, app_db, email): credentials = dbcalls.DB_find_one(cred_db, {'email': email}) credentials["_id"] = str(credentials["_id"]) del credentials['password'] # WARNING: this assume that there is only one application setting within the database applicationSettings = dbcalls.DB_find_one(app_db, {}) applicationSettings["_id"] = str(applicationSettings["_id"]) return jsonify({ "credentials": credentials, "applicationSettings": applicationSettings })
def create_google(): email = request.args['email'] google_id = request.args['google_id'] name = request.args['name'] createdAt = datetime.datetime.fromtimestamp(time.time()).strftime('%c') # hash the googleID and save it in pw_hash pw_hash = bcrypt.generate_password_hash(google_id.encode('utf-8')) # account exists if dbcalls.DB_find_one(credentials_collection, {'email': email}): return "An account already exists with " + email, 401 else: savedDocument = { "createdAt": createdAt, "email": email, "fullName": name, "password": pw_hash, "runTutorial": True, "defaultNoteSettings": { "noteColor": "#E1EBF5", "fontName": "Arial", "fontSize": "12", "draftjsObj": {"blocks": [{"key": "9043t", "text": " ", "type": "unstyled", "depth": 0, "inlineStyleRanges": [{"offset": 0, "length": 1, "style": "fontsize-12"}, {"offset": 0, "length": 1, "style": "fontfamily-Arial"}], "entityRanges": [], "data": {}}], "entityMap": {}} }, } document = control.new_account(credentials_collection, savedDocument) return document, 200
def verify(): current_user = get_jwt_identity() bool = False credentials = dbcalls.DB_find_one(credentials_collection, {'email': current_user}) if(credentials): bool = True return jsonify({"bool": bool}), 200
def getData(): current_user = get_jwt_identity() credentials = dbcalls.DB_find_one(credentials_collection, {'email': current_user}) if (credentials): note_and_credential = control.get_note_and_credential(notes_collection, credentials, current_user) return note_and_credential, 200 return "Invalid Email or Password", 401
def saveNote(): print(get_jwt_identity()) credentials = dbcalls.DB_find_one(credentials_collection, {'email': get_jwt_identity()}) if (credentials): form_data = json.loads(request.get_data()) control.save_note(notes_collection, form_data) return "SAVED", 200 return "NOT SAVED", 400
def updateDefaultSettings(): email = get_jwt_identity() credentials = dbcalls.DB_find_one(credentials_collection, {'email': email}) if credentials: form_data = json.loads(request.get_data()) form_data_new = json.loads(form_data['body']) control.update_default_setting(credentials_collection, form_data_new, email) return "Default Setting updated", 200 else: return "Error with JWT", 400
def login_google(): email = request.args['email'] google_id = request.args['googleID'] credentials = dbcalls.DB_find_one(credentials_collection, {'email': email}) if (credentials): if (bcrypt.check_password_hash(credentials['password'], google_id.encode('utf-8'))): login_credential = control.get_credential(credentials, email) return login_credential, 200 return "Invalid Email or Password", 401 return "Email Does Not Exist", 401
def addNote(): email = get_jwt_identity() print(email) credentials = dbcalls.DB_find_one(credentials_collection, {'email': email}) defaultNoteSettings = credentials['defaultNoteSettings']['draftjsObj'] baseNewNote = { "email": email, "title": None, "createdAt": datetime.datetime.fromtimestamp(time.time()).strftime('%c'), "content": None, "noteSettings": defaultNoteSettings, "lastUpdated": datetime.datetime.fromtimestamp(time.time()).strftime('%c'), "category": None, "noteColor": credentials['defaultNoteSettings']['noteColor'], "wordSpacing": "0.9px", "lineSpacing": "1", "isHyphenated": False } notes = control.add_note(notes_collection, baseNewNote) return notes, 200
def add_note(note_db, base_note): _id = dbcalls.DB_insert(note_db, base_note) x = dbcalls.DB_find_one(note_db, {"_id": ObjectId(_id)}) x["_id"] = str(x["_id"]) return jsonify(x)
def fetch_note(cred_db, value): data = dbcalls.DB_find_one(cred_db, value) data["_id"] = str(data["_id"]) return jsonify(data)