seed listing view and template

This commit is contained in:
wcolmenares 2019-05-26 16:15:07 -04:00
parent 321d8548da
commit d37144c541
2 changed files with 73 additions and 6 deletions

View file

@ -0,0 +1,35 @@
{% extends "base_short.html" %}
{% load i18n staticfiles bootstrap3 %}
{% block title %}
<title>Options for {{user}}</title>
{% endblock %}
{% block content %}
<div class="auth-container">
<div class="auth-bg"></div>
<div class="auth-center">
<div class="auth-content">
<div class="auth-box">
<h1 class="section-heading allcaps">{% trans "Seeds of," %} {{user}}</h1><br><br>
<table class="table table-hover text-center">
<tbody>
{% for i in seed %}
<tr>
<td>{{ i.realm }}</td>
<td>{{ i.seed }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<br>
<hr>
<div class="text-center">
<a href="{% url 'account_delete' %}">Delete your account</a><br>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View file

@ -34,6 +34,13 @@ from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
admin_seed = config('ADMIN_SEED')
admin_name = config('ADMIN_NAME')
admin_realm = config('ADMIN_REALM')
user_realm = config('USER_REALM')
otp_url = config('OTPSERVER')
def activate_account_link(base_url, user, pwd, firstname, lastname, email, epochutc):
tokengen = PasswordResetTokenGenerator()
pseudouser = PseudoUser()
@ -551,6 +558,17 @@ class ActivateAccount(View):
ldap_manager.create_user(
clean_list[0], clean_list[1], clean_list[2], clean_list[3], clean_list[4]
)
req = requests.post(otp_url, data=json.dumps(
{
'auth_token': TOTP(admin_seed).now(),
'auth_name': admin_name,
'auth_realm': admin_realm,
'name': clean_list[0],
'realm': user_realm
}), headers={'Content-Type': 'application/json'})
if req.status_code != 201:
logger.error("User {} failed to create its otp seed".format(clean_list[0]))
#Send welcome email
except Exception as e:
return render(request, 'error.html', {'urlname': 'register',
@ -624,15 +642,12 @@ class SeedRetrieveCreate(APIView):
user = authenticate(username=username, password=password)
if user is not None:
admin_seed = config('ADMIN_SEED')
admin_name = config('ADMIN_NAME')
otp_url = config('OTPSERVER')
req = requests.get(otp_url, data=json.dumps(
{
'auth_token': TOTP(admin_seed).now(),
'auth_name': admin_name,
'auth_realm': 'ungleich-admin'}), headers={'Content-Type': 'application/json'})
'auth_realm': admin_realm}), headers={'Content-Type': 'application/json'})
response_data = json.loads(req.text)
@ -648,7 +663,7 @@ class SeedRetrieveCreate(APIView):
{
'auth_token': TOTP(admin_seed).now(),
'auth_name': admin_name,
'auth_realm': 'ungleich-admin',
'auth_realm': admin_realm,
'name': username,
'realm': realm
}), headers={'Content-Type': 'application/json'})
@ -660,3 +675,20 @@ class SeedRetrieveCreate(APIView):
else:
return Response('Invalid Credentials', 400)
class Seeds(LoginRequiredMixin, View):
login_url = reverse_lazy('login_index')
def get(self, request):
seedlist = []
response = requests.get(
otp_url,
headers={'Content-Type': 'application/json'},
data=json.dumps(
{'auth_name': admin_name, 'auth_realm': admin_realm, 'auth_token': TOTP(admin_seed).now()}))
response_data = json.loads(response.text)
for i in range(len(response_data)):
if response_data[i]['name'] == 'wcolmenares': #request.user:
value = {'realm': response_data[i]['realm'], 'seed': response_data[i]['seed']}
seedlist.append(value)
return render(request, 'seed_list.html', {'seed': seedlist})