def save_item(item, update_desc=False): baidu_id = item.get('id') if baidu_id is None: return session = DB_Session() photo = session.query(Photo).filter(Photo.baidu_id==baidu_id).first() if not photo: photo = Photo(baidu_id=baidu_id, photo_id=item['photo_id'], image_url = item['image_url'], image_width = item['image_width'], image_height = item['image_height'], thumbnail_url = item['thumbnail_url'], thumbnail_width = item['thumbnail_width'], thumbnail_height = item['thumbnail_height'], thumb_large_url = item['thumb_large_url'], thumb_large_width = item['thumb_large_width'], thumb_large_height = item['thumb_large_height'], from_url = item['from_url'], obj_url = item['obj_url'], desc = item['desc'], image_date = item['date'], insert_date = datetime.datetime.now() ) session.add(photo) session.commit() logging.warn("add one item-%s" % photo.id) elif update_desc: photo.desc = item['desc'] session.commit() logging.warn("update one item-%s" % photo.id) session.close()
def register(): form = RegistrationForm(request.form) if form.validate_on_submit(): db_session = DB_Session() hashedPWD = pbkdf2_sha256.hash(form.password.data) newUser = User(form.username.data, hashedPWD, form.email.data, form.twoFactorAuthEnabled.data, form.twoFactorAuthKey.data) db_session.add(newUser) db_session.commit() db_session.close() # app.logger.info('Account created with username: %s' % form.username.data) return render_template('index.html') return render_template('register.html', form=form)
def SendAndSaveForgotPasswordCode(email): code = os.urandom(8) content = "Yo dog here's your code to reset your password: \n <b>%s</b>" % ( code) print(email) try: server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login('*****@*****.**', 'Geheimlol!1') server.sendmail('*****@*****.**', email, content) server.close() dbsess = DB_Session() user = dbsess.query(User).filter_by(email=email).first() newCode = ResetPwdCode(owner=user.username, code=code) dbsess.add(newCode) dbsess.commit() dbsess.close() except: pass
def __init__(self): sess = DB_Session() roles = sess.query(Role).all() if (len(roles) == 0): normal = Role("normal") admin = Role("admin") helpdesk = Role("helpdesk") sess.add(normal) sess.add(admin) sess.add(helpdesk) sess.commit() sess.close()
def __init__(self): sess = DB_Session() users = sess.query(User).all() if len(users) == 0: sess.add( User('Piet', '*****@*****.**', pbkdf2_sha256.hash('Asdf1234'), True, 'averylonglonglongkey', 1)) sess.add( User('Klaas', '*****@*****.**', pbkdf2_sha256.hash('Asdf1234'), True, 'averytalltalltallkey', 2)) sess.add( User('Freek', '*****@*****.**', pbkdf2_sha256.hash('Asdf1234'), True, 'averyhandsomelongkey', 3)) sess.commit() sess.close()