You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. :author: Grey Li ()
  4. :url: http://greyli.com
  5. :copyright: © 2018 Grey Li <withlihui@gmail.com>
  6. :license: MIT, see LICENSE for more details.
  7. """
  8. from flask_avatars import Avatars
  9. from flask_bootstrap import Bootstrap
  10. from flask_dropzone import Dropzone
  11. from flask_login import LoginManager, AnonymousUserMixin
  12. from flask_mail import Mail
  13. from flask_moment import Moment
  14. from flask_sqlalchemy import SQLAlchemy
  15. from flask_whooshee import Whooshee
  16. from flask_wtf import CSRFProtect
  17. bootstrap = Bootstrap()
  18. db = SQLAlchemy()
  19. login_manager = LoginManager()
  20. mail = Mail()
  21. dropzone = Dropzone()
  22. moment = Moment()
  23. whooshee = Whooshee()
  24. avatars = Avatars()
  25. csrf = CSRFProtect()
  26. @login_manager.user_loader
  27. def load_user(user_id):
  28. from albumy.models import User
  29. user = User.query.get(int(user_id))
  30. return user
  31. login_manager.login_view = 'auth.login'
  32. # login_manager.login_message = 'Your custom message'
  33. login_manager.login_message_category = 'warning'
  34. login_manager.refresh_view = 'auth.re_authenticate'
  35. # login_manager.needs_refresh_message = 'Your custom message'
  36. login_manager.needs_refresh_message_category = 'warning'
  37. class Guest(AnonymousUserMixin):
  38. def can(self, permission_name):
  39. return False
  40. @property
  41. def is_admin(self):
  42. return False
  43. login_manager.anonymous_user = Guest