-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs + Add 'toui' command + Fixes
- Loading branch information
1 parent
fd83f2f
commit cda9c95
Showing
46 changed files
with
602 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
docs/Examples.advanced_example_3_toui_with_google_sign_in.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
ToUI with Google sign in | ||
======================== | ||
|
||
ToUI can be used with Google sign in. This example shows how to use Google sign in with ToUI. | ||
Make sure to create a Google app first. Also, add the following as an authorized redirect URI to your Google app: | ||
`https://<your-domain>/toui-google-sign-in` | ||
|
||
One way to create a Google app is through Google Firebase. Perhaps check it out. | ||
|
||
This example uses the HTML file "test6.html": | ||
|
||
.. code-block:: html | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<button id="sign-in"><img width="200px" src="./google_button.png"></img></button> | ||
<p id="user-info"></p> | ||
</body> | ||
</html> | ||
|
||
Python code: | ||
|
||
.. code-block:: python | ||
import os | ||
from toui import Website, Page | ||
# Create app | ||
app = Website(__name__, assets_folder="assets", secret_key="some secret key") | ||
app.add_user_database_using_sql(f"sqlite:///{os.getcwd()}/.user_database.db") | ||
# Create pages | ||
pg = Page(html_file="assets/test6.html", url="/") | ||
# Create functions that will be called from HTML | ||
def get_user_info(): | ||
pg = app.get_user_page() | ||
if app.get_current_user(): | ||
pg.get_element("user-info").set_content(f"User: {app.get_current_user().username}") | ||
def sign_in(): | ||
"""Sign in using Google.""" | ||
app.sign_in_using_google(client_id=os.environ['GOOGLE_CLIENT_ID'], | ||
client_secret=os.environ['GOOGLE_CLIENT_SECRET'], | ||
after_auth_url="/") | ||
# Connect functions to elements | ||
pg.get_body_element().on("load", get_user_info) | ||
pg.get_element("sign-in").onclick(sign_in) | ||
# Add pages to app | ||
app.add_pages(pg) | ||
if __name__ == '__main__': | ||
app.run() | ||
107 changes: 107 additions & 0 deletions
107
docs/Examples.advanced_example_4_toui_with_firebase.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
ToUI with Firebase | ||
================== | ||
|
||
ToUI can be used with Firebase. Create a Firebase app to use this example. In this example, ToUI is used with Firebase for: | ||
|
||
- User authentication | ||
- Stroing user data in database | ||
- File storage | ||
- File retrieval | ||
|
||
|
||
This example uses the HTML file "test7.html": | ||
|
||
.. code-block:: html | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<h1>Sign in users:</h1> | ||
<input id="username"/> | ||
<input id="password"/> | ||
<button id="sign-in">Sign in</button> | ||
<button id="sign-up">Sign up</button> | ||
<p id="output"></p> | ||
<h1>Upload files:</h1> | ||
<input type="file" id="file"/> | ||
<button id="get-file">Download uploaded file</button> | ||
<p id="output2"></p> | ||
</body> | ||
</html> | ||
|
||
Python code: | ||
|
||
.. code-block:: python | ||
import sys | ||
sys.path.append("..") | ||
import os | ||
from toui import Website, Page | ||
app = Website(__name__, assets_folder="assets", secret_key="some text") | ||
app.add_firebase(".my_firebase_credentials.json") # You can get this file from your firebase project settings | ||
app.add_user_database_using_firebase() # Connects to firestore database. Make sure that you created one in Firebase. | ||
BUCKET_NAME = "test-14583.appspot.com" # Change this value to match your bucket name in Firebase Storage | ||
main_pg = Page(html_file="assets/test7.html", url="/") | ||
def sign_in(): | ||
pg = app.get_user_page() | ||
username = pg.get_element("username").get_value() | ||
password = pg.get_element("password").get_value() | ||
pg.get_element("output").set_content("loading") | ||
success = app.signin_user(username=username, password=password) | ||
if success: | ||
age = app.get_current_user_data("age") | ||
pg.get_element("output").set_content(f"Signed in successfully. Age of user: {age}") | ||
else: | ||
pg.get_element("output").set_content("Sign in failed") | ||
def sign_up(): | ||
pg = app.get_user_page() | ||
username = pg.get_element("username").get_value() | ||
password = pg.get_element("password").get_value() | ||
pg.get_element("output").set_content("loading") | ||
success = app.signup_user(username=username, password=password) | ||
if success: | ||
app.signin_user(username=username, password=password) | ||
value_added = app.set_current_user_data("age", 20) | ||
pg.get_element("output").set_content(f"Signed up successfully. Age added: {value_added}") | ||
else: | ||
pg.get_element("output").set_content("Sign up failed") | ||
def store_file(): | ||
pg = app.get_user_page() | ||
file = pg.get_element("file").get_files()[0] | ||
with open(".test_file", "w") as f: | ||
file.save(f) | ||
app.store_file_using_firebase(destination_path=f"{app.get_current_user_id()}/test_file", file_path=".test_file", bucket_name=BUCKET_NAME) | ||
pg.get_element("output2").set_content("File stored") | ||
def retrieve_file(): | ||
pg = app.get_user_page() | ||
if os.path.exists(".new_test_file"): | ||
raise Exception(".new_test_file already exists") | ||
app.get_file_from_firebase(source_path=f"{app.get_current_user_id()}/test_file", new_file_path=".new_test_file", bucket_name=BUCKET_NAME) | ||
with open(".new_test_file", "r") as f: | ||
pg.get_element("output2").set_content("Downloaded file content: " + f.read()) | ||
main_pg.get_element("sign-in").onclick(sign_in) | ||
main_pg.get_element("sign-up").onclick(sign_up) | ||
main_pg.get_element("file").on("change", store_file) | ||
main_pg.get_element("get-file").onclick(retrieve_file) | ||
app.add_pages(main_pg) | ||
if __name__ == '__main__': | ||
app.run() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ToUI | ||
==== | ||
|
||
Version: v2.4.3-beta | ||
Version: v3.0.0-beta | ||
|
||
.. include:: ../README.md | ||
:parser: myst_parser.sphinx_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.add_firebase | ||
----------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.add_firebase |
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
docs/toui.apps.DesktopApp.add_user_database_using_firebase.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.add_user_database_using_firebase | ||
------------------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.add_user_database_using_firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.add_user_database_using_sql | ||
-------------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.add_user_database_using_sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.email_exists | ||
----------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.email_exists |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.get_current_user_data | ||
-------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.get_current_user_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.get_current_user_id | ||
------------------------------ | ||
|
||
.. automethod:: toui.apps.DesktopApp.get_current_user_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.get_file_from_firebase | ||
--------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.get_file_from_firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.is_signed_in | ||
----------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.is_signed_in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.set_current_user_data | ||
-------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.set_current_user_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.sign_in_using_google | ||
------------------------------- | ||
|
||
.. automethod:: toui.apps.DesktopApp.sign_in_using_google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DesktopApp.store_file_using_firebase | ||
------------------------------------ | ||
|
||
.. automethod:: toui.apps.DesktopApp.store_file_using_firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.add_firebase | ||
-------------------- | ||
|
||
.. automethod:: toui.apps.Website.add_firebase |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.add_user_database_using_firebase | ||
---------------------------------------- | ||
|
||
.. automethod:: toui.apps.Website.add_user_database_using_firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.add_user_database_using_sql | ||
----------------------------------- | ||
|
||
.. automethod:: toui.apps.Website.add_user_database_using_sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.email_exists | ||
-------------------- | ||
|
||
.. automethod:: toui.apps.Website.email_exists |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.get_current_user_data | ||
----------------------------- | ||
|
||
.. automethod:: toui.apps.Website.get_current_user_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.get_current_user_id | ||
--------------------------- | ||
|
||
.. automethod:: toui.apps.Website.get_current_user_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.get_file_from_firebase | ||
------------------------------ | ||
|
||
.. automethod:: toui.apps.Website.get_file_from_firebase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Website.is_signed_in | ||
-------------------- | ||
|
||
.. automethod:: toui.apps.Website.is_signed_in |
Oops, something went wrong.