mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 14:56:47 +00:00
Merge pull request #126 from hongwei1/master
feature/added create user invitation page
This commit is contained in:
commit
7fe03cd201
@ -35,11 +35,13 @@
|
||||
<li{% if entitlementrequests_index_url in request.path %} class="active"{% endif %}><a href="{{ entitlementrequests_index_url }}">Entitlement Requests</a></li>
|
||||
{% url "users-index" as users_index_url %}
|
||||
{% url 'my-user-detail' API_USER_ID as url_users_detail %}
|
||||
<li class="dropdown{% if users_index_url in request.path or url_users_detail in request.path %} active{% endif %}">
|
||||
{% url "my-user-invitation" as my_user_invitation %}
|
||||
<li class="dropdown{% if users_index_url in request.path or url_users_detail or my_user_invitation in request.path %} active{% endif %}">
|
||||
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Users</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li{% if users_index_url in request.path %} class="active"{% endif %}><a href="{{ users_index_url }}">All</a></li>
|
||||
<li{% ifequal request.path url_users_detail %} class="active" {% endifequal %}><a href="{{ url_users_detail }}">My User</a></li>
|
||||
<li{% ifequal request.path my_user_invitation %} class="active" {% endifequal %}><a href="{{ my_user_invitation }}">Invite Developer</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
{% url "api-metrics" as api_metrics_url %}
|
||||
|
||||
@ -5,7 +5,6 @@ Forms of users app
|
||||
|
||||
from django import forms
|
||||
|
||||
|
||||
class AddEntitlementForm(forms.Form):
|
||||
user_id = forms.CharField(
|
||||
widget=forms.HiddenInput(),
|
||||
@ -34,3 +33,76 @@ class AddEntitlementForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('label_suffix', '')
|
||||
super(AddEntitlementForm, self).__init__(*args, **kwargs)
|
||||
|
||||
class CreateInvitationForm(forms.Form):
|
||||
bank_id = forms.ChoiceField(
|
||||
label='Bank',
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
choices=[],
|
||||
)
|
||||
first_name = forms.CharField(
|
||||
label='First Name',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'First Name',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
)
|
||||
last_name = forms.CharField(
|
||||
label='Last Name',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'Last Name',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
)
|
||||
email = forms.CharField(
|
||||
label='Email',
|
||||
widget=forms.EmailInput(
|
||||
attrs={
|
||||
'placeholder': 'felixsmith@example.com',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
company = forms.CharField(
|
||||
label='Company',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'TESOBE GmbH',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
country = forms.CharField(
|
||||
label='Country',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'Germany',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
purpose = forms.CharField(
|
||||
label='Purpose',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'placeholder': 'For the Bank App',
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs.setdefault('label_suffix', '')
|
||||
super(CreateInvitationForm, self).__init__(*args, **kwargs)
|
||||
|
||||
84
apimanager/users/templates/users/invitation.html
Normal file
84
apimanager/users/templates/users/invitation.html
Normal file
@ -0,0 +1,84 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block page_title %}{{ block.super }} / Users{% endblock page_title %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div id="create-invitation">
|
||||
<h1>Invitation Developer</h1>
|
||||
|
||||
<form action="{% url 'my-user-invitation' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger">
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.bank_id.errors %}<div class="alert alert-danger">{{ form.bank_id.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.bank_id.label_tag }}
|
||||
{{ form.bank_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.first_name.errors %}<div class="alert alert-danger">{{ form.first_name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.first_name.label_tag }}
|
||||
{{ form.first_name }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
{% if form.last_name.errors %}<div class="alert alert-danger">{{ form.last_name.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.last_name.label_tag }}
|
||||
{{ form.last_name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-3">
|
||||
{% if form.email.errors %}<div class="alert alert-danger">{{ form.email.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.email.label_tag }}
|
||||
{{ form.email }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-3">
|
||||
{% if form.company.errors %}<div class="alert alert-danger">{{ form.company.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.company.label_tag }}
|
||||
{{ form.company }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-3">
|
||||
{% if form.country.errors %}<div class="alert alert-danger">{{ form.country.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.country.label_tag }}
|
||||
{{ form.country }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-3">
|
||||
{% if form.purpose.errors %}<div class="alert alert-danger">{{ form.purpose.errors }}</div>{% endif %}
|
||||
<div class="form-group">
|
||||
{{ form.purpose.label_tag }}
|
||||
{{ form.purpose }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Create" class="btn btn-primary" />
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
||||
{% block extrajs %}
|
||||
{% endblock extrajs %}
|
||||
|
||||
{% block extracss %}
|
||||
<link href="{% static 'users/css/users.css' %}" rel="stylesheet">
|
||||
{% endblock extracss %}
|
||||
@ -5,7 +5,7 @@ URLs for users app
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import IndexView, DetailView, MyDetailView, DeleteEntitlementView
|
||||
from .views import IndexView, DetailView, MyDetailView, DeleteEntitlementView,InvitationView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^all$',
|
||||
@ -17,6 +17,9 @@ urlpatterns = [
|
||||
url(r'^myuser/user_id/(?P<user_id>[\w\@\.\+-]+)$',
|
||||
MyDetailView.as_view(),
|
||||
name='my-user-detail'),
|
||||
url(r'^myuser/invitation$',
|
||||
InvitationView.as_view(),
|
||||
name='my-user-invitation'),
|
||||
url(r'^(?P<user_id>[\w-]+)/entitlement/delete/(?P<entitlement_id>[\w-]+)$',
|
||||
DeleteEntitlementView.as_view(),
|
||||
name='users-delete-entitlement'),
|
||||
|
||||
@ -2,17 +2,15 @@
|
||||
"""
|
||||
Views of users app
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.views.generic import FormView, TemplateView, View
|
||||
|
||||
from base.filters import BaseFilter
|
||||
from obp.api import API, APIError
|
||||
|
||||
from .forms import AddEntitlementForm
|
||||
from .forms import AddEntitlementForm,CreateInvitationForm
|
||||
|
||||
|
||||
class FilterRoleName(BaseFilter):
|
||||
@ -254,6 +252,54 @@ class MyDetailView(LoginRequiredMixin, FormView):
|
||||
})
|
||||
return context
|
||||
|
||||
class InvitationView(LoginRequiredMixin, FormView):
|
||||
"""View to create a User Invitation"""
|
||||
form_class = CreateInvitationForm
|
||||
template_name = 'users/invitation.html'
|
||||
success_url = reverse_lazy('my-user-invitation')
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.api = API(request.session.get('obp'))
|
||||
return super(InvitationView, self).dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form(self, *args, **kwargs):
|
||||
form = super(InvitationView, self).get_form(*args, **kwargs)
|
||||
form.api = self.api
|
||||
fields = form.fields
|
||||
try:
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
data = form.cleaned_data
|
||||
urlpath = '/banks/{}/user-invitation'.format(data['bank_id'])
|
||||
payload = {
|
||||
'first_name': data['first_name'],
|
||||
'last_name': data['last_name'],
|
||||
'email': data['email'],
|
||||
'company': data['company'],
|
||||
'country': data['country'],
|
||||
'purpose': data['purpose']
|
||||
}
|
||||
try:
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
if 'code' in result and result['code'] >= 400:
|
||||
messages.error(self.request, result['message'])
|
||||
return super(InvitationView, self).form_valid(form)
|
||||
else:
|
||||
msg = 'Create User Invitation secret_key({}) at Bank({}) has been {}!'.format(result['secret_key'],data['bank_id'], result['status'] )
|
||||
messages.success(self.request, msg)
|
||||
return super(InvitationView, self).form_valid(form)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return super(InvitationView, self).form_invalid(form)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
return super(InvitationView, self).form_invalid(form)
|
||||
|
||||
class DeleteEntitlementView(LoginRequiredMixin, View):
|
||||
"""View to delete an entitlement"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user