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)
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
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)
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)
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, )
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)
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)
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)
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)
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)
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)