2025-01-24 16:34:02 +01:00
|
|
|
# API Documentation
|
|
|
|
|
|
|
|
Currently only some details about the internal API are available.
|
|
|
|
|
|
|
|
## How to create a user
|
|
|
|
```python
|
|
|
|
# Save user to the table named 'user'
|
|
|
|
# Password gets sha256 encrypted with default a salt string
|
|
|
|
# of the snek.system.security module.
|
|
|
|
|
|
|
|
new_user_object = await app.service.user.register(
|
2025-01-24 23:35:44 +01:00
|
|
|
username="retoor", password="retoorded"
|
2025-01-24 16:34:02 +01:00
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Encrypt string
|
|
|
|
```python
|
|
|
|
from snek.system import security
|
|
|
|
|
|
|
|
# Support for both utf and bytes.
|
|
|
|
var1 = security.encrypt("data")
|
|
|
|
var2 = security.encrypt(b"data")
|
|
|
|
|
|
|
|
# Is correct:
|
2025-01-24 23:35:44 +01:00
|
|
|
assert var1 == var2
|
2025-01-24 16:34:02 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## How to create a basic HTML / Markdown view
|
|
|
|
```python
|
2025-01-24 23:35:44 +01:00
|
|
|
from snek.system.view import BaseView
|
|
|
|
|
2025-01-24 16:34:02 +01:00
|
|
|
|
|
|
|
class IndexView(BaseView):
|
2025-01-24 23:35:44 +01:00
|
|
|
|
2025-01-24 16:34:02 +01:00
|
|
|
async def get(self):
|
|
|
|
# The render function supports markdown.
|
|
|
|
# It will render with syntax highlighting.
|
|
|
|
# Just use the .md file extension in the file name.
|
|
|
|
return await self.render("index.html")
|
|
|
|
```
|
|
|
|
## How to create a FormView
|
|
|
|
```python
|
|
|
|
from snek.form.register import RegisterForm
|
2025-01-24 23:35:44 +01:00
|
|
|
from snek.system.view import BaseFormView
|
|
|
|
|
2025-01-24 16:34:02 +01:00
|
|
|
|
|
|
|
class RegisterFormView(BaseFormView):
|
2025-01-24 23:35:44 +01:00
|
|
|
|
2025-01-24 16:34:02 +01:00
|
|
|
form = RegisterForm
|
|
|
|
```
|
|
|
|
## How to register a class view
|
|
|
|
```python
|
|
|
|
app.routes.add_view("/your-page.html", YourViewClass)
|
|
|
|
```
|