コード例 #1
0
ファイル: hash.py プロジェクト: hputiprawan2/Web-Blog
def isHack(username):
    
    hash1 = HashLog.query.with_entities(HashLog.hash_org).filter(HashLog.hash_name == username)\
                    .order_by(desc(HashLog.hash_time)).first()
    hash2 = HashLog.query.with_entities(HashLog.hash_comp).filter(HashLog.hash_name == username)\
                    .order_by(desc(HashLog.hash_time)).first()

    # get the id of last login user to compare
    lastSeenID = db.session.query(HashLog).with_entities(HashLog.hash_id) \
                    .filter(HashLog.hash_name == username) \
                    .order_by(desc(HashLog.hash_time)).first()

    # if the hashes are the same, then it doesnt get hacked
    if compHash(hash1, hash2):
        return False
    else: # if not then there is some external modify, or might get hacked 
        try: 
            db.create_all()
            db.session.query(HashLog).filter(HashLog.hash_id == lastSeenID[0])\
                    .update({'hash_isHack': 'isHack'})
            db.session.commit()
            return True
        except:
            print 'error in update isHack()'
            db.session.rollback()
    
        return True
コード例 #2
0
 def test_obter_autor_por_nome(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Autor('Jose'))
     db.session.commit()
     self.assertEqual(modelsDAO.obter_autor_por_nome('Jose'),
                      models.Autor.query.filter_by(nome='Jose').first())
コード例 #3
0
ファイル: views.py プロジェクト: hputiprawan2/Web-Blog
def addPosts(postType, postTitle, postPrivacy, postContent): 
            try:

                user = current_user.get_id()
                post = Posts(
                    post_type=postType,
                    post_title=postTitle,
                    post_privacy=postPrivacy,
                    post_content=postContent,
                    post_authorID=user
                )
                db.create_all()
                db.session.add(post)
                db.session.commit()

                # get post_id for trigger
                postID = db.session.query(Posts.post_id)\
                .filter(Posts.post_type == postType)\
                .filter(Posts.post_title == postTitle)\
                .filter(Posts.post_privacy == postPrivacy)\
                .filter(Posts.post_content == postContent)\
                .filter(Posts.post_authorID == user).first()

                Log(action='ADD', 
                postID=postID[0],
                postTitle=postTitle,  
                postType=postType,
                postPrivacy=postPrivacy,
                postContent=postContent)

            except:
                Log("ADD FAIL")
                db.session.rollback()
                flash('Fail to add post!')
コード例 #4
0
ファイル: views.py プロジェクト: hputiprawan2/Web-Blog
def register():
    error = None
    form = SignupForm()
    if request.method == 'POST':
        if request.form.get('submit') == 'Cancel':
            return redirect(url_for('UsersFiles.login'))
        
        elif form.validate_on_submit():
            try: 
                user = Users(
                    user_name=form.user_name.data,
                    user_password=form.user_password1.data 
                )
                db.create_all()
                db.session.add(user)
                db.session.commit()
                Log("SIGNUP")

                login_user(user)
                Log("LOGIN")
                # add hash
                addCompHash(str(current_user))
                flash('You are just login!')
                return redirect(url_for('HomeFiles.home'))

            except:
                error = 'Signup Fail'
                db.session.rollback()
                Log("SIGNUP FAIL")
            #     trace= get_current_traceback(skip=1, show_hidden_frames=True,
            # ignore_system_exceptions=False)
            # return redirect(url_for('ShareFiles.stack_trace', trace=trace))
            

    return render_template('register.html', form = form, error = error) 
コード例 #5
0
ファイル: hash.py プロジェクト: hputiprawan2/Web-Blog
def addCompHash(username):

        # get the data that you want to generate 
        data = getData(username)
        # data = getData()

        # make a hash
        hash_data = makeHash(data)

        try: 
            # first time login, so nothing to compare, just add the new org hash 
            exist_user = HashLog.query.filter(HashLog.hash_name == username).first()
            if exist_user is None:
                myHash = HashLog(
                    hash_name=username,
                    hash_org=hash_data
                ) 
                db.create_all()
                db.session.add(myHash)
                db.session.commit()
            else:
                db.create_all()
                # get the id of last login user to compare
                lastSeenID = db.session.query(HashLog).with_entities(HashLog.hash_id) \
                                .filter(HashLog.hash_name == username) \
                                .order_by(desc(HashLog.hash_id)).first()
                # Save the hash into db
                db.session.query(HashLog).filter(HashLog.hash_id == lastSeenID[0])\
                        .update({'hash_comp': hash_data, 'hash_time': datetime.now()})
                
                db.session.commit()
        except:
            print 'error in addCompHash()'
            db.session.rollback()
コード例 #6
0
 def test_obter_editora_por_nome(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Editora('Amago'))
     db.session.commit()
     self.assertEqual(modelsDAO.obter_editora_por_nome('Amago'),
                      models.Editora.query.filter_by(nome='Amago').first())
コード例 #7
0
 def test_inserir_editora(self):
     db.drop_all()
     db.create_all()
     nome = 'Amago'
     editoraTest = models.Editora(nome)
     modelsDAO.inserir_editora(editoraTest.nome)
     editora = models.Editora.query.filter_by(nome='Amago').first()
     self.assertEqual(compareObjects(editora, editoraTest), True)
コード例 #8
0
 def test_obter_autores(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Autor('Jose'))
     db.session.add(models.Autor('Francisco'))
     db.session.commit()
     autor = modelsDAO.obter_autores()
     self.assertEqual(autor, models.Autor.query.all())
コード例 #9
0
 def test_obter_usuarios(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Usuario('Augusto', 'augusto', '1234', 1))
     db.session.add(models.Usuario('Fernanda', 'fernanda', '1234', 2))
     db.session.commit()
     usuarios = modelsDAO.obter_usuarios()
     self.assertEqual(usuarios, models.Usuario.query.all())
コード例 #10
0
 def test_obter_editoras(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Editora('Alfa'))
     db.session.add(models.Editora('Omega'))
     db.session.commit()
     editora = modelsDAO.obter_editoras()
     self.assertEqual(editora, models.Editora.query.all())
コード例 #11
0
 def test_inserir_autor(self):
     db.drop_all()
     db.create_all()
     nome = 'Jose'
     autorTest = models.Autor(nome)
     modelsDAO.inserir_autor(autorTest.nome)
     autor = models.Autor.query.filter_by(nome='Jose').first()
     self.assertEqual(compareObjects(autor, autorTest), True)
コード例 #12
0
 def test_atualizar_editora(self):
     db.drop_all()
     db.create_all()
     editora = models.Editora('Alfa')
     db.session.add(editora)
     db.session.commit()
     editoraTest = models.Editora('novo nome')
     modelsDAO.atualizar_editora(editora.id, editoraTest.nome)
     self.assertEqual(compareObjects(editora, editoraTest), True)
コード例 #13
0
 def test_obter_usuario_por_user(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Usuario('Augusto', 'augusto', '1234', 1))
     db.session.add(models.Usuario('Fernanda', 'fernanda', '1234', 2))
     db.session.commit()
     self.assertEqual(
         modelsDAO.obter_usuario_por_user('augusto'),
         models.Usuario.query.filter_by(user='******').first())
コード例 #14
0
 def test_remover_autor(self):
     db.drop_all()
     db.create_all()
     autor = models.Autor('Jose')
     db.session.add(autor)
     db.session.commit()
     idAutor = autor.id
     modelsDAO.remover_autor(autor.id)
     self.assertEqual(models.Autor.query.get(idAutor), None)
コード例 #15
0
 def test_atualizar_autor(self):
     db.drop_all()
     db.create_all()
     autor = models.Autor('Jose')
     db.session.add(autor)
     db.session.commit()
     autorTest = models.Autor('novo nome')
     modelsDAO.atualizar_autor(autor.id, autorTest.nome)
     self.assertEqual(compareObjects(autor, autorTest), True)
コード例 #16
0
 def test_remover_usuario(self):
     db.drop_all()
     db.create_all()
     usuario = models.Usuario('Augusto', 'augusto', '1234', 1)
     db.session.add(usuario)
     db.session.commit()
     idUsuario = usuario.id
     modelsDAO.remover_usuario(usuario.id)
     self.assertEqual(models.Usuario.query.get(idUsuario), None)
コード例 #17
0
 def test_remover_editora(self):
     db.drop_all()
     db.create_all()
     editora = models.Editora('Omega')
     db.session.add(editora)
     db.session.commit()
     idEditora = editora.id
     modelsDAO.remover_editora(editora.id)
     self.assertEqual(models.Editora.query.get(idEditora), None)
コード例 #18
0
ファイル: db.py プロジェクト: Alexanderlacuna/linksbank
    def add_db(self):
        try:
            db.create_all()

            db.session.add(self)
            db.session.commit()
        except Exception as e:
            raise e

        return "success"
コード例 #19
0
 def test_atualizar_usuario(self):
     db.drop_all()
     db.create_all()
     usuario = models.Usuario('Augusto', 'augusto', '1234', 1)
     db.session.add(usuario)
     db.session.commit()
     userTest = models.Usuario('novo nome', usuario.user, 'nova senha',
                               usuario.tipo)
     modelsDAO.atualizar_usuario(usuario.id, userTest.nome, userTest.senha)
     self.assertEqual(compareObjects(usuario, userTest), True)
コード例 #20
0
 def test_inserir_usuario(self):
     db.drop_all()
     db.create_all()
     nome = 'Augusto'
     user = '******'
     senha = '1234'
     tipo = 1
     db.session.add(models.Usuario('Fernanda', 'fernanda', '1234', 2))
     userTest = models.Usuario(nome, user, senha, tipo)
     modelsDAO.inserir_usuario(userTest.nome, userTest.user, userTest.senha,
                               userTest.tipo)
     usuario = models.Usuario.query.filter_by(user='******').first()
     self.assertEqual(compareObjects(usuario, userTest), True)
コード例 #21
0
 def test_obter_livro(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Autor('Jose'))
     db.session.add(models.Editora('Alfa'))
     autor = models.Autor.query.filter_by(nome='Jose').first()
     editora = models.Editora.query.filter_by(nome='Alfa').first()
     db.session.add(
         models.Livro(
             123456, 'A volta dos que não foram', 'Drama', 1, 2007,
             'Esse livro é um drama sobra a volta dos que não foram', 2,
             editora.id, autor.id))
     db.session.commit()
     livro = modelsDAO.obter_livros()
     self.assertEqual(livro, models.Livro.query.all())
コード例 #22
0
ファイル: views.py プロジェクト: hputiprawan2/Web-Blog
def addComment(comment_postID, comment_content):   
    try:
        comment = Comments(
            comment_postID=comment_postID,
            comment_owner=current_user.get_id(),
            comment_content=comment_content
        )
        db.create_all()
        db.session.add(comment)
        db.session.commit()

        # Log
        commentLog('COMMENT', comment_postID, current_user.get_id(), current_user, comment_content)

    except:
        print 'addComment fail'
        db.session.rollback()
        flash('Fail to add comment!')
コード例 #23
0
 def test_inserir_livro(self):
     db.drop_all()
     db.create_all()
     db.session.add(models.Autor('Jose'))
     db.session.add(models.Editora('Alfa'))
     db.session.commit()
     autor = models.Autor.query.filter_by(nome='Jose').first()
     editora = models.Editora.query.filter_by(nome='Alfa').first()
     livroTest = models.Livro(
         123456, 'A volta dos que não foram', 'Drama', 1, 2007,
         'Esse livro é um drama sobra a volta dos que não foram', 2,
         editora.id, autor.id)
     modelsDAO.inserir_livro(
         123456, 'A volta dos que não foram', 'Drama', 1, 2007,
         'Esse livro é um drama sobra a volta dos que não foram', 2,
         editora.id, autor.id)
     livro = models.Livro.query.filter_by(isbn=livroTest.isbn).first()
     self.assertEqual(compareObjects(livro, livroTest), True)
コード例 #24
0
ファイル: hash.py プロジェクト: hputiprawan2/Web-Blog
def addOrgHash(username):

        # get the data that you want to generate 
        data = getData(username)
        # data = getData()

        # make a hash
        hash_data = makeHash(data)
        
        try: 
            db.create_all()
            myHash = HashLog(
                    hash_name=username,
                    hash_org=hash_data
                ) 
            db.session.add(myHash)
            db.session.commit()
        except:
                print 'error in addOrgHash()'
                db.session.rollback()
コード例 #25
0
 def setUp(self) -> None:
     self.app = create_app("testing")
     self.app_content = self.app.app_context()
     self.app_content.push()
     db.create_all()
コード例 #26
0
ファイル: views.py プロジェクト: 845788173/copy
def create_all():
    db.create_all()
    return 'hjfsfjaj'
コード例 #27
0
def create_db():
    db.create_all()
コード例 #28
0
ファイル: views.py プロジェクト: qiOstrich/flask-code
def createTable():
    db.create_all()
    return 'OK'
コード例 #29
0
ファイル: create_db.py プロジェクト: heikern/simpleData
from App import db
#from App.models import tempSensorData, adminUsers
from App.models import sensorData, adminUsers

db.create_all()
コード例 #30
0
ファイル: unitTest.py プロジェクト: hputiprawan2/Web-Blog
 def setUp(self):
     db.create_all()
     db.session.add(Users("hanna", "hanna", "*****@*****.**"))
     # db.session.add(BlogPost("hello", "hello"))
     db.session.commit()
コード例 #31
0
ファイル: wsgi.py プロジェクト: Asada-san/RunescapeCalculator
def create_tables():
    db.create_all()
コード例 #32
0
ファイル: views.py プロジェクト: hello-rgv/work_servers
def db_create():
    db.drop_all()
    db.create_all()
    return 'db_create'
コード例 #33
0
def create_table():
    db.create_all()
    return '创建成功'
コード例 #34
0
    def __init__(self, id, news_cate,news_title, news_desc, news_content,news_img, news_imgcounts, news_paltform,
                 news_author,crawled_time,create_time):
        self.news_cate = news_cate
        self.news_title = news_title
        self.news_desc = news_desc
        self.news_content = news_content
        self.news_img = news_img
        self.news_imgcounts = news_imgcounts
        self.news_paltform = news_paltform
        self.news_author = news_author
        self.crawled_time = crawled_time
        self.create_time = create_time


db.create_all(app=create_app())

# 初始化role 并插入数据库
# db.create_all()
# test_role1 = Role(1 ,'supervisol', '超超超超级管理员哦')
#
# test_role2 = Role(2,'your try', '你试试哦')
# db.session.add_all([test_role1,test_role2])
# db.session.commit()


# #查询数据库
# a = db.session.query(Role).filter_by(id=2).first()  # 查询role表中id为2的第一个匹配项目,用".字段名"获取字段值
# print(a)
# db.session.query(role).all()  # 得到一个list,返回role表里的所有role实例
# db.session.query(role).filter(role.id == 2).first() # 结果与第一种一致
コード例 #35
0
ファイル: tests.py プロジェクト: AnhNguyen20695/SeeBook_new
 def setUp(self):
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
     db.create_all()
コード例 #36
0
 def setUp(self):
     db.drop_all()
     db.create_all()
     print('Setup completo')
コード例 #37
0
from App import db
from App.views import Response

db.reflect()
db.drop_all()
db.create_all()

users = Response.query.all()
for user in users:
    db.session.delete(user)
    db.session.commit()
コード例 #38
0
from App import createApp, db

# Create flask application
app = createApp()

# create the database and the database tables
db.create_all(app=app)

if __name__ == '__main__':
    app.run(debug=True)