예제 #1
0
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
    })
예제 #2
0
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
예제 #3
0
def getArrayOfNotes(note_db, email):
    userNotes = dbcalls.DB_find(note_db, {'email': email})
    arrayOfNotes = []
    for doc in userNotes:
        doc["_id"] = str(doc["_id"])
        arrayOfNotes.append(doc)
    return arrayOfNotes
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
파일: app.py 프로젝트: cnhexin/writefree-be
def deleteNote():
    email = get_jwt_identity()
    noteID = request.args['noteID']
    dbcalls.DB_delete_one(notes_collection, {
        'email': email,
        "_id": ObjectId(noteID)
    })
    notes = control.get_note(notes_collection, email)
    return notes, 200
예제 #8
0
def save_note(note_db, form_data):
    query = {"_id": ObjectId(form_data['noteID'])}
    new_values = {
        "title": form_data['title'],
        "category": form_data['category'],
        "content": form_data['noteContent'],
        "lastUpdated":
        datetime.datetime.fromtimestamp(time.time()).strftime('%c')
    }
    dbcalls.DB_update_one(note_db, {"$set": new_values}, query)
예제 #9
0
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
예제 #10
0
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
예제 #11
0
def new_account(cred_db, savedDocument):
    dbcalls.DB_insert_one(cred_db, savedDocument)
    savedDocument["_id"] = str(savedDocument["_id"])
    del savedDocument['password']
    access_token = create_access_token(identity=savedDocument["email"])
    refresh_token = create_refresh_token(identity=savedDocument["email"])
    return jsonify({
        "credentials": savedDocument,
        "access_token": access_token,
        "refresh_token": refresh_token
    })
예제 #12
0
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
예제 #13
0
def update_default_setting(cred_db, form_data, email):
    noteColor = form_data['noteColor']
    fontName = form_data['fontName']
    fontSize = form_data['fontSize']
    draftjs = {
        "blocks": [{
            "key":
            "9043t",
            "text":
            " ",
            "type":
            "unstyled",
            "depth":
            0,
            "inlineStyleRanges": [{
                "offset": 0,
                "length": 1,
                "style": "fontsize-" + str(fontSize)
            }, {
                "offset": 0,
                "length": 1,
                "style": "fontfamily-" + fontName
            }],
            "entityRanges": [],
            "data": {}
        }],
        "entityMap": {}
    }
    query = {
        '$set': {
            'defaultNoteSettings': {
                'noteColor': noteColor,
                'fontName': fontName,
                'fontSize': fontSize,
                'draftjsObj': draftjs
            }
        }
    }
    dbcalls.DB_find_one_and_update(cred_db, {'email': email}, query)
예제 #14
0
파일: app.py 프로젝트: cnhexin/writefree-be
def changeNoteColor():
    noteID = ObjectId(request.args['noteID'])
    noteColor = request.args['noteColor']
    query = {'$set': {'noteColor': noteColor}}
    dbcalls.DB_find_one_and_update(notes_collection, {'_id': noteID}, query)
    return "Note Color Changed", 200
예제 #15
0
def disable_tutorial(cred_db, email):
    query = {'$set': {'runTutorial': False}}
    dbcalls.DB_find_one_and_update(cred_db, {'email': email}, query)
예제 #16
0
def fetch_note(cred_db, value):
    data = dbcalls.DB_find_one(cred_db, value)
    data["_id"] = str(data["_id"])
    return jsonify(data)
예제 #17
0
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)