Ejemplo n.º 1
0
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())

        all_data = user_model.get_all()
        for x in all_data:
            if username == x[1]:
                return render_template(
                    'reg.html',
                    title='Регистрация',
                    form=form,
                    alert='Такой пользователь уже зареестрирован')

        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html',
                           title='Регистрация',
                           form=form,
                           alert='')
Ejemplo n.º 2
0
def login():
    form = LoginForm()
    user_name = form.username.data
    password = form.password.data
    user_model = UsersModel(db.get_connection())
    exists = user_model.exists(user_name, password)
    if form.validate_on_submit():

        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
    return render_template('login.html', form=form, message=user_model.exists(user_name, password)[1])
Ejemplo n.º 3
0
def login():
    try:
        if session['user_id']:
            return redirect("/index")
    except:
        pass
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(users_db.get_connection())
        true_pass = user_model.password_check(user_name)
        exists = user_model.exists(user_name, true_pass)
        if check_password_hash(true_pass, password) and exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            session['block'] = exists[2]
            return redirect("/index")
        else:
            all_data = user_model.get_all()
            for x in all_data:
                if user_name == x[1]:
                    return render_template('login.html',
                                           title='Авторизация',
                                           form=form,
                                           alert='Неправильный пароль')
            return render_template('login.html',
                                   title='Авторизация',
                                   form=form,
                                   alert='Такой пользователь не существует')
    return render_template('login.html',
                           title='Авторизация',
                           form=form,
                           alert='')
Ejemplo n.º 4
0
def reg():
    form = RegForm()
    if form.validate_on_submit():
        username = form.username.data
        name = form.name.data
        surname = form.surname.data
        password = form.password.data
        confirm = form.confirm.data
        password_hash = generate_password_hash(password)
        user_model = UsersModel(users_db.get_connection())
        exists = user_model.exists(username, password_hash)
        if not exists[0] and password == confirm:
            user_model.insert(username, name, surname, password_hash)
            exists = user_model.exists(username, password_hash)
            session['username'] = username
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('reg.html', title='Sign up', form=form)
Ejemplo n.º 5
0
def login():
    global ind
    form = LoginForm()
    if form.validate_on_submit():
        f = open('admins', encoding="utf-8", mode='r+')
        data = f.read().split('\n')
        ff = open('users', encoding="utf-8", mode='r+')
        data1 = ff.read().split('\n')
        logins = {}
        login = []
        for i in data:
            i = i.split(':')
            logins[str(i[0])] = str(i[1])
            login.append(str(i[0]))
            user_name = str(form.username.data)
            password = str(form.password.data)
            if user_name in login:
                if str(logins[user_name]) == str(password):
                    user_model = UsersModel(db.get_connection())
                    user_model.insert(user_name, password)
                    exists = user_model.exists(user_name, password)
                    if (exists[0]):
                        session['username'] = user_name
                        session['user_id'] = exists[1]
                return redirect("/admin")
            else:
                for i in data1:
                    i = i.split(':')
                    logins[i[0]] = i[1]
                    login.append(i[0])
                    user_name = form.username.data
                    password = form.password.data
                    if user_name in login:
                        if str(logins[user_name]) == str(password):
                            user_model = UsersModel(db.get_connection())
                            user_model.insert(user_name, password)
                            exists = user_model.exists(user_name, password)
                            if (exists[0]):
                                session['username'] = user_name
                                session['user_id'] = exists[1]
                        return redirect("/user")
    return render_template('login.html', title='Авторизация', form=form)
Ejemplo n.º 6
0
def sign_in():
    form = SigninForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(u_db.get_connection())
        exists = user_model.exists(user_name, password)
        if exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect('/home')
    return render_template('sign_in.html', title='Авторизация', form=form)
Ejemplo n.º 7
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(users_db.get_connection())
        true_pass = user_model.password_check(user_name)
        exists = user_model.exists(user_name, true_pass)
        if check_password_hash(true_pass, password) and exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('login.html', title='Sign in', form=form)
Ejemplo n.º 8
0
def sign_up():
    if request.method == 'POST':
        user_name = request.form['login']
        password = request.form['password']
        card_number = request.form['card_number']
        expiry_m = request.form['expiry_m']
        expiry_y = request.form['expiry_y']
        name = request.form['name']
        safe_number = request.form['ccv']
        money = request.form['money']
        user_model = UsersModel(u_db.get_connection())
        if not user_model.exists(user_name)[0] and card_check(card_number) and check_data(expiry_m, expiry_y) and\
            name_check(name) and cvv_check(safe_number) and check_money(money):
            if not user_model.exist_card_number(card_number)[0]:
                user_model.insert(user_name, password, card_number, expiry_m,
                                  expiry_y, name, safe_number, money)
                session['username'] = user_name
                session['user_id'] = user_model.exists(user_name, password)[1]
                return redirect('/home')
        else:
            return render_template('sign_up2.html', title='Регистрация')
    return render_template('sign_up.html', title='Регистрация')
Ejemplo n.º 9
0
def register():
    form = RegisterForm()
    if request.method == 'GET':
        return render_template('register.html', form=form)
    elif request.method == 'POST':
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        user_model.insert(user_name, password)
        exists = user_model.exists(user_name, password)
        if (exists[0]):
            session['username'] = user_name
            session['user_id'] = exists[1]
        return redirect("/index")
Ejemplo n.º 10
0
def reg():
    form = RegistForm()
    if form.validate_on_submit():
        ind = ''
        f = open('users', encoding="utf-8", mode='r+')
        ff = open('admins', encoding="utf-8", mode='r+')
        datauser = f.read()
        dataadmin = ff.read()
        user_name = form.username.data
        password = form.password.data
        repeat = form.repeat.data
        mail = form.mail.data
        code = form.user_admin.data
        user_model = UsersModel(db.get_connection())
        user_model.insert(user_name, password)
        exists = user_model.exists(user_name, password)
        if str(code) == 'sell':
            ind = 'admin'
        else:
            ind = 'user'
        if password != repeat:
            return redirect('/register')
        if ind == 'admin':
            if user_name not in dataadmin:
                ff.write('\n')
                ff.write(user_name)
                ff.write(':')
                ff.write(password)
                ff.write(':')
                ff.write(mail)
            else:
                return redirect('/register')
        else:
            if user_name not in datauser:
                f.write('\n')
                f.write(user_name)
                f.write(':')
                f.write(password)
                f.write(':')
                f.write(mail)
            else:
                return redirect('/register')
        if exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
            return redirect("/index")
    return render_template('regist.html', title='Регистрация', form=form)
Ejemplo n.º 11
0
def api_auth():
    if not request.json:
        return json.dumps({'error': 'Empty request'})
    elif not all(key in request.json for key in ['pass', 'login']):
        return json.dumps({'error': 'Bad request'})

    password = request.json['pass']
    user_name = request.json['login']

    user_model = UsersModel(users_db.get_connection())
    true_pass = user_model.password_check(user_name)
    exists = user_model.exists(user_name, true_pass)
    if check_password_hash(true_pass, password) and exists[0]:
        token = generate_password_hash(str(password) + str(user_name))
        user_model.add_token(token, exists[1])
        return json.dumps({'token': token})
    else:
        return json.dumps({'error': 'Incorrect info'})
Ejemplo n.º 12
0
def register():
    form = RegisterForm()
    if request.method == 'GET':
        return render_template('register.html', form=form, message="")
    elif request.method == 'POST':
        if form.password.data != form.trypassword.data:
            return render_template('register.html',
                                   form=form,
                                   message="Пароли не совпадают")
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        if user_model.get_by_name(user_name) is None:
            user_model.insert(user_name, password)
            exists = user_model.exists(user_name, password)
            return redirect("/login")
        else:
            return render_template(
                'register.html',
                form=form,
                message="Такой пользователь уже есть. Исправьте данные")
        """