Пример #1
0
def create():
    email = request.form['email']
    phone = request.form['phone']
    password = request.form['password']
    password_confirmation = request.form['password_confirmation']

    validator = CombinedValidator(validators=[
        EmailValidator(lambda: email),
        PasswordValidator(lambda: password, lambda: password_confirmation),
        PhoneValidator(lambda: phone),
        UniqueEmailValidator(lambda: email)
    ])

    errors, valid = validator.validate()
    if not valid:
        for e in errors:
            flash(e.message)
        return redirect(url_for('user.sign_up'))

    pu = PasswordUtil()
    user = User()
    user.email = email
    user.phone = phone
    user.salt = pu.generate_salt()
    user.password = pu.hash_password(password, user.salt)
    user.is_admin = False

    db.session.add(user)
    db.session.commit()

    flash('Możesz się teraz zalogować')
    return redirect(url_for('user.sign_in'))
Пример #2
0
def create():
    if is_rest_call(request):
        username = request.json.get('username')
        password = request.json.get('password')
        password_confirmation = password
        pu = PasswordUtil()
        user = User()
        user.name = username
        user.salt = pu.generate_salt()
        user.password = pu.hash_password(password, user.salt)

        db.session.add(user)
        db.session.commit()

        return jsonify({'status': 'success'}), 200

    username = request.form['username']
    password = request.form['password']
    password_confirmation = request.form['password_confirmation']

    print(username)
    print(password)
    print(password_confirmation)

    validator = CombinedValidator(validators=[
        PasswordValidator(lambda: password, lambda: password_confirmation),
        UniqueUsernameValidator(lambda: username)
    ])

    errors, valid = validator.validate()
    if not valid:
        for e in errors:
            flash(e.message)
        return redirect(url_for('user.sign_up'))

    pu = PasswordUtil()
    user = User()
    user.name = username
    user.salt = pu.generate_salt()
    user.password = pu.hash_password(password, user.salt)

    db.session.add(user)
    db.session.commit()

    flash('Możesz się teraz zalogować')
    return redirect(url_for('user.sign_in'))
Пример #3
0
def set_password(id):
    password = request.form["password"]
    password_confirmation = request.form["password_confirmation"]

    pv = PasswordValidator(lambda: password, lambda: password_confirmation)
    errors, valid = pv.validate()
    if not valid:
        for e in errors:
            flash(e.message)
        return redirect(url_for('user.get', id=id))

    user = User.query.get(id)
    if user is None:
        abort(404)

    pu = PasswordUtil()
    salt = pu.generate_salt()
    sha = pu.hash_password(password, salt)
    user.salt = salt
    user.password = sha
    db.session.commit()
    flash('Zmieniono')
    return redirect(url_for('user.get', id=id))
Пример #4
0
AMOUNT_OF_USERS = 50
AMOUNT_OF_MESSAGES = 180
AMOUNT_OF_OFFERS = 100

pu = PasswordUtil()

app.db.session.commit()
app.db.drop_all()
app.db.create_all()

for _ in range(AMOUNT_OF_USERS):
    user = User()
    user.email = fake.email()
    user.is_admin = False
    user.salt = pu.generate_salt()
    user.password = pu.hash_password(fake.password(), user.salt)
    user.phone = '123654789'

    app.db.session.add(user)
    print('.', end='')

app.db.session.commit()

admin = User()
admin.email = '*****@*****.**'
admin.is_admin = True
admin.salt = pu.generate_salt()
admin.password = pu.hash_password('admin', admin.salt)
admin.phone = '123654789'

app.db.session.add(admin)
Пример #5
0
fake = Factory.create('pl_PL')

AMOUNT_OF_USERS = 500
AMOUNT_OF_MEASUREMENTS = 45

pu = PasswordUtil()

app.db.session.commit()
app.db.drop_all()
app.db.create_all()

admin = User()
admin.name = 'jaro'
admin.salt = pu.generate_salt()
admin.password = pu.hash_password('jaro', admin.salt)

app.db.session.add(admin)
app.db.session.commit()

for _ in range(AMOUNT_OF_MEASUREMENTS):
    m = Measurement()
    m.systolic = random.randint(100, 120)
    m.diastolic = random.randint(80, 90)
    m.pulse = random.randint(60, 80)
    m.date = datetime.datetime(2017, 1 % 2 + 1, _ % 30 + 1, _ * 3 % 24,
                               _ * 7 % 60)
    m.user_id = admin.id

    app.db.session.add(m)
    print('.', end='')
Пример #6
0
def sign_in_user(login, password):
    user = User.query.filter_by(email=login).first()
    if user is None: return False
    pu = PasswordUtil()
    hashed_password = pu.hash_password(password, user.salt)
    return hashed_password == user.password