app_cfg.py 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # -*- coding: utf-8 -*-
  2. """
  3. Global configuration file for TG2-specific settings in tracim.
  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. from tgext.pluggable import plug, replace_template
  13. import tracim
  14. from tracim import model
  15. from tracim.lib import app_globals, helpers
  16. base_config = AppConfig()
  17. base_config.renderers = []
  18. base_config.use_toscawidgets = False
  19. base_config.use_toscawidgets2 = True
  20. base_config.package = tracim
  21. #Enable json in expose
  22. base_config.renderers.append('json')
  23. #Enable genshi in expose to have a lingua franca for extensions and pluggable apps
  24. #you can remove this if you don't plan to use it.
  25. base_config.renderers.append('genshi')
  26. #Set the default renderer
  27. base_config.default_renderer = 'mako'
  28. base_config.renderers.append('mako')
  29. #Configure the base SQLALchemy Setup
  30. base_config.use_sqlalchemy = True
  31. base_config.model = tracim.model
  32. base_config.DBSession = tracim.model.DBSession
  33. # base_config.flash.cookie_name
  34. # base_config.flash.default_status -> Default message status if not specified (ok by default)
  35. base_config['flash.template'] = '''
  36. <div class="alert alert-${status}" style="margin-top: 1em;">
  37. <button type="button" class="close" data-dismiss="alert">&times;</button>
  38. <div id="${container_id}">
  39. <img src="/assets/icons/32x32/status/flash-${status}.png"/>
  40. ${message}
  41. </div>
  42. </div>
  43. '''
  44. # -> string.Template instance used as the flash template when rendered from server side, will receive $container_id, $message and $status variables.
  45. # flash.js_call -> javascript code which will be run when displaying the flash from javascript. Default is webflash.render(), you can use webflash.payload() to retrieve the message and show it with your favourite library.
  46. # flash.js_template -> string.Template instance used to replace full javascript support for flash messages. When rendering flash message for javascript usage the following code will be used instead of providing the standard webflash object. If you replace js_template you must also ensure cookie parsing and delete it for already displayed messages. The template will receive: $container_id, $cookie_name, $js_call variables.
  47. # Configure the authentication backend
  48. # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
  49. base_config.sa_auth.cookie_secret = "3283411b-1904-4554-b0e1-883863b53080"
  50. base_config.auth_backend = 'sqlalchemy'
  51. # what is the class you want to use to search for users in the database
  52. base_config.sa_auth.user_class = model.User
  53. from tg.configuration.auth import TGAuthMetadata
  54. from sqlalchemy import and_
  55. #This tells to TurboGears how to retrieve the data for your user
  56. class ApplicationAuthMetadata(TGAuthMetadata):
  57. def __init__(self, sa_auth):
  58. self.sa_auth = sa_auth
  59. def authenticate(self, environ, identity):
  60. user = self.sa_auth.dbsession.query(self.sa_auth.user_class).filter(and_(self.sa_auth.user_class.is_active==True, self.sa_auth.user_class.email_address==identity['login'])).first()
  61. if user and user.validate_password(identity['password']):
  62. return identity['login']
  63. def get_user(self, identity, userid):
  64. return self.sa_auth.dbsession.query(self.sa_auth.user_class).filter(and_(self.sa_auth.user_class.is_active==True, self.sa_auth.user_class.email_address==userid)).first()
  65. def get_groups(self, identity, userid):
  66. return [g.group_name for g in identity['user'].groups]
  67. def get_permissions(self, identity, userid):
  68. return [p.permission_name for p in identity['user'].permissions]
  69. base_config.sa_auth.dbsession = model.DBSession
  70. base_config.sa_auth.authmetadata = ApplicationAuthMetadata(base_config.sa_auth)
  71. # You can use a different repoze.who Authenticator if you want to
  72. # change the way users can login
  73. #base_config.sa_auth.authenticators = [('myauth', SomeAuthenticator()]
  74. # You can add more repoze.who metadata providers to fetch
  75. # user metadata.
  76. # Remember to set base_config.sa_auth.authmetadata to None
  77. # to disable authmetadata and use only your own metadata providers
  78. #base_config.sa_auth.mdproviders = [('myprovider', SomeMDProvider()]
  79. # override this if you would like to provide a different who plugin for
  80. # managing login and logout of your application
  81. base_config.sa_auth.form_plugin = None
  82. # You may optionally define a page where you want users to be redirected to
  83. # on login:
  84. base_config.sa_auth.post_login_url = '/post_login'
  85. # You may optionally define a page where you want users to be redirected to
  86. # on logout:
  87. base_config.sa_auth.post_logout_url = '/post_logout'
  88. plug(base_config, 'resetpassword')
  89. replace_template(base_config, 'resetpassword.templates.index', 'tracim.templates.reset_password_index')
  90. replace_template(base_config, 'resetpassword.templates.change_password', 'tracim.templates.reset_password_change_password')