예제 #1
0
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
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
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
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
    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
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
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
def createTable():
    db.create_all()
    return 'OK'
예제 #29
0
from App import db
#from App.models import tempSensorData, adminUsers
from App.models import sensorData, adminUsers

db.create_all()
예제 #30
0
 def setUp(self):
     db.create_all()
     db.session.add(Users("hanna", "hanna", "*****@*****.**"))
     # db.session.add(BlogPost("hello", "hello"))
     db.session.commit()
예제 #31
0
def create_tables():
    db.create_all()
예제 #32
0
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
 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)