Пример #1
0
    def test_user_activate(self, client, db):
        # Registers a user
        res = client.get(url_for('auth.register'), status=200)
        user = User(email="*****@*****.**", username='******')
        form = fill_register_form(res.forms['register-form'], user)
        res = form.submit().follow()

        # Registered user is not verified
        user = User.find_by_email(user.email)
        assert not user.verified

        # Activate token is created for registered user
        assert user.activate_token

        # An invalid user/token combination does not verify the user
        res = client.get(
            url_for('auth.activate', userid=user.id, activate_token="moop"))
        assert not user.verified

        # A valid user/token combination verifies the user
        res = client.get(
            url_for('auth.activate',
                    userid=user.id,
                    activate_token=user.activate_token))
        assert user.verified
Пример #2
0
def setup_module(cls):
    salt = bcrypt.gensalt()
    hashed_pw = bcrypt.hashpw('password', salt)
    user = User.create(username='******',
                       password=hashed_pw,
                       email='*****@*****.**',
                       salt=salt,
                       admin=True)
    user2 = User.create(username='******',
                        password=hashed_pw,
                        email='*****@*****.**',
                        salt=salt,
                        admin=False)
Пример #3
0
def on_message(client, userdata, msg):

    print(msg.topic+": "+str(msg.payload))

    if(msg.topic.endswith("ctecka/request")):
        s = session()
        code = msg.payload
        user = User.find_by_number(code)
        before, sep, after = msg.topic.rpartition('/')
        #client.publish(before + sep + "potvrzeni", payload=ACCESS_ALLOWED_CODE)
        #print("ACCESS ALLOWED")
        if user and can_access(user):

            client.publish(before + sep + "potvrzeni", payload=ACCESS_ALLOWED_CODE)
            print("ACCESS ALLOWED")
            card = CardEntries(card_number=code, time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
            s.add(card)
            s.commit()
        else:
            client.publish(before + sep + "potvrzeni", payload=ACCESS_DENIED_CODE)
            print("ACCESS DENIED")

        code = DEFAULT_CODE
        s.remove();
    elif (msg.topic.endswith("ctecka/log")):
        print msg.payload
Пример #4
0
def setup_module(cls):
    salt = bcrypt.gensalt()
    hashed_pw = bcrypt.hashpw('password', salt)
    user = User.create(username='******',
                       password=hashed_pw,
                       email='*****@*****.**',
                       salt=salt)
Пример #5
0
    def setUp(self):
        self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
        app.testing = True
        self.app = app.test_client()
        with app.app_context():
            init_db()

        self.user = User('test', 'password')
        db_session.add(self.user)
        db_session.commit()
Пример #6
0
    def test_register(self, client, db):
        # Go to register page
        res = client.get(url_for('auth.register'), status=200)

        # Register form successfully submits and redirects
        user = User(email="*****@*****.**", username='******')
        form = fill_register_form(res.forms['register-form'], user)
        res = form.submit().follow()

        # Register-form is no longer displayed
        assert not res.forms.get('register-form')

        # Registered user persists in the database
        assert User.find_by_email(user.email)

        # Cannot register same user twice. Register-form should still be displayed
        res = client.get(url_for('auth.register'), status=200)
        res = fill_register_form(res.forms['register-form'], user).submit()
        assert res.forms['register-form']
Пример #7
0
    def test_register(self, client, db):
        # Go to register page
        res = client.get(url_for('auth.register'), status=200)

        # Register form successfully submits and redirects
        user = User(email="*****@*****.**", username='******')
        form = fill_register_form(res.forms['register-form'], user)
        res = form.submit().follow()

        # Register-form is no longer displayed
        assert not res.forms.get('register-form')

        # Registered user persists in the database
        assert User.find_by_email(user.email)

        # Cannot register same user twice. Register-form should still be displayed
        res = client.get(url_for('auth.register'), status=200)
        res = fill_register_form(res.forms['register-form'], user).submit()
        assert res.forms['register-form']
Пример #8
0
    def test_user_activate(self, client, db):
        # Registers a user
        res = client.get(url_for('auth.register'), status=200)
        user = User(email="*****@*****.**", username='******')
        form = fill_register_form(res.forms['register-form'], user)
        res = form.submit().follow()

        # Registered user is not verified
        user = User.find_by_email(user.email)
        assert not user.verified

        # Activate token is created for registered user
        assert user.activate_token

        # An invalid user/token combination does not verify the user
        res = client.get(url_for('auth.activate', userid=user.id, activate_token="moop"))
        assert not user.verified

        # A valid user/token combination verifies the user
        res = client.get(url_for('auth.activate', userid=user.id, activate_token=user.activate_token))
        assert user.verified
Пример #9
0
def on_message(client, userdata, msg):
    print(msg.topic+": "+str(msg.payload))
    if(msg.topic.endswith("ctecka/request")):
        code = msg.payload
        # user = User.find_by_number(code)
        user_chip = User.find_by_chip(code)
        before, sep, after = msg.topic.rpartition('/')
        if (user_chip) and (can_access(user_chip, msg.topic, code)):

            client.publish(before + sep + "potvrzeni", payload=ACCESS_ALLOWED_CODE)
            print("ACCESS ALLOWED")
        else:
            print user_chip
            if user_chip is None:
                timecardId = Timecard.getIdAndName()
                for i in range(len(timecardId)):
                    if find(msg.topic, timecardId[i][1]):
                        card = Card(card_number="", chip_number=code, time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), id_card_reader=timecardId[i][0], id_user="******", access=False)
                        db.session.add(card)
                        db.session.commit()
            client.publish(before + sep + "potvrzeni", payload=ACCESS_DENIED_CODE)
            print("ACCESS DENIED")

        code = DEFAULT_CODE
Пример #10
0
 def test_password_verification(self):
     u = User(password='******')
     assert u.verify_password('cat') is True
     assert u.verify_password('dog') is False
 def test_password_verification(self):
     u = User(password='******')
     assert u.verify_password('cat') is True
     assert u.verify_password('dog') is False
 def test_password_salts_are_random(self):
     u = User(password='******')
     u2 = User(password='******')
     assert u.password_hash != u2.password_hash
 def test_find_by_email(self, db):
     email = "*****@*****.**"
     u1 = generate_user(email=email)
     u1.save()
     assert User.find_by_email(email) == u1
 def test_no_password_getter(self):
     "Password should not be directly accessible"
     u = User(password='******')
     with pytest.raises(AttributeError):
         u.password  # pylint: disable=W0104
Пример #15
0
 def test_find_by_email(self, db):
     email = "*****@*****.**"
     u1 = generate_user(email=email)
     u1.save()
     assert User.find_by_email(email) == u1
Пример #16
0
def setup_module(cls):
    salt = bcrypt.gensalt()
    hashed_pw = bcrypt.hashpw('password', salt)
    user = User.create(username='******', password=hashed_pw, email='*****@*****.**', salt=salt, admin = True)
    user2 = User.create(username='******', password=hashed_pw, email='*****@*****.**', salt=salt, admin = False)
 def test_password_setter(self):
     "Setting password generates a password hash"
     u = User(password='******')
     assert u.password_hash is not None
 def test_find_by_username(self, db):
     username = "******"
     u1 = generate_user(username=username)
     u1.save()
     assert User.find_by_username(username) == u1
Пример #19
0
 def test_find_by_username(self, db):
     username = "******"
     u1 = generate_user(username=username)
     u1.save()
     assert User.find_by_username(username) == u1
Пример #20
0
def setup_module(cls):
    salt = bcrypt.gensalt()
    hashed_pw = bcrypt.hashpw('password', salt)
    user = User.create(username='******', password=hashed_pw, email='*****@*****.**', salt=salt)