コード例 #1
0
ファイル: workers.py プロジェクト: wasw100/app-ncdh
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()
コード例 #2
0
    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()
コード例 #3
0
ファイル: app.py プロジェクト: JvPost/SecurityProject
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)
コード例 #4
0
    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()
コード例 #5
0
ファイル: app.py プロジェクト: JvPost/SecurityProject
def editProfileFunc(loggedInUser, form):
    changedUsername = False
    if form.username.data is not None:
        if form.username.data != loggedInUser.username:
            dbsess = DB_Session()
            dbsess.query(User).filter(username=loggedInUser.username).update(
                {'username': form.username.data})
            dbsess.commit()
            dbsess.close()
            changedUsername = True

    if form.password.data is not None:
        if loggedInUser.username != pbkdf2_sha256.hash(form.password.data):
            dbsess = DB_Session()
            dbsess.query(User).filter(username=loggedInUser.username).update(
                {'password': pbkdf2_sha256.hash(form.password.data)})
            dbsess.commit()
            dbsess.close()

    if form.email.data is not None:
        if loggedInUser.email != form.email.data:
            dbsess = DB_Session()
            dbsess.query(User).filter(username=loggedInUser.username).update(
                {'email': form.email.data})
            dbsess.commit()
            dbsess.close()

    if changedUsername:
        dbsess = DB_Session()
        changedUser = dbsess.query(User).filter_by(
            username=form.username.data).first()
        dbsess.close()
        session['username'] = changedUser.username
コード例 #6
0
ファイル: app.py プロジェクト: JvPost/SecurityProject
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