Skip to content

Commit

Permalink
Fix google sign in + Add full template
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarakalmehairbi committed Aug 7, 2023
1 parent 8f274b3 commit c29cbde
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 27 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
![Docs](https://img.shields.io/readthedocs/toui)

# Overview
ToUI is a Python framework for creating user interfaces (web apps and desktop apps)
from HTML code easily. It allows you to call your Python functions from HTML. No JavaScript knowledge is required, but some knowledge of HTML
is usually required.
ToUI is a Python framework for creating user interfaces (web apps and desktop apps) from HTML code easily. It allows you to call your Python functions from HTML. No JavaScript knowledge is required, but some knowledge of HTML is usually required.

# Why ToUI
- Converts HTML and CSS files into a fast-responsive app using Python alone.
Expand All @@ -23,6 +21,22 @@ is usually required.
- **Firebase (experimental)**
- **Password protection for your app**

# Preview

### Calling a Python function from HTML code

![gif](https://github.com/mubarakalmehairbi/ToUI/blob/main/images/home.gif?raw=True)

### Simple calculator

![gif](https://github.com/mubarakalmehairbi/ToUI/blob/main/images/calculator.gif?raw=True)

Follow the link below to preview a live app created using ToUI:

https://toui-92bd1594dbed.herokuapp.com/

To download this template and customize to create your own web app, go to this [section](#start-with-a-template).

# How to install
Run this command:
```shell
Expand Down Expand Up @@ -87,7 +101,13 @@ To start with a basic template for a ToUI project. Run the command:
```
toui init
```
Alternatively, use this [template](https://github.com/mubarakalmehairbi/BasicToUIProject).
You can find the same template [here](https://github.com/mubarakalmehairbi/BasicToUIProject).

To start with a full template that includes a **Home** page, an **About** page, **Contact** page, a simple **Calculator** page, a **Sign-in** page (including **Google sign-in**), a simple **Dashboard**, and more, run the following command:
```
toui init --full
```
You can also find the full template [here](https://github.com/mubarakalmehairbi/FullToUIProject).

# Make the app responsive
Check this [example](https://toui.readthedocs.io/en/latest/Examples.example_1_simple_website.html)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ToUI
====

Version: v3.3.0-beta
Version: v3.4.0

.. include:: ../README.md
:parser: myst_parser.sphinx_
Expand Down
Binary file added images/calculator.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/home.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion toui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .structure import ToUIBlueprint
from . import exceptions

__version__ = "v3.3.0-beta"
__version__ = "v3.4.0"
31 changes: 15 additions & 16 deletions toui/_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
ToUI Command Line Interface
===========================
Usage:
toui init
Creates a basic ToUI project template in the current directory.
toui init [--full]
Creates a basic ToUI project template in the current directory. If --full is
specified, a full ToUI project template with many features will be created.
toui --minimal-reqs
Installs the minimal requirements for ToUI to work. This is useful if you want to
Expand Down Expand Up @@ -60,21 +61,19 @@ def main():
if "init" in sys.argv:
if not "--full" in sys.argv:
response = requests.get("https://github.com/mubarakalmehairbi/BasicToUIProject/archive/master.zip", stream=True)
project_path = "MyBasicToUIProject"
if os.path.exists(project_path):
i = 1
project_path = f"MyBasicToUIProject_{i}"
while os.path.exists(project_path):
i += 1
project_path = f"MyBasicToUIProject_{i}"
z = zipfile.ZipFile(io.BytesIO(response.content))
z.extractall(project_path)


project_name = "MyBasicToUIProject"
else:
# To be added soon.
#requests.get("https://github.com/mubarakalmehairbi/ToUIFullAppTemplate/archive/master.zip")
pass
response = requests.get("https://github.com/mubarakalmehairbi/FullToUIProject/archive/master.zip")
project_name = "MyFullToUIProject"
project_path = project_name
if os.path.exists(project_path):
i = 1
project_path = f"{project_name}_{i}"
while os.path.exists(project_path):
i += 1
project_path = f"{project_name}_{i}"
z = zipfile.ZipFile(io.BytesIO(response.content))
z.extractall(project_path)

if __name__ == "__main__":
main()
15 changes: 10 additions & 5 deletions toui/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ def sign_in_using_google(self, client_id, client_secret, after_auth_url, additio
url = f"/toui-google-sign-in?scope={scope}"
if custom_username:
url += f"&username={custom_username}"
if custom_host:
url += f"&host={custom_host}"
self.user_vars._set('google-redirect-uri-host', custom_host)
for key, value in other_params.items():
url += f"&{key}={value}"
self.user_vars._set('google-after-auth-url', after_auth_url)
Expand Down Expand Up @@ -1047,8 +1046,8 @@ def _sign_in_using_google(self):
client_id = self._google_data['client_id']
client_secret = self._google_data['client_secret']
scope = request.args.get("scope")
if request.args.get("host"):
redirect_uri = request.args.get("host") + "/toui-google-sign-in"
if self.user_vars._get('google-redirect-uri-host') is not None:
redirect_uri = self.user_vars._get('google-redirect-uri-host') + "/toui-google-sign-in"
else:
redirect_uri = request.base_url
response_type = "code"
Expand All @@ -1062,6 +1061,7 @@ def _sign_in_using_google(self):
username = request.args.get("username")
if "code" in request.args:
code = request.args.get("code")
self.user_vars._set('google-redirect-uri-host', None)
dictToSend = {'code':code,
'client_id':client_id,
'client_secret':client_secret,
Expand All @@ -1071,6 +1071,7 @@ def _sign_in_using_google(self):
headers={'Host': 'oauth2.googleapis.com',
'Content-Type':'application/x-www-form-urlencoded'})
dictFromServer = res.json()
info(f"Google response keys: {dictFromServer.keys()}")
self.user_vars._set('google-access-token', dictFromServer['access_token'])
if 'refresh_token' in dictFromServer:
self.user_vars._set('google-refresh-token', dictFromServer['refresh_token'])
Expand All @@ -1082,7 +1083,11 @@ def _sign_in_using_google(self):
if self.email_exists(email):
self.signin_user(email=email, username=username, password=None)
else:
self.signup_user(email=email, username=username, password=None)
success = self.signup_user(email=email, username=username, password=None)
if success:
self.signin_user(email=email, username=username, password=None)
else:
error("Error signing up user")
return redirect(after_auth_url)
else:
# Validating scope
Expand Down

0 comments on commit c29cbde

Please sign in to comment.