Ejemplo n.º 1
0
def scatman():
    um = UsersModel(db.get_connection())
    user_list = um.get_all()
    nm = NewsModel(db.get_connection())
    news_list = nm.get_all()
    stats_list = []
    for i in user_list:
        hobosti = list(
            filter(lambda x: x == i[0], map(lambda x: x[3], news_list)))
        stats_list.append([i[0], i[1], len(hobosti)])
    return render_template('stats.html', stats_list=stats_list)
Ejemplo n.º 2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        exists = user_model.exists(user_name, password)
        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
    return render_template('login.html', title='Авторизация', form=form)
Ejemplo n.º 3
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user_name = form.username.data
        pass_word = form.password.data
        um = UsersModel(db.get_connection())
        a = um.insert(user_name, pass_word)
        if a[0]:
            return redirect('/index')
        else:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   comment=a[1])

    return render_template('register.html', title='Lol', form=form, comment='')
Ejemplo n.º 4
0
	def testAddLongPassWord(self): ## Error 
		password = '******' * 200
		dataUser = UsersModel()
		self.assertEqual(dataUser.add('kkkk', password), (UsersModel.ERR_BAD_PASSWORD, self.Err_Num))
Ejemplo n.º 5
0
	def testAddDuplicateUserName(self):### Error 
		dataUser = UsersModel()
		self.assertEqual(dataUser.add('abcd', '456'), (UsersModel.ERR_USER_EXISTS, self.Err_Num))
Ejemplo n.º 6
0
	def testAddLongUserName(self):  ## Error 
		user = '******' * 130
		dataUser = UsersModel()
		self.assertEqual(dataUser.add(user, '1234'), (UsersModel.ERR_BAD_USERNAME, self.Err_Num))
Ejemplo n.º 7
0
	def testAddNullPassWord(self):  ### good one
		dataUser = UsersModel()
		self.assertEqual(dataUser.add('abc', ''), (UsersModel.SUCCESS, self.Good_Num))
Ejemplo n.º 8
0
	def testAddNullUserName(self):  ### Error 
		dataUser = UsersModel()
		self.assertEqual(dataUser.add('', '456'), (UsersModel.ERR_BAD_USERNAME, self.Err_Num))
Ejemplo n.º 9
0
	def testNullNull(self): #### Error
		dataUser = UsersModel()
		self.assertEqual(dataUser.login('', ''), (UsersModel.ERR_BAD_USERNAME, self.Err_Num))
Ejemplo n.º 10
0
	def testLoginWrongPassWord(self): #### Error
		dataUser = UsersModel()
		self.assertEqual(dataUser.login('123', '456'), (UsersModel.ERR_BAD_CREDENTIALS, self.Err_Num))
Ejemplo n.º 11
0
	def testAdd(self):    ### good one 
		dataUser = UsersModel()
		self.assertEqual(dataUser.add('123', '123'), (UsersModel.SUCCESS, self.Good_Num))
Ejemplo n.º 12
0
	def testLogin(self):   ### good one 
		dataUser = UsersModel()
		self.assertEqual(dataUser.login('abcd', 'abcd'), (UsersModel.SUCCESS, self.Good_Num ))  ### count = 2
Ejemplo n.º 13
0
from AddNews import AddNewsForm
from data_init import DB
from flask import Flask, redirect, render_template, session
from LoginForm import LoginForm
from NewsModel import NewsModel
from UsersModel import UsersModel

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
#инициализируем таблицу
db = DB('asav')
NewsModel(db.get_connection()).init_table()
UsersModel(db.get_connection()).init_table()


# http://127.0.0.1:8080/login
@app.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        exists = user_model.exists(user_name, password)
        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
    return render_template('login.html', title='Авторизация', form=form)

Ejemplo n.º 14
0
from AddNews import AddNewsForm
from data_init import DB
from LoginForm import LoginForm
from NewsModel import NewsModel
from UsersModel import UsersModel

#инициализируем таблицу
db = DB('asav')
UsersModel(db.get_connection()).init_table()
user_ = UsersModel(db.get_connection())
#добавляем пользователя (по одному!!!!!)
user_.insert('Admin', 'pass')
user_.insert('Dasip', 'BeakEasy_cool')
user_.insert('cTPoIJTeJIb', 'asdqwezxcfghrtyvbn')
user_.insert('Fred', '#@#@fff!11')