login checks

This commit is contained in:
Raffu Khondaker 2020-06-04 22:43:35 -04:00
parent 1825ace9a4
commit edfb553df6
2 changed files with 21 additions and 4 deletions

View File

@ -6,6 +6,10 @@ import argparse
#already ccrerrated account through website, has to login #already ccrerrated account through website, has to login
def update():
#get data from database
return
def yesorno(question): def yesorno(question):
questions = [ questions = [
{ {
@ -42,7 +46,7 @@ def login():
if(user["webmail"] == data[i]["webmail"] and user["password"]) == data[i]["password"]: if(user["webmail"] == data[i]["webmail"] and user["password"]) == data[i]["password"]:
print("Logged in!") print("Logged in!")
return data[i] return data[i]
print("Error in your submission. Please re-enter") print("User not found. Please Try again")
return None return None
#did not create account through website, has to signup/login #did not create account through website, has to signup/login
@ -68,7 +72,7 @@ def signup():
{ {
'type': 'input', 'type': 'input',
'name': 'webmail', 'name': 'webmail',
'message': 'What\'s TJ Webmail?', 'message': 'What\'s your TJ Webmail?',
}, },
{ {
'type': 'password', 'type': 'password',
@ -77,6 +81,19 @@ def signup():
}, },
] ]
user = prompt(questions) user = prompt(questions)
for i in user:
if user[i] == "":
print("Some forms were left blank. Try again.\n")
return
if len(user["password"]) < 6:
print("Password is too short. Try again.")
return
if (("@tjhsst.edu" in user['webmail']) == False):
print("Webmail entered was not a @tjhhsst.edu. Try again.")
return
print("@tjhsst.edu" in user['webmail'] == False)
user["classes"] = [] user["classes"] = []
with open('users.json', 'r') as json_file: with open('users.json', 'r') as json_file:
data = json.load(json_file) data = json.load(json_file)
@ -91,7 +108,6 @@ def setup(user):
for a in user["classes"][c]: for a in user["classes"][c]:
os.makedirs(c + "/" + a) os.makedirs(c + "/" + a)
def start(): def start():
if(os.path.exists(".login.txt") == True): if(os.path.exists(".login.txt") == True):
b = yesorno("Do you have a SkoolOS account?(y/N)") b = yesorno("Do you have a SkoolOS account?(y/N)")

3
run.py
View File

@ -1,6 +1,6 @@
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
from PyInquirer import prompt, print_json from PyInquirer import prompt, print_json
from commands import start from commands import start, update
import argparse import argparse
import json import json
import os import os
@ -10,6 +10,7 @@ my_parser = argparse.ArgumentParser(prog='skool', description='Let SkoolOS contr
my_parser.add_argument('--init', action="store_true") #returns true if run argument my_parser.add_argument('--init', action="store_true") #returns true if run argument
args = my_parser.parse_args() args = my_parser.parse_args()
update()
outputs = vars(args) outputs = vars(args)
if(outputs['init']): if(outputs['init']):
start() start()