Package: ppss-auth
This package aims to give and easy pluggable module to provide authentication and user maintennance in a Pyramid web application.
It relies the Pyramid+SQLAlchemy+Mako stack. Implementation for other template languages is on the roadmap.Installation and setupInstall the packageInstall the package with:pipinstallppss_author put ppss_auth in your app dependencies (setup.py, in the install_requires list of packages)To activate the package, in your main__init__.pyfile, inside the main function, add this line:config.include('ppss_auth')in your models include the ppss_auth's models with this line:fromppss_auth.modelsimport*Configure the databaseThis can be a zero-db-conf module:
run the app withppss_auth.initdbset to True (that is the default for the params, so you can even leave it blank: see configuration, below). You are done with this, unless you need more in-depth initialization (follow reading)You want to do it yourselfTo init the Tables manually, in the initialization script (usually inscripts/intializedb.py), add this row:fromppss_authimport(modelsasppssmodels)and while creating the default data (in the "with transaction.manager" block of code), use something like:ppssmodels.initdb(dbsession,createdefault=False)This creates the tables and, ifcreatedefaultevaulates to True, it create a default admin/admin user with the admin permission.
Please change the password to avoid secuirity issues.You can create some data as well. Refer to [models] section, below, for more info.RequirementsWhen a user login,essionauthpolicyis used to store her informations (userid and user groups).ini file configurationppss_auth use these info from the ini file:default userppss_auth.adminname - the name of a sueruser. Deafult to "admin"ppss_auth.adminpass - the corresponding password. If not provided the admin is not allowed to log in (with the ini credentials. It may exist in database)predefined permissions, groups, usersppss_auth.permission_list - list of permission, one on each indented rowppss_auth.group_listppss_auth.user_listppss_auth.default_passwordAn example is as follow:ppss_auth.permission_list=permision1permision2permision3ppss_auth.group_list=group1=permision1,permision2group2=permision1group3=permision2ppss_auth.user_list=user1=group1,group2iser2=group3ppss_auth.default_password=temp0r4ryPassword->changeme!db stuffppss_auth.initdb [True] - true/false value, tells the lib to init db automatically on first run.routesppss_auth.login_url [/login] - url for login.ppss_auth.logout_url [/logout]- url for logout.where to land after succesfull login/logoutppss_auth.post_login_follow - try to redirect the browser back to where it came from after successful login (use true case insensitive to activate it). It's useful if combined with the forbidden patternppss_auth.post_login_route [home] - name of the route where to send the browser after user logged in. Ignored if ppss_auth.post_login_follow is set to true AND there is a referer to go to.ppss_auth.post_logout_route - name of the route where to send the browser after log out. Defaults to hometemplates stuffYou can override all this values and even provide a mako-free environment. This can be a litlle tricky, but there is no hard-coded dependency to mako, just the defaults.ppss_auth.logintemplate - name of the login template. It defaults to the internal template: "ppss_auth:/templates/login.mako"ppss_auth.changepasswordtemplate - name of the change password template. Defaults to: ppss_auth:/templates/change.makoppss_auth.modifyusertemplate - Defaults to: ppss_auth:/templates/modifyuser.makoppss_auth.listusertemplate - Defaults to: ppss_auth:/templates/listuser.makoppss_auth.logintemplateinherit - Defaults to: ppss_auth:/templates/layout.makolook and feelppss_auth.bootstrapversion - Should 3 or 4, accordind to the the version of bootstrap that the hosting site uses. Defaults to 4Things to know (devs only)databaseThi package provide the creation and usage of 3 main tables (and the other tables required for ER consistency):ppss_user - containing basic information about the users (username, hashed password and related data )ppss_group - user groups to allow for easier handling of user groups and permissionsppss_permission - a list of permissions (just an id and a name)modelsPPSsuserThis represents the user of your application.
She has ausername, apasswordand relation to hergroups. She also has aenabledproperty and some timestamps (creation times, and similar times).Use thesetPassword(password)method on PPSsuser instances to change the password, providing the new password.todict(self)is a commodity method to get a dict of the main properties.PPSsgroupThis class represnts the groups of your users. It's a many-to-many relation: each user can belong to many groups, and each group can gather many users.
Other than anameand theenabledflag (integer with 1 for enabled), its main user is the many-to-many relation to permissions. This means that all users in the same group share (at least) all the permissions given to the group.PPSspermissionThis class represents the permissions of the application. You can create new permissions and link them to group. You can use those permissions in thepermissionattribute of theview_configdecorator to restrict usage of some methods using ACL, or you can check it whenever needed.Integrating with existing alembicenp.py file
add the following row among the imports:fromppss_auth.ppss_auth_utils.dbimportexclude_ppss_auth_tablesand use itrun_migrations_offlinefunction substituting context with:context.configure(url=settings['sqlalchemy.url'],**exclude_ppss_auth_tables(config))and inrun_migrations_onlinesubstituting context with:context.configure(connection=connection,target_metadata=target_metadata,**exclude_ppss_auth_tables(config))add the following to your .ini file, belowalembicsection:[alembic:exclude]tables=module_db_versionpattern=ppss**auth*This package aims to give and easy pluggable module to provide authentication and user maintennance in a Pyramid web application.
It relies the Pyramid+SQLAlchemy+Mako stack. Implementation for other template languages is on the roadmap.Installation and setupInstall the packageInstall the package with:pipinstallppss_author put ppss_auth in your app dependencies (setup.py, in the install_requires list of packages)To activate the package, in your main__init__.pyfile, inside the main function, add this line:config.include('ppss_auth')in your models include the ppss_auth's models with this line:fromppss_auth.modelsimport*Configure the databaseThis can be a zero-db-conf module:
run the app withppss_auth.initdbset to True (that is the default for the params, so you can even leave it blank: see configuration, below). You are done with this, unless you need more in-depth initialization (follow reading)You want to do it yourselfTo init the Tables manually, in the initialization script (usually inscripts/intializedb.py), add this row:fromppss_authimport(modelsasppssmodels)and while creating the default data (in the "with transaction.manager" block of code), use something like:ppssmodels.initdb(dbsession,createdefault=False)This creates the tables and, ifcreatedefaultevaulates to True, it create a default admin/admin user with the admin permission.
Please change the password to avoid secuirity issues.You can create some data as well. Refer to [models] section, below, for more info.RequirementsWhen a user login,essionauthpolicyis used to store her informations (userid and user groups).ini file configurationppss_auth use these info from the ini file:default userppss_auth.adminname - the name of a sueruser. Deafult to "admin"ppss_auth.adminpass - the corresponding password. If not provided the admin is not allowed to log in (with the ini credentials. It may exist in database)predefined permissions, groups, usersppss_auth.permission_list - list of permission, one on each indented rowppss_auth.group_listppss_auth.user_listppss_auth.default_passwordAn example is as follow:ppss_auth.permission_list=permision1permision2permision3ppss_auth.group_list=group1=permision1,permision2group2=permision1group3=permision2ppss_auth.user_list=user1=group1,group2iser2=group3ppss_auth.default_password=temp0r4ryPassword->changeme!db stuffppss_auth.initdb [True] - true/false value, tells the lib to init db automatically on first run.routesppss_auth.login_url [/login] - url for login.ppss_auth.logout_url [/logout]- url for logout.where to land after succesfull login/logoutppss_auth.post_login_follow - try to redirect the browser back to where it came from after successful login (use true case insensitive to activate it). It's useful if combined with the forbidden patternppss_auth.post_login_route [home] - name of the route where to send the browser after user logged in. Ignored if ppss_auth.post_login_follow is set to true AND there is a referer to go to.ppss_auth.post_logout_route - name of the route where to send the browser after log out. Defaults to hometemplates stuffYou can override all this values and even provide a mako-free environment. This can be a litlle tricky, but there is no hard-coded dependency to mako, just the defaults.ppss_auth.logintemplate - name of the login template. It defaults to the internal template: "ppss_auth:/templates/login.mako"ppss_auth.changepasswordtemplate - name of the change password template. Defaults to: ppss_auth:/templates/change.makoppss_auth.modifyusertemplate - Defaults to: ppss_auth:/templates/modifyuser.makoppss_auth.listusertemplate - Defaults to: ppss_auth:/templates/listuser.makoppss_auth.logintemplateinherit - Defaults to: ppss_auth:/templates/layout.makolook and feelppss_auth.bootstrapversion - Should 3 or 4, accordind to the the version of bootstrap that the hosting site uses. Defaults to 4Things to know (devs only)databaseThi package provide the creation and usage of 3 main tables (and the other tables required for ER consistency):ppss_user - containing basic information about the users (username, hashed password and related data )ppss_group - user groups to allow for easier handling of user groups and permissionsppss_permission - a list of permissions (just an id and a name)modelsPPSsuserThis represents the user of your application.
She has ausername, apasswordand relation to hergroups. She also has aenabledproperty and some timestamps (creation times, and similar times).Use thesetPassword(password)method on PPSsuser instances to change the password, providing the new password.todict(self)is a commodity method to get a dict of the main properties.PPSsgroupThis class represnts the groups of your users. It's a many-to-many relation: each user can belong to many groups, and each group can gather many users.
Other than anameand theenabledflag (integer with 1 for enabled), its main user is the many-to-many relation to permissions. This means that all users in the same group share (at least) all the permissions given to the group.PPSspermissionThis class represents the permissions of the application. You can create new permissions and link them to group. You can use those permissions in thepermissionattribute of theview_configdecorator to restrict usage of some methods using ACL, or you can check it whenever needed.Integrating with existing alembicenp.py file
add the following row among the imports:fromppss_auth.ppss_auth_utils.dbimportexclude_ppss_auth_tablesand use itrun_migrations_offlinefunction substituting context with:context.configure(url=settings['sqlalchemy.url'],**exclude_ppss_auth_tables(config))and inrun_migrations_onlinesubstituting context with:context.configure(connection=connection,target_metadata=target_metadata,**exclude_ppss_auth_tables(config))add the following to your .ini file, belowalembicsection:[alembic:exclude]tables=module_db_versionpattern=ppss**auth*