app_cfg.py 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. """
  3. Global configuration file for TG2-specific settings in pod.
  4. This file complements development/deployment.ini.
  5. Please note that **all the argument values are strings**. If you want to
  6. convert them into boolean, for example, you should use the
  7. :func:`paste.deploy.converters.asbool` function, as in::
  8. from paste.deploy.converters import asbool
  9. setting = asbool(global_conf.get('the_setting'))
  10. """
  11. from tg.configuration import AppConfig
  12. import pod
  13. from pod import model
  14. from pod.lib import app_globals, helpers
  15. base_config = AppConfig()
  16. base_config.renderers = []
  17. base_config.use_toscawidgets = False
  18. base_config.use_toscawidgets2 = True
  19. base_config.package = pod
  20. #Enable json in expose
  21. base_config.renderers.append('json')
  22. #Enable genshi in expose to have a lingua franca for extensions and pluggable apps
  23. #you can remove this if you don't plan to use it.
  24. base_config.renderers.append('genshi')
  25. #Set the default renderer
  26. base_config.default_renderer = 'mako'
  27. base_config.renderers.append('mako')
  28. #Configure the base SQLALchemy Setup
  29. base_config.use_sqlalchemy = True
  30. base_config.model = pod.model
  31. base_config.DBSession = pod.model.DBSession
  32. # Configure the authentication backend
  33. # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
  34. base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
  35. base_config.auth_backend = 'sqlalchemy'
  36. # what is the class you want to use to search for users in the database
  37. base_config.sa_auth.user_class = model.User
  38. from tg.configuration.auth import TGAuthMetadata
  39. #This tells to TurboGears how to retrieve the data for your user
  40. class ApplicationAuthMetadata(TGAuthMetadata):
  41. def __init__(self, sa_auth):
  42. self.sa_auth = sa_auth
  43. def authenticate(self, environ, identity):
  44. user = self.sa_auth.dbsession.query(self.sa_auth.user_class).filter_by(email_address=identity['login']).first()
  45. if user and user.validate_password(identity['password']):
  46. return identity['login']
  47. def get_user(self, identity, userid):
  48. return self.sa_auth.dbsession.query(self.sa_auth.user_class).filter_by(email_address=userid).first()
  49. def get_groups(self, identity, userid):
  50. return [g.group_name for g in identity['user'].groups]
  51. def get_permissions(self, identity, userid):
  52. return [p.permission_name for p in identity['user'].permissions]
  53. base_config.sa_auth.dbsession = model.DBSession
  54. base_config.sa_auth.authmetadata = ApplicationAuthMetadata(base_config.sa_auth)
  55. # You can use a different repoze.who Authenticator if you want to
  56. # change the way users can login
  57. #base_config.sa_auth.authenticators = [('myauth', SomeAuthenticator()]
  58. # You can add more repoze.who metadata providers to fetch
  59. # user metadata.
  60. # Remember to set base_config.sa_auth.authmetadata to None
  61. # to disable authmetadata and use only your own metadata providers
  62. #base_config.sa_auth.mdproviders = [('myprovider', SomeMDProvider()]
  63. # override this if you would like to provide a different who plugin for
  64. # managing login and logout of your application
  65. base_config.sa_auth.form_plugin = None
  66. # You may optionally define a page where you want users to be redirected to
  67. # on login:
  68. base_config.sa_auth.post_login_url = '/post_login'
  69. # You may optionally define a page where you want users to be redirected to
  70. # on logout:
  71. base_config.sa_auth.post_logout_url = '/post_logout'