auth.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 1 Auth
  2. ------
  3. 1.1 Custom model
  4. ~~~~~~~~~~~~~~~~
  5. You custom model if you need more when register or confirm email
  6. 1.1.1 register_models
  7. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  8. .. code-block:: python
  9. from flask_maple import Auth
  10. class MyAuth(Auth):
  11. def register_models(self, form):
  12. user = self.User()
  13. user.username = form.username.data
  14. user.password = user.set_password(form.password.data)
  15. user.email = form.email.data
  16. self.db.session.add(user)
  17. self.db.session.commit()
  18. return user
  19. 1.1.2 confirm_models
  20. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  21. .. code-block:: python
  22. class MyAuth(Auth):
  23. def confirm_models(self, user):
  24. user.is_confirmed = True
  25. user.confirmed_time = datetime.now()
  26. self.db.session.commit()
  27. 1.1.3 email_models
  28. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  29. .. code-block:: python
  30. class MyAuth(Auth):
  31. def email_models(self):
  32. current_user.send_email_time = datetime.now()
  33. self.db.session.commit()
  34. 1.2 Custom form
  35. ~~~~~~~~~~~~~~~
  36. You can add custom form when register Auth
  37. .. code-block:: python
  38. Auth(app, db=db, mail=mail, user_model=User,
  39. login_form=loginform,
  40. register_form=registerform,
  41. forget_form=forgetpasswordform)
  42. **template**
  43. .. code-block:: python
  44. templates/auth/login.html
  45. templates/auth/register.html
  46. templates/auth/forget.html