fixing login stuff

separate_pages
quadrismegistus 4 years ago
parent 7b752abfd6
commit dd6c0507fc

@ -0,0 +1 @@
{"user": {"logged_in": true, "logged_in_when": 1596706879.5428135}}

@ -1,43 +1,2 @@
testing
<class '__main__.MyLayout'>
<class '__main__.MainApp'>
testing2
<class '__main__.MainApp'>
testing2
<class '__main__.MainApp'>
<class '__main__.MainApp'>
<class '__main__.MainApp'>
<__main__.MyIconButton object at 0x7f7d4ea78c78>
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
<Response [401]>
FAILED!Login failed
FAILED!Login failed
[True, True]
['build', True]

@ -25,7 +25,8 @@ MyLayout:
background_palette: 'Red'
background_hue: '500'
specific_text_color: 1,0,0,1
right_action_items: [['radio-tower', partial(root.change_screen, 'feed')], ['account-group', partial(root.change_screen, 'people')], ['calendar', partial(root.change_screen, 'events')], ['message-processing-outline', partial(root.change_screen, 'messages')], ['bell-outline', partial(root.change_screen, 'notifications')]]
# right_action_items: [['radio-tower', partial(root.change_screen, 'feed')], ['account-group', partial(root.change_screen, 'people')], ['calendar', partial(root.change_screen, 'events')], ['message-processing-outline', partial(root.change_screen, 'messages')], ['bell-outline', partial(root.change_screen, 'notifications')]]
right_action_items: [['post-outline', partial(root.change_screen, 'feed')], ['message-processing-outline', partial(root.change_screen, 'messages')], ['bell-outline', partial(root.change_screen, 'notifications')]]
left_action_items: [[f"assets/logo.png", partial(root.change_screen, 'welcome')]]
ScreenManager:
@ -33,6 +34,12 @@ MyLayout:
# transition: NoTransition()
###
# LOGIN SCREEN
###
LoginScreen:
name: "login"
# text: "Login"
@ -40,22 +47,27 @@ MyLayout:
MDBoxLayout:
orientation: "vertical"
pos_hint: {'center_x':.5, 'center_y':0.55}
size_hint:0.5,0.5
pos_hint: {'center_x':0.5, 'center_y':0.5}
size_hint:0.5,None
padding:'10dp'
# md_bg_color:1,0,0,1
id: loginbox
MDTextField:
id: username
hint_text: "Username"
hint_text: "username"
required: True
write_tab: False
multiline: False
helper_text_mode: "on_error"
MDTextField:
id: password
password: True
hint_text: "Password"
hint_text: "password"
required: True
write_tab: False
multiline: False
helper_text_mode: "on_error"
@ -90,7 +102,12 @@ MyLayout:
name: 'welcome'
MyLabel:
text: "Turning and turning in the widening gyre \nThe falcon cannot hear the falconer;\nThings fall apart; the centre cannot hold;\nMere anarchy is loosed upon the world,\nThe blood-dimmed tide is loosed, and everywhere \nThe ceremony of innocence is drowned;\nThe best lack all conviction, while the worst \nAre full of passionate intensity.\n\nSurely some revelation is at hand;\nSurely the Second Coming is at hand. \nThe Second Coming! Hardly are those words out \nWhen a vast image out of Spiritus Mundi\nTroubles my sight: somewhere in sands of the desert \nA shape with lion body and the head of a man, \nA gaze blank and pitiless as the sun, \nIs moving its slow thighs, while all about it \nReel shadows of the indignant desert birds. \nThe darkness drops again; but now I know \nThat twenty centuries of stony sleep\nWere vexed to nightmare by a rocking cradle, \nAnd what rough beast, its hour come round at last, \nSlouches towards Bethlehem to be born?"
text: "Welcome!"
font_style: "H3"
pos_hint: {'center_y':0.85}
MyLabel:
text: "\n\nTurning and turning in the widening gyre \nThe falcon cannot hear the falconer;\nThings fall apart; the centre cannot hold;\nMere anarchy is loosed upon the world,\nThe blood-dimmed tide is loosed, and everywhere \nThe ceremony of innocence is drowned;\nThe best lack all conviction, while the worst \nAre full of passionate intensity.\n\nSurely some revelation is at hand..."
PeopleScreen:

@ -21,6 +21,9 @@ from kivy.properties import NumericProperty
from kivymd.uix.list import * #MDList, ILeftBody, IRightBody, ThreeLineAvatarListItem, TwoLineAvatarListItem, BaseListItem, ImageLeftWidget
from kivy.uix.image import Image, AsyncImage
import requests,json
from kivy.storage.jsonstore import JsonStore
from kivy.core.window import Window
Window.size = (640, 1136) #(2.65 * 200, 5.45 * 200)
root = None
@ -46,6 +49,7 @@ class MyLabel(MDLabel):
self.pos_hint = {'center_y': 0.5}
self.halign='center'
self.height=self.texture_size[1]
self.font_family='Courier'
for k,v in kwargs.items(): setattr(self,k,v)
class ContactPhoto(ILeftBody, AsyncImage):
@ -95,7 +99,7 @@ class PostCard(MDCard):
class ProtectedScreen(MDScreen):
def on_pre_enter(self):
global app
if app.logged_on==False:
if not app.is_logged_in():
app.root.change_screen('login')
@ -128,24 +132,42 @@ class FeedScreen(ProtectedScreen):
class MainApp(MDApp):
title = 'Gyre'
api = 'http://localhost:5555/api'
logged_on=False
logged_in=False
store = JsonStore('gyre.json')
login_expiry = 60 * 60 * 24 * 7 # once a week
#login_expiry = 5 # 5 seconds
def build(self):
global app,root
app = self
self.root = root = Builder.load_file('main.kv')
self.root.change_screen('login')
if not self.is_logged_in():
self.root.change_screen('login')
else:
self.root.change_screen('welcome')
return self.root
def is_logged_in(self):
if self.logged_in: return True
if not self.store.exists('user'): return False
if self.store.get('user')['logged_in']:
if time.time() - self.store.get('user')['logged_in_when'] < self.login_expiry:
self.logged_in=True
return True
return False
def do_login(self):
self.logged_in=True
self.store.put('user',logged_in=True,logged_in_when=time.time())
self.root.change_screen('welcome')
def login(self,un,pw):
url = self.api+'/login'
res = requests.post(url, json={'name':un, 'passkey':pw})
if res.status_code==200:
self.logged_on=True
self.root.change_screen('welcome')
self.do_login()
else:
self.root.ids.login_status.text=res.text
@ -153,8 +175,7 @@ class MainApp(MDApp):
url = self.api+'/register'
res = requests.post(url, json={'name':un, 'passkey':pw})
if res.status_code==200:
self.logged_on=True
self.root.change_screen('welcome')
self.do_login()
else:
self.root.ids.login_status.text=res.text

@ -39,6 +39,9 @@ class Handler(FileSystemEventHandler):
if event.is_directory:
return None
if event.src_path.endswith('gyre.json'): return None
if event.src_path.endswith('log.txt'): return None
elif event.event_type == 'created':
# Take any action here when a file is first created.
print("Received created event - %s." % event.src_path)

Loading…
Cancel
Save