text = form.getfirst("text", "") text = html.escape(text) if text and user is not None: wall.publish(user, text) elif action == "login": login = form.getfirst("login", "") login = html.escape(login) password = form.getfirst("password", "") password = html.escape(password) if wall.find(login, password): cookie = wall.set_cookie(login) print('Set-cookie: session={}'.format(cookie)) elif wall.find(login): pass # А надо бы предупреждение выдать else: wall.register(login, password) cookie = wall.set_cookie(login) print('Set-cookie: session={}'.format(cookie)) pattern = ''' <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>The wall</title> </head> <body> Form for login and registration. If not in base, register new user. <form action="/cgi-bin/wall.py"> Login: <input type="text" name="login"> Pass: <input type="password" name="password">
text = form.getfirst("text", "") text = html.escape(text) if text and user is not None: wall.publish(user, text) elif action == "login": login = form.getfirst("login", "") login = html.escape(login) password = form.getfirst("password", "") password = html.escape(password) if wall.find(login, password): cookie = wall.set_cookie(login) print('Set-cookie: session={}'.format(cookie)) elif wall.find(user): print('что-то пошло не так') # А надо бы предупреждение выдать else: wall.register(user, password) cookie = wall.set_cookie(login) print('Set-cookie: session={}'.format(cookie)) pattern = ''' <!DOCTYPE HTML> <html> <head> <meta charset="windows-1251"> <title>Стена</title> </head> <body> Форма логина и регистрации. При вводе несуществующего имени зарегистрируется новый пользователь. <form action="/cgi-bin/wall.py"> Логин: <input type="text" name="login"> Пароль: <input type="password" name="password">
#!/usr/bin/env python3 import cgi, time, os, http.cookies import random, base64, sqlite3 from _wall import Wall wall = Wall() wall.register("123", "22") wall.register("44", "55") wall.prall() print(wall.find('1234'))
<meta http-equiv="refresh" content="0; url="http:/cgi-bin/wall.py" /> <script type="text/javascript"> window.location.href = "http:/cgi-bin/wall.py" </script> </head> </html> ''' print(pattern) if action == "reg": #если хотим зарегистрироваться login = form.getfirst("login", "") password = form.getfirst("password", "") fam = form.getfirst("fam", "") im = form.getfirst("im", "") otch = form.getfirst("otch", "") job = form.getfirst("job", "") adm = form.getfirst("adm", "") possib = wall.register(login, password, adm) if not possib: pattern = ''' <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta http-equiv="refresh" content="0; url="http:/loginex/loginex.html" /> <script type="text/javascript"> window.location.href = "http:/loginex/loginex.html" </script> </head> </html> ''' print(pattern) else: wall.register1(login, fam, im, otch, job)