예제 #1
0
def send_mail_password_reset(email):
    user = db.users.find_one({'email': email})
    if user:
        hashlink = get_hash(email)
        create_reset_mail_object(email, str(hashlink))
        updates = {
            RESET_PASSWORD_DATE: get_date(),
            RESET_PASSWORD_HASH: get_date(),
            LAST_UPDATED: get_date()
        }
        db.users.update(
            {'_id': ObjectId(user['_id'])},
            {"$inc": {"r": 1}, "$set": updates},
            upsert=False)
    else:
        logger.error("no user found with email: " + email)
예제 #2
0
파일: auth.py 프로젝트: ipedrazas/dotmarks
def reset_password():
    print "reset_password"
    try:
        data = json.loads(request.data)
        print data
        password = data['password']
        token = data['token']

        if password and token:
            users = app.data.driver.db['users']
            user = users.find_one({"_reseth": token})
            if user:
                pwd = get_hash(password, user['salt'])
                updates = {
                    RESET_PASSWORD_DATE: None,
                    RESET_PASSWORD_HASH: None,
                    LAST_UPDATED: get_date(),
                    "password": pwd
                }
                users.update({"_reseth": token}, {"$set": updates})
                response = Response('password updated', 200)
        else:
            response = Response('email not found', 406)
    except:
        response = Response('data not valid', 400)

    # response.headers.add('Access-Control-Allow-Origin', '*')
    # response.headers.add('AccessControlAllowMethods', 'POST, OPTIONS')
    # response.headers.add('Access-Control-Allow-Headers', '*')

    return response
예제 #3
0
def parse_html(oid):
    cursor = db.attachments.find({'_id': ObjectId(oid)})
    for attachment in cursor:
        html = fs.get(attachment['file']).read()
        # print html
        for link in BeautifulSoup(html, parseOnlyThese=SoupStrainer('a')):
            if link:
                # print link.contents
                dk = {}
                dk['url'] = link['href']
                print "parsing " + link['href']
                if ',' in link['tags']:
                    tags = link['tags'].strip().split(',')
                    if tags:
                        dk['tags'] = tags
                dk['username'] = attachment['user']
                if link.contents[0]:
                    title = link.contents[0]
                    print title
                    if 'http' != title[:4]:
                        dk['title'] = title
                if 'title' not in dk:
                    dk['title'] = get_title_from_url(dk['url'])
                new_id = dks.insert(dk)
                if new_id:
                    users.update({'username': attachment['user']},
                                 {"$inc": {"dots": 1},
                                  "$set": {LAST_UPDATED: get_date()}},
                                 upsert=False)
예제 #4
0
def parse_html(oid):
    cursor = db.attachments.find({'_id': ObjectId(oid)})
    for attachment in cursor:
        html = fs.get(attachment['file']).read()
        # print html
        for link in BeautifulSoup(html, parseOnlyThese=SoupStrainer('a')):
            if link:
                # print link.contents
                dk = {}
                dk['url'] = link['href']
                print "parsing " + link['href']
                if ',' in link['tags']:
                    tags = link['tags'].strip().split(',')
                    if tags:
                        dk['tags'] = tags
                dk['username'] = attachment['user']
                if link.contents[0]:
                    title = link.contents[0]
                    print title
                    if 'http' != title[:4]:
                        dk['title'] = title
                if 'title' not in dk:
                    dk['title'] = get_title_from_url(dk['url'])
                new_id = dks.insert(dk)
                if new_id:
                    users.update({'username': attachment['user']}, {
                        "$inc": {
                            "dots": 1
                        },
                        "$set": {
                            LAST_UPDATED: get_date()
                        }
                    },
                                 upsert=False)
예제 #5
0
def parse_html(oid):
    cursor = db.attachments.find({"_id": ObjectId(oid)})
    for attachment in cursor:
        html = fs.get(attachment["file"]).read()
        # print html
        for link in BeautifulSoup(html, parseOnlyThese=SoupStrainer("a")):
            if link:
                # print link.contents
                dk = {}
                dk["url"] = link["href"]
                print "parsing " + link["href"]
                if "," in link["tags"]:
                    tags = link["tags"].strip().split(",")
                    if tags:
                        dk["tags"] = tags
                dk["username"] = attachment["user"]
                if link.contents[0]:
                    title = link.contents[0]
                    print title
                    if "http" != title[:4]:
                        dk["title"] = title
                if "title" not in dk:
                    dk["title"] = get_title_from_url(dk["url"])
                new_id = dks.insert(dk)
                if new_id:
                    users.update(
                        {"username": attachment["user"]},
                        {"$inc": {"dots": 1}, "$set": {LAST_UPDATED: get_date()}},
                        upsert=False,
                    )
예제 #6
0
def reset_password():
    print "reset_password"
    try:
        data = json.loads(request.data)
        print data
        password = data['password']
        token = data['token']

        if password and token:
            users = app.data.driver.db['users']
            user = users.find_one({"_reseth": token})
            if user:
                pwd = get_hash(password, user['salt'])
                updates = {
                    RESET_PASSWORD_DATE: None,
                    RESET_PASSWORD_HASH: None,
                    LAST_UPDATED: get_date(),
                    "password": pwd
                }
                users.update({"_reseth": token}, {"$set": updates})
                response = Response('password updated', 200)
        else:
            response = Response('email not found', 406)
    except:
        response = Response('data not valid', 400)

    # response.headers.add('Access-Control-Allow-Origin', '*')
    # response.headers.add('AccessControlAllowMethods', 'POST, OPTIONS')
    # response.headers.add('Access-Control-Allow-Headers', '*')

    return response
예제 #7
0
def post_login(item):
    if 'username' in item:
        updates = {
            RESET_PASSWORD_DATE: None,
            RESET_PASSWORD_HASH: None,
            LAST_UPDATED: get_date()
        }
        db.users.update({'username': item['username']}, {"$set": updates},
                        upsert=False)
예제 #8
0
def send_mail_password_reset(email):
    user = db.users.find_one({'email': email})
    if user:
        hashlink = get_hash(email)
        create_reset_mail_object(email, str(hashlink))
        updates = {
            RESET_PASSWORD_DATE: get_date(),
            RESET_PASSWORD_HASH: get_date(),
            LAST_UPDATED: get_date()
        }
        db.users.update({'_id': ObjectId(user['_id'])}, {
            "$inc": {
                "r": 1
            },
            "$set": updates
        },
                        upsert=False)
    else:
        logger.error("no user found with email: " + email)
예제 #9
0
def post_login(item):
    if 'username' in item:
        updates = {
            RESET_PASSWORD_DATE: None,
            RESET_PASSWORD_HASH: None,
            LAST_UPDATED: get_date()
        }
        db.users.update(
            {'username': item['username']},
            {"$set": updates},
            upsert=False)
예제 #10
0
def parse_log(item):
    if 'source_id' in item:
        oid = item['source_id']
        if(item['action'] == 'click'):
            db.dotmarks.update(
                {"_id": ObjectId(oid)},
                {"$inc": {"views": 1}, "$set": {LAST_UPDATED: get_date()}},
                upsert=False)

        if(item['action'] == 'star'):
            updates = {'star': 'true' in item['value']}
            do_update(oid, updates)
예제 #11
0
def parse_log(item):
    if 'source_id' in item:
        oid = item['source_id']
        if (item['action'] == 'click'):
            db.dotmarks.update({"_id": ObjectId(oid)}, {
                "$inc": {
                    "views": 1
                },
                "$set": {
                    LAST_UPDATED: get_date()
                }
            },
                               upsert=False)

        if (item['action'] == 'star'):
            updates = {'star': 'true' in item['value']}
            do_update(oid, updates)
예제 #12
0
def reset_password():
    print "reset_password"
    document = {}
    status = 200

    if request.method == 'OPTIONS':
        resp = app.make_default_options_response()
    else:

        try:
            data = json.loads(request.data)
            password = data['password']
            token = data['token']
            if password and token:
                users = app.data.driver.db['users']
                user = users.find_one({"_reseth": token})
                if user:
                    pwd = get_hash(password, user['salt'])
                    updates = {
                        RESET_PASSWORD_DATE: None,
                        RESET_PASSWORD_HASH: None,
                        LAST_UPDATED: get_date(),
                        "password": pwd
                    }
                    users.update({"_reseth": token}, {"$set": updates})
                    document = {'result': 'password updated'}
            else:
                status = 406
                document = {'err': 'email not found'}
        except:
            document = {'err': 'data not valid'}
            status = 400

        resp = make_response(jsonify(document), status)
        resp.mimetype = 'application/json'

    return add_headers(resp)