-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2
- Loading branch information
Showing
6 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from chimedb.core import connect as connect_chimedb | ||
from chimedb.core.mediawiki import MediaWikiUser | ||
|
||
import panel as pn | ||
import tornado | ||
|
||
|
||
def get_user(request_handler): | ||
user = request_handler.get_secure_cookie("user") | ||
if user is not None and isinstance(user, (str, bytes, bytearray)): | ||
user = tornado.escape.json_decode(user) | ||
return user | ||
|
||
|
||
next_url = "/" | ||
|
||
login_url = "/login" | ||
|
||
|
||
class LoginHandler(tornado.web.RequestHandler): | ||
def get(self): | ||
errormessage = self.get_argument("error", "") | ||
self.render("login.html", errormessage=errormessage) | ||
|
||
def post(self): | ||
username = self.get_argument("username", "") | ||
password = self.get_argument("password", "") | ||
|
||
if not username: | ||
error_msg = "?error=" + tornado.escape.url_escape("Invalid username.") | ||
self.redirect(login_url + error_msg) | ||
return | ||
|
||
connect_chimedb() | ||
try: | ||
MediaWikiUser.authenticate(username, password) | ||
except UserWarning as err: | ||
error_msg = "?error=" + tornado.escape.url_escape(str(err)) | ||
self.redirect(login_url + error_msg) | ||
else: | ||
# make the username accessible to the panel application | ||
pn.state.cache["username"] = username | ||
self.set_current_user(username) | ||
self.redirect(next_url) | ||
|
||
def set_current_user(self, user): | ||
if user: | ||
self.set_secure_cookie("user", tornado.escape.json_encode(user)) | ||
else: | ||
self.clear_cookie("user") | ||
|
||
def get_user(self): | ||
user = self.get_secure_cookie("user") | ||
if user is not None and isinstance(user, (str, bytes, bytearray)): | ||
user = tornado.escape.json_decode(user) | ||
return user | ||
|
||
|
||
logout_url = "/logout" | ||
|
||
|
||
class LogoutHandler(tornado.web.RequestHandler): | ||
def get(self): | ||
self.clear_cookie("user") | ||
self.redirect(next_url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!--This is taken from https://github.com/bokeh/bokeh/blob/branch-2.2/examples/howto/server_auth/login.html--> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>login - bondia | CHIME Daily Validation</title> | ||
<style> | ||
*{ | ||
margin:0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
html{ | ||
height: 100%; | ||
} | ||
img { | ||
max-width: 100%; | ||
max-height: 100%; | ||
} | ||
body{ | ||
font-family: 'Segoe UI', sans-serif;; | ||
font-size: 1rem; | ||
line-height: 1.6; | ||
height: 100%; | ||
} | ||
.wrap { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background: #fafafa; | ||
} | ||
.login-form{ | ||
width: 350px; | ||
margin: 0 auto; | ||
border: 1px solid #ddd; | ||
padding: 2rem; | ||
background: #ffffff; | ||
} | ||
.form-input{ | ||
background: #fafafa; | ||
border: 1px solid #eeeeee; | ||
padding: 12px; | ||
width: 100%; | ||
} | ||
.form-group{ | ||
margin-bottom: 1rem; | ||
} | ||
.form-button{ | ||
background: #69d2e7; | ||
border: 1px solid #ddd; | ||
color: #ffffff; | ||
padding: 10px; | ||
width: 100%; | ||
text-transform: uppercase; | ||
} | ||
.form-button:hover{ | ||
background: #69c8e7; | ||
} | ||
.form-header{ | ||
text-align: center; | ||
margin-bottom : 2rem; | ||
} | ||
.form-footer{ | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wrap"> | ||
<form class="login-form" action="/login" method="post"> | ||
{% module xsrf_form_html() %} | ||
<div class="form-header"> | ||
<h3><img alt="CHIME logo" src="https://bao.chimenet.ca/wiki/images/2/20/Logo_chime_20140529_4cyl.svg"></h3> | ||
<p>Login to access CHIME daily validation</p> | ||
</div> | ||
<!--Email Input--> | ||
<div class="form-group"> | ||
<input name="username" type="text" class="form-input" autocapitalize="off" autocorrect="off" placeholder="username"> | ||
</div> | ||
<!--Password Input--> | ||
<div class="form-group"> | ||
<input name="password" type="password" class="form-input" placeholder="password"> | ||
</div> | ||
<!--Login Button--> | ||
<div class="form-group"> | ||
<button class="form-button" type="submit">Login</button> | ||
</div> | ||
<span class="errormessage">{{errormessage}}</span> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters