Skip to content

Commit 1a00120

Browse files
updated registration
1 parent 06bdfda commit 1a00120

File tree

3 files changed

+7
-55
lines changed

3 files changed

+7
-55
lines changed

src/routers/ui_routes.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import src.oauth2 as oauth2
1010
from src.config import Settings
11-
from src import models
11+
from src import models, schemas
1212
from src import app
1313

1414

@@ -74,32 +74,19 @@ async def register(request: Request, response_model=HTMLResponse):
7474
form = form._dict
7575
form.pop('register')
7676

77+
#validates the form data
7778
new_user = models.User(**form)
7879

7980
base_url = request.base_url
80-
login_url = app.user_router.url_path_for('create_user')
81-
request_url = base_url.__str__() + login_url.__str__()[1:]
81+
create_user_url = app.user_router.url_path_for('create_user')
82+
request_url = base_url.__str__() + create_user_url.__str__()[1:]
8283
http3client = http3.AsyncClient()
83-
response = await http3client.post(request_url, data=form)
84+
response = await http3client.post(request_url, json=form)
8485

85-
if (response.status_code==200):
86-
data = response.json()
87-
token = data['access_token']
88-
89-
redirect = RedirectResponse(url=router.url_path_for('home'))
86+
if (response.status_code==201):
87+
redirect = RedirectResponse(url=router.url_path_for('signin'))
9088
redirect.status_code = 302
91-
redirect.set_cookie('Authorization', f'Bearer {token}')
9289
return redirect
9390

94-
95-
96-
print ('\n\n')
97-
print(new_user.id)
98-
print(new_user.email)
99-
# print (form)
100-
print ('\n\n')
101-
102-
103-
10491
return TEMPLATES.TemplateResponse("accounts/register.html", {"request" : request})
10592

src/sql_app.db

0 Bytes
Binary file not shown.

src/templates/accounts/register.html

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,6 @@ <h5>Sign UP</h5>
8888
</div>
8989

9090
</form>
91-
<script>
92-
let register_form = document.querySelector('#register_form')
93-
94-
register_form.addEventListener('submit', async function(event){
95-
/* event.preventDefault() */
96-
return
97-
/* let form_action = register_form.action */
98-
/* let email = register_form.querySelector('#email').value */
99-
/* let username = register_form.querySelector('#username').value */
100-
/* let password = register_form.querySelector('#password').value */
101-
102-
/* let new_user = {
103-
'email' : email,
104-
'username' : username,
105-
'password' : password
106-
} */
107-
108-
fetch(form_action, {
109-
method: "POST",
110-
headers: {'Content-Type' : 'application/json'},
111-
body: JSON.stringify(new_user)
112-
113-
}).then(res => {
114-
if (res.status==201){
115-
register_form.reset()
116-
alert('success, now signin')
117-
window.location.href = register_form.dataset.successful_redirect
118-
} else {
119-
alert('bad credentials')
120-
}
121-
122-
})
123-
124-
125-
</script>
12691
{% endif %}
12792

12893
</div>

0 commit comments

Comments
 (0)