From b1f3fb707bc5b22bd579bde10c1322b524a4db16 Mon Sep 17 00:00:00 2001 From: Kerwin Date: Tue, 12 Feb 2019 00:04:11 +0800 Subject: [PATCH 1/2] fix template directory doesn't copy into `lib` add added "if __name__ == "__main__":" --- setup.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a09efb4..cf46400 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,9 @@ +import os from setuptools import setup, find_packages -setup( +pjoin = os.path.join + +setup_args = dict( name='jupyterhub-nativeauthenticator', version='0.0.1', description='JupyterHub Native Authenticator', @@ -11,7 +14,17 @@ packages=find_packages(), install_requires=['jupyterhub>=0.8', 'bcrypt'], package_data={ - 'templates': ['*.html'], - 'common-credentials': ['common-credentials.txt'], + 'nativeauthenticator': [ + pjoin('templates', '*.html'), + 'common-credentials.txt' + ], } ) + + +def main(): + setup(**setup_args) + + +if __name__ == '__main__': + main() From 893e1d3afb30244a9beeafcb6ce53cf0f7ac1127 Mon Sep 17 00:00:00 2001 From: 00Kai0 Date: Tue, 12 Feb 2019 15:11:41 +0800 Subject: [PATCH 2/2] fix errors orm 1. allow empty email 2. fix password typeerror 3. add length on dialect to support mysql --- nativeauthenticator/orm.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nativeauthenticator/orm.py b/nativeauthenticator/orm.py index 740e235..589c33e 100644 --- a/nativeauthenticator/orm.py +++ b/nativeauthenticator/orm.py @@ -9,10 +9,10 @@ class UserInfo(Base): __tablename__ = 'users_info' id = Column(Integer, primary_key=True, autoincrement=True) - username = Column(String, nullable=False) - password = Column(String, nullable=False) + username = Column(String(128), nullable=False) + password = Column(String(128), nullable=False) is_authorized = Column(Boolean, default=False) - email = Column(String) + email = Column(String(128)) @classmethod def find(cls, db, username): @@ -23,8 +23,9 @@ def find(cls, db, username): def is_valid_password(self, password): """Checks if a password passed matches the password stored""" - encoded_pw = bcrypt.hashpw(password.encode(), self.password) - return encoded_pw == self.password + check_pwd = self.password.encode() if type(self.password) != bytes else self.password + encoded_pw = bcrypt.hashpw(password.encode(), check_pwd) + return encoded_pw == check_pwd @classmethod def change_authorization(cls, db, username): @@ -35,6 +36,8 @@ def change_authorization(cls, db, username): @validates('email') def validate_email(self, key, address): + if not address: + return assert re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", address) return address