Skip to content

Commit ca479bb

Browse files
dorianbrownnaoyak
authored andcommitted
Added LdapAuthProvider, and tweaked login-form to require password and
look pretty.
1 parent 75960be commit ca479bb

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
from flask import request, render_template
3+
from ldap3 import Server, Connection, ALL
4+
5+
from ..models import User
6+
from ..auth_provider import KnowledgeAuthProvider
7+
8+
9+
class LdapAuthProvider(KnowledgeAuthProvider):
10+
_registry_keys = ['ldap']
11+
12+
def init(self):
13+
# Create server connection
14+
address = "ldap://127.0.0.1:389" # Move to Config file
15+
self.server = Server(address, get_info=ALL)
16+
17+
def prompt(self):
18+
return render_template('auth-login-form.html', skip_password=False)
19+
20+
def validate(self, user):
21+
user_id = user.identifier
22+
password = request.form['password']
23+
userdn_string = "cn={0},ou=people,dc=planetexpress,dc=com" # Move to Config file
24+
conn = Connection(self.server, user=userdn_string.format(user_id), password=password)
25+
return conn.bind()
26+
27+
# TODO: Populate user with LDAP INFO. Put LDAP Schema in config file?
28+
def get_user(self):
29+
return User(identifier=request.form['username'])

knowledge_repo/app/templates/auth-login-form.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
.login-form {
77
display: block;
88
list-style-type: none;
9-
margin: 10px;
9+
width: 340px;
10+
margin: 50px auto;
1011
padding: 1em;
1112
background: white;
1213
border: 1px solid #e2ddddcf;
@@ -28,16 +29,21 @@
2829
.login-form > input[type=submit] {
2930
margin-bottom: 0px;
3031
}
32+
.login-form > p {
33+
font-size: 30px;
34+
text-align: center;
35+
}
3136

3237
button, input, select, textarea {
3338
font-weight: 500;
3439
}
3540
</style>
3641

3742
<form name='login' action='authorize' method='POST' class='login-form'>
43+
<p> Log in </p>
3844
<input type='text' placeholder="Username" name='username' />
3945
{% if not skip_password %}
40-
<input type='password' placeholder="Password" name='password' />
46+
<input type='password' placeholder="Password" name='password' required/>
4147
{% endif %}
4248
<input type='submit' value='Sign in'/>
4349
</form>

0 commit comments

Comments
 (0)