mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
commit
d98976679f
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
class HelperForm(forms.ModelForm):
|
class HelperForm(forms.ModelForm):
|
||||||
@ -33,3 +34,42 @@ class DeleteForm(forms.Form):
|
|||||||
fields = [
|
fields = [
|
||||||
'confirm_delete'
|
'confirm_delete'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EditUserForm(HelperForm):
|
||||||
|
""" Form for editing user information
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'email'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class SetPasswordForm(HelperForm):
|
||||||
|
""" Form for setting user password
|
||||||
|
"""
|
||||||
|
|
||||||
|
enter_password = forms.CharField(max_length=100,
|
||||||
|
min_length=8,
|
||||||
|
required=True,
|
||||||
|
initial='',
|
||||||
|
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
||||||
|
help_text='Enter new password')
|
||||||
|
|
||||||
|
confirm_password = forms.CharField(max_length=100,
|
||||||
|
min_length=8,
|
||||||
|
required=True,
|
||||||
|
initial='',
|
||||||
|
widget=forms.PasswordInput(attrs={'autocomplete': 'off'}),
|
||||||
|
help_text='Confirm new password')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = [
|
||||||
|
'enter_password',
|
||||||
|
'confirm_password'
|
||||||
|
]
|
||||||
|
@ -30,7 +30,7 @@ from django.conf.urls.static import static
|
|||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
from rest_framework.documentation import include_docs_urls
|
from rest_framework.documentation import include_docs_urls
|
||||||
|
|
||||||
from .views import IndexView, SearchView
|
from .views import IndexView, SearchView, SettingsView, EditUserView, SetPasswordView
|
||||||
|
|
||||||
from users.urls import user_urls
|
from users.urls import user_urls
|
||||||
|
|
||||||
@ -61,6 +61,11 @@ urlpatterns = [
|
|||||||
|
|
||||||
url(r'^login/', auth_views.LoginView.as_view(), name='login'),
|
url(r'^login/', auth_views.LoginView.as_view(), name='login'),
|
||||||
url(r'^logout/', auth_views.LogoutView.as_view(template_name='registration/logout.html'), name='logout'),
|
url(r'^logout/', auth_views.LogoutView.as_view(template_name='registration/logout.html'), name='logout'),
|
||||||
|
|
||||||
|
url(r'^settings/', SettingsView.as_view(), name='settings'),
|
||||||
|
|
||||||
|
url(r'^edit-user/', EditUserView.as_view(), name='edit-user'),
|
||||||
|
url(r'^set-password/', SetPasswordView.as_view(), name='set-password'),
|
||||||
|
|
||||||
url(r'^admin/', admin.site.urls, name='inventree-admin'),
|
url(r'^admin/', admin.site.urls, name='inventree-admin'),
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from django.views.generic.base import TemplateView
|
|||||||
|
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
|
||||||
from .forms import DeleteForm
|
from .forms import DeleteForm, EditUserForm, SetPasswordForm
|
||||||
from .helpers import str2bool
|
from .helpers import str2bool
|
||||||
|
|
||||||
from rest_framework import views
|
from rest_framework import views
|
||||||
@ -371,6 +371,59 @@ class AjaxDeleteView(AjaxMixin, UpdateView):
|
|||||||
return self.renderJsonResponse(request, form, data=data, context=context)
|
return self.renderJsonResponse(request, form, data=data, context=context)
|
||||||
|
|
||||||
|
|
||||||
|
class EditUserView(AjaxUpdateView):
|
||||||
|
""" View for editing user information """
|
||||||
|
|
||||||
|
ajax_template_name = "modal_form.html"
|
||||||
|
ajax_form_title = "Edit User Information"
|
||||||
|
form_class = EditUserForm
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
return self.request.user
|
||||||
|
|
||||||
|
|
||||||
|
class SetPasswordView(AjaxUpdateView):
|
||||||
|
""" View for setting user password """
|
||||||
|
|
||||||
|
ajax_template_name = "InvenTree/password.html"
|
||||||
|
ajax_form_title = "Set Password"
|
||||||
|
form_class = SetPasswordForm
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
return self.request.user
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
form = self.get_form()
|
||||||
|
|
||||||
|
valid = form.is_valid()
|
||||||
|
|
||||||
|
p1 = request.POST.get('enter_password', '')
|
||||||
|
p2 = request.POST.get('confirm_password', '')
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
# Passwords must match
|
||||||
|
|
||||||
|
if not p1 == p2:
|
||||||
|
error = 'Password fields must match'
|
||||||
|
form.errors['enter_password'] = [error]
|
||||||
|
form.errors['confirm_password'] = [error]
|
||||||
|
|
||||||
|
valid = False
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': valid
|
||||||
|
}
|
||||||
|
|
||||||
|
if valid:
|
||||||
|
user = self.request.user
|
||||||
|
|
||||||
|
user.set_password(p1)
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, form, data=data)
|
||||||
|
|
||||||
|
|
||||||
class IndexView(TemplateView):
|
class IndexView(TemplateView):
|
||||||
""" View for InvenTree index page """
|
""" View for InvenTree index page """
|
||||||
|
|
||||||
@ -414,3 +467,10 @@ class SearchView(TemplateView):
|
|||||||
context['query'] = query
|
context['query'] = query
|
||||||
|
|
||||||
return super(TemplateView, self).render_to_response(context)
|
return super(TemplateView, self).render_to_response(context)
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsView(TemplateView):
|
||||||
|
""" View for configuring User settings
|
||||||
|
"""
|
||||||
|
|
||||||
|
template_name = "InvenTree/settings.html"
|
||||||
|
7
InvenTree/templates/InvenTree/password.html
Normal file
7
InvenTree/templates/InvenTree/password.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{% extends "modal_form.html" %}
|
||||||
|
|
||||||
|
{% block pre_form_content %}
|
||||||
|
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
{% endblock %}
|
66
InvenTree/templates/InvenTree/settings.html
Normal file
66
InvenTree/templates/InvenTree/settings.html
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block page_title %}
|
||||||
|
InvenTree | Settings
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>InvenTree Settings</h3>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class='row'>
|
||||||
|
<div class='col-sm-6'>
|
||||||
|
<h4>User Information</h4>
|
||||||
|
</div>
|
||||||
|
<div class='col-sm-6'>
|
||||||
|
<div class='btn-group' style='float: right;'>
|
||||||
|
<div class='btn btn-primary' type='button' id='edit-user' title='Edit User Information'>Edit</div>
|
||||||
|
<div class='btn btn-primary' type='button' id='edit-password' title='Change Password'>Set Password</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<table class='table table-striped table-condensed'>
|
||||||
|
<tr>
|
||||||
|
<td>First Name</td>
|
||||||
|
<td>{{ user.first_name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Last Name</td>
|
||||||
|
<td>{{ user.last_name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Email Address</td>
|
||||||
|
<td>{{ user.email }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js_load %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js_ready %}
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
$("#edit-user").on('click', function() {
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'edit-user' %}",
|
||||||
|
{
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#edit-password").on('click', function() {
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'set-password' %}",
|
||||||
|
{
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -19,7 +19,9 @@
|
|||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<li><a href="/admin/"><span class="glyphicon glyphicon-edit"></span> Admin</a></li>
|
<li><a href="/admin/"><span class="glyphicon glyphicon-edit"></span> Admin</a></li>
|
||||||
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<li><a href="{% url 'settings' %}"><span class="glyphicon glyphicon-cog"></span> Settings</a></li>
|
||||||
<li><a href="{% url 'logout' %}"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
|
<li><a href="{% url 'logout' %}"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{% url 'login' %}"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
|
<li><a href="{% url 'login' %}"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user