Example #1
0
    def test_user_password(self, testapp):
        """ Test password hashing and checking """

        admin = User('admin', 'supersafepassword')

        assert admin.username == 'admin'
        assert admin.check_password('supersafepassword')
Example #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('hangman_home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Example #3
0
def createdb():
    """ Creates a database with all of the tables defined in
        your SQLAlchemy models
    """
    db.create_all()
    db.session.add(User('admin', 'hangman'))
    db.session.commit()
    conn = db.session.connection().connection
    cur = conn.cursor()
    df1 = pd.read_csv('dictionary.csv')
    word_list = df1['Word'].tolist()
    final_words = list()
    for index in range(len(word_list)):
        if pd.isnull(word_list[index]):
            continue
        if len(word_list[index]) == 5 or len(word_list[index]) == 6:
            final_words.append(word_list[index])
    del word_list
    df = pd.DataFrame(final_words)
    df.to_csv('dictionary1.csv', index=False)

    dictionary_sql = """
                   COPY dictionary FROM stdin WITH CSV HEADER
                   DELIMITER as ','
                   """
    with open('dictionary1.csv', 'r') as f:
        cur.copy_expert(sql=dictionary_sql, file=f)
        conn.commit()
        cur.close()
    db.session.commit()
Example #4
0
    def test_user_save(self, testapp):
        """ Test Saving the user model to the database """

        admin = User('admin', 'supersafepassword')
        db.session.add(admin)
        db.session.commit()

        user = User.query.filter_by(username="******").first()
        assert user is not None
Example #5
0
def rank(request):
    user = request.POST.get('id', "default")
    result = request.POST.get('result', "lose")
    p1 = Player.objects.filter(name='Player1')
    p2 = Player.objects.filter(name='Player2')
    p3 = Player.objects.filter(name='Player3')
    p4 = Player.objects.filter(name='Player4')
    plist = [p1, p2, p3, p4]
    if p1[0].done and p2[0].done and p3[0].done and p4[0].done:
        Counting.objects.filter(name='Init').update(count=1)
        for p in plist:
            p.update(init=1, lives=8, done=0, win=0, lose=0)
    if result == "win":
        if User.objects.filter(name=user):
            User.objects.filter(name=user).update(score=F('score') + 100)
        else:
            rank = User(name=user, score=100)
            rank.save()
    ranker = User.objects.all().order_by('-score')[:5]
    context = {'ranker': ranker}
    return render(request, 'rank.html', context)
Example #6
0
    def validate(self):
        check_validate = super(LogonForm, self).validate()

        # if our validators do not pass
        if not check_validate:
            return False

        # Does our the exist
        user = User.query.filter_by(username=self.username.data).first()
        if user:
            self.username.errors.append('Username already Present')
            return False

        db.session.add(User(self.username.data, self.password.data))
        db.session.commit()
        return True
Example #7
0
def testapp(request):
    app = create_app('hangman.settings.TestConfig')
    client = app.test_client()

    db.app = app
    db.create_all()

    if getattr(request.module, "create_user", True):
        admin = User('admin', 'supersafepassword')
        db.session.add(admin)
        db.session.commit()

    def teardown():
        db.session.remove()
        db.drop_all()

    request.addfinalizer(teardown)

    return client