First version of web help

This commit is contained in:
louis chauvet 2018-11-10 21:55:40 +01:00
parent 5f5192b704
commit bdcaf6bda5
8 changed files with 263 additions and 72 deletions

View File

@ -28,7 +28,7 @@ tr = {
},
"list_modules": {
"title": "Liste des modules",
},
},
"load": {
},
"unload": {

View File

@ -18,7 +18,7 @@
"level": "INFO",
"formatter": "simple",
"filename": "info.log",
"maxBytes": 10485760,
"maxBytes": 1048576,
"backupCount": 20,
"encoding": "utf8"
},
@ -27,7 +27,7 @@
"level": "ERROR",
"formatter": "simple",
"filename": "errors.log",
"maxBytes": 10485760,
"maxBytes": 1048576,
"backupCount": 20,
"encoding": "utf8"
},

View File

@ -73,7 +73,6 @@ setup_logging()
eventloop = asyncio.get_event_loop()
foBot = FoBot(db_connection=db_connection)
foWeb = FoWeb(bot=None, db=db_connection)
bot_app = foBot.start(os.environ['FOBOT_DISCORD_TOKEN'], max_messages=100000000)

View File

@ -11,7 +11,7 @@ import tornado.web
def maybe_create_tables(db):
with db.cursor() as cur:
#cur.execute("DROP TABLE users ")
# cur.execute("DROP TABLE users ")
cur.execute("CREATE TABLE IF NOT EXISTS users ("
" id int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
" email VARCHAR(100) NOT NULL UNIQUE,"
@ -146,7 +146,6 @@ class AuthLoginHandler(BaseHandler):
try:
user = self.queryone("SELECT * FROM users WHERE email = %s",
self.get_argument("email"))
print(user)
except NoResultError:
get_arg = self.get_argument
self.render("auth/login.html", error="Email not found or bad password", get_arg=get_arg)
@ -171,18 +170,21 @@ class AuthLogoutHandler(BaseHandler):
class AuthCreateHandler(BaseHandler):
async def get(self):
get_arg = self.get_argument
self.render("auth/create_user.html", get_arg=get_arg)
self.render("auth/create_user.html", error=None, get_arg=get_arg)
async def post(self):
hashed_password = await tornado.ioloop.IOLoop.current().run_in_executor(
None, bcrypt.hashpw, tornado.escape.utf8(self.get_argument("password")),
bcrypt.gensalt()
)
self.execute("INSERT INTO users (email, name, hashed_password) VALUES (%s, %s, %s)",
self.get_argument("email"), self.get_argument("name"),
tornado.escape.to_unicode(hashed_password))
users = self.queryone("SELECT * FROM users WHERE email = %s", self.get_argument("email"))
print(users)
try:
get_arg = self.get_argument
self.execute("INSERT INTO users (email, name, hashed_password) VALUES (%s, %s, %s)",
self.get_argument("email"), self.get_argument("name"),
tornado.escape.to_unicode(hashed_password))
users = self.queryone("SELECT * FROM users WHERE email = %s", self.get_argument("email"))
except:
self.render("auth/create_user.html", error="Email already exists.", get_arg=get_arg)
self.set_secure_cookie("blogdemo_user", str(users.id))
self.redirect(self.get_argument("next", "/"))
@ -193,7 +195,7 @@ class BlogHomeHandler(BaseHandler):
if not entries:
self.redirect("/blog/compose")
return
self.render("blog\\index.html", entries=entries)
self.render("blog/index.html", entries=entries)
class BlogPostHandler(BaseHandler):
@ -202,7 +204,7 @@ class BlogPostHandler(BaseHandler):
if not entry:
raise tornado.web.HTTPError(404)
self.render("blog\\entry.html", entry=entry)
self.render("blog/entry.html", entry=entry)
class BotConnectHandler(BaseHandler):
@ -213,9 +215,14 @@ class BotConfigureHandler(BaseHandler):
pass
class BotHelpHandler(BaseHandler):
async def get(self):
self.render("bot/help.html")
class BlogEntryModule(tornado.web.UIModule):
def render(self, entry):
return self.render_string("blog\\modules\\entry.html", entry=entry)
return self.render_string("blog/modules/entry.html", entry=entry)
class FoWeb(tornado.web.Application):
@ -231,7 +238,8 @@ class FoWeb(tornado.web.Application):
(r"/blog", BlogHomeHandler),
(r"/blog/entry/([^/]+)", BlogPostHandler),
(r"/bot/connect", BotConnectHandler),
(r"/bot/configure", BotConfigureHandler)
(r"/bot/configure", BotConfigureHandler),
(r"/bot/help", BotHelpHandler)
]
settings = dict(
website_title=u"FoBot",

View File

@ -1,137 +1,136 @@
body {
background: white;
color: black;
margin: 15px;
margin-top: 0;
background: white;
color: black;
margin: 15px;
margin-top: 0;
}
body,
input,
textarea {
font-family: Georgia, serif;
font-size: 12pt;
font-family: Georgia, serif;
font-size: 12pt;
}
table {
border-collapse: collapse;
border: 0;
border-collapse: collapse;
border: 0;
}
td {
border: 0;
padding: 0;
border: 0;
padding: 0;
}
h1,
h2,
h3,
h4 {
font-family: "Helvetica Nue", Helvetica, Arial, sans-serif;
margin: 0;
font-family: "Helvetica Nue", Helvetica, Arial, sans-serif;
margin: 0;
}
h1 {
font-size: 20pt;
font-size: 20pt;
}
pre,
code {
font-family: monospace;
color: #060;
font-family: monospace;
color: #060;
}
pre {
margin-left: 1em;
padding-left: 1em;
border-left: 1px solid silver;
line-height: 14pt;
margin-left: 1em;
padding-left: 1em;
border-left: 1px solid silver;
line-height: 14pt;
}
a,
a code {
color: #00c;
color: #060;
}
#body {
max-width: 800px;
margin: auto;
margin: auto;
}
#header {
background-color: #3b5998;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
margin-bottom: 1em;
background-color: #359;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
margin-bottom: 1em;
}
#header,
#header a {
color: white;
color: white;
}
#header h1 a {
text-decoration: none;
text-decoration: none;
}
#footer,
#content {
margin-left: 10px;
margin-right: 10px;
margin-left: 10px;
margin-right: 10px;
}
#footer {
margin-top: 3em;
margin-top: 3em;
}
.entry h1 a {
color: black;
text-decoration: none;
color: black;
text-decoration: none;
}
.entry {
margin-bottom: 2em;
margin-bottom: 2em;
}
.entry .date {
margin-top: 3px;
margin-top: 3px;
}
.entry p {
margin: 0;
margin-bottom: 1em;
margin: 0;
margin-bottom: 1em;
}
.entry .body {
margin-top: 1em;
line-height: 16pt;
margin-top: 1em;
line-height: 16pt;
}
.compose td {
vertical-align: middle;
padding-bottom: 5px;
vertical-align: middle;
padding-bottom: 5px;
}
.compose td.field {
padding-right: 10px;
padding-right: 10px;
}
.compose .title,
.compose .submit {
font-family: "Helvetica Nue", Helvetica, Arial, sans-serif;
font-weight: bold;
font-family: "Helvetica Nue", Helvetica, Arial, sans-serif;
font-weight: bold;
}
.compose .title {
font-size: 20pt;
font-size: 20pt;
}
.compose .title,
.compose .markdown {
width: 100%;
width: 100%;
}
.compose .markdown {
height: 500px;
line-height: 16pt;
height: 500px;
line-height: 16pt;
}

View File

@ -0,0 +1,74 @@
.documentation {
}
.documentation .summary {
margin:0;
padding: 0;
border: 0.25em solid #3b5998;
position: fixed;
overflow: auto;
width: 25%;
margin:0;
}
.documentation .summary h2 {
background-color: #3b5998;
padding: 0.4em;
}
.documentation .summary ul {
list-style-type: none;
padding: 0;
margin: 0;
}
.documentation .summary ul li {
display: block;
padding: 0;
}
.documentation .summary ul li ul {
display: none;
}
.documentation .summary ul li:hover ul {
display: block;
}
.documentation .summary a {
background-color: #5889ef;
color: black;
display: block;
padding: 0.3em;
text-decoration: none;
}
.documentation .summary a:hover {
background-color: #496ebc;
}
.documentation .summary a:active {
background-color: #4CAF50; /* Add a green color to the "active/current" link */
color: white;
}
.documentation .content {
margin-left: 28%;
}
.documentation .content h2 {
padding: 1em;
}
.documentation .content h3 {
padding: 0.5em;
}
.documentation .content h4 {
padding: 0.25em;
}
.documentation .content ul {
list-style-type: none;
}

View File

@ -1,11 +1,14 @@
{% extends "../base.html" %}
{% block body %}
<form action="/auth/create" method="POST">
Email: <input name="email" type="text" required><br>
Name: <input name="name" type="text" required><br>
Password: <input name="password" type="password" required><br>
{% module xsrf_form_html() %}
<input type="submit">
</form>
{% if error %}
<span style="color: red">Error: {{ error }}</span><p>
{% end %}
<form action="/auth/create" method="POST">
Email: <input name="email" type="text" required><br>
Name: <input name="name" type="text" required><br>
Password: <input name="password" type="password" required><br>
{% module xsrf_form_html() %}
<input type="submit">
</form>
{% end %}

108
web/templates/bot/help.html Normal file
View File

@ -0,0 +1,108 @@
{% extends "../base.html" %}
{% block head %}
<link rel="stylesheet" href="{{ static_url("documentation.css") }}" type="text/css">
{% end %}
{% block title %} {{ escape(handler.settings["website_title"]) }} - Help{% end %}
{% block body %}
<div class="documentation">
<div class="summary">
<h2>Summary</h2>
<ul>
<li>
<a href="#module_modules">Module (<code>modules</code>)</a>
<ul>
<li><a href="#">Liste des modules</a></li>
<li><a href="#">Charger un module</a></li>
<li><a href="#">Décharger un module</a></li>
</ul>
</li>
<li>
<a href="#module_help">Help (<code>help</code>)</a>
<ul>
<li><a href="#">Aide générale</a></li>
<li><a href="#">Aide d'un module précit</a></li>
<li><a href="#">Aide d'une commande précise</a></li>
</ul>
</li>
<li><a href="">Cofiguration (<code>config</code>)</a></li>
<li><a href="">Deeptown (<code>deeptown</code>)</a></li>
<li><a href="">Survey (<code>survey</code>)</a></li>
<li><a href="">Pi (<code>pi</code>)</a></li>
<li><a href="">Github (<code>github</code>)</a></li>
<li><a href="">Direct access to database (<code>directAccessDB</code>)</a></li>
</ul>
</div>
<div class="content">
<h2 id="module_modules">Modules (<code>modules</code>)</h2>
<div>
<h3>Liste des modules (<code>list_modules</code>)</h3>
<div>
<p>Commande permettant de lister les modules disponibles. (réservé aux administrateurs)</p>
<div>
<h4>Exemples:</h4>
<ul>
<li><code>list_modules</code>: retourne la liste des modules disponibles</li>
</ul>
</div>
</div>
<h3>Charger un module (<code>load</code>)</h3>
<div>
<p>Commande permettant de charger des modules. (réservé aux administrateurs)</p>
<div>
<h4>Exemples:</h4>
<ul>
<li><code>load help</code>: charge le module <code>help</code></li>
<li><code>load help module1 module2 ...</code>: charger les modules <code>help</code>,
<code>module1</code>,
<code>module2</code>,
...
</li>
</ul>
</div>
</div>
<h3>Décharger un module (<code>unload</code>)</h3>
<div>
<p>Commande permettant de décharger des modules. (réservé aux administrateurs)</p>
<div>
<h4>Exemples:</h4>
<ul>
<li><code>unload module</code>: décharge le module <code>module</code></li>
<li><code>unload module1 module2 module3 ...</code>: décharge les modules <code>module1</code>,
<code>module2</code>,
<code>module3</code>, ...
</li>
</ul>
</div>
</div>
</div>
<h2 id="module_help">Help (<code>help</code>)</h2>
<div>
<h3>Aide générale</h3>
<div>
<p>Commande permettant de lister les différentes commandes actives sur le bot.</p>
<div>
<h4>Exemples:</h4>
<ul>
<li><code>help</code>: Afficher la liste des commandes</li>
</ul>
</div>
</div>
<h3>Aide d'un module précit</h3>
<div>
<p>Commande permmetant d'afficher la description de toutes les commandes d'un module.</p>
<div>
<h4>Exemples:</h4>
<ul>
<li><code>help modules</code>: Affiche la description de toutes les commandes du module
<code>modules</code>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
{% end %}