mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 05:39:59 +00:00
Enable add user in web and remove bind key id in registration form
This commit is contained in:
@@ -106,7 +106,8 @@ class RegistrationBackend(object):
|
||||
else:
|
||||
site = RequestSite(request)
|
||||
new_user = RegistrationProfile.objects.create_inactive_user(username, email,
|
||||
password, site)
|
||||
password, site,
|
||||
send_email=settings.REGISTRATION_SEND_MAIL)
|
||||
|
||||
userid = kwargs['userid']
|
||||
if userid:
|
||||
@@ -215,7 +216,7 @@ class RegistrationForm(forms.Form):
|
||||
except User.DoesNotExist:
|
||||
return self.cleaned_data['email']
|
||||
|
||||
raise forms.ValidationError(_("A user with this email alread"))
|
||||
raise forms.ValidationError(_("A user with this email already"))
|
||||
|
||||
def clean_userid(self):
|
||||
if self.cleaned_data['userid'] and len(self.cleaned_data['userid']) != 40:
|
||||
|
33
forms.py
Normal file
33
forms.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class AddUserForm(forms.Form):
|
||||
"""
|
||||
Form for adding a user.
|
||||
"""
|
||||
|
||||
email = forms.EmailField()
|
||||
password1 = forms.CharField(widget=forms.PasswordInput())
|
||||
password2 = forms.CharField(widget=forms.PasswordInput())
|
||||
|
||||
def clean_email(self):
|
||||
try:
|
||||
user = User.objects.get(email__iexact=self.cleaned_data['email'])
|
||||
except User.DoesNotExist:
|
||||
return self.cleaned_data['email']
|
||||
|
||||
raise forms.ValidationError(_("A user with this email already"))
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
Verifiy that the values entered into the two password fields
|
||||
match. Note that an error here will end up in
|
||||
``non_field_errors()`` because it doesn't apply to a single
|
||||
field.
|
||||
|
||||
"""
|
||||
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
|
||||
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
|
||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||
return self.cleaned_data
|
@@ -149,5 +149,5 @@ div.home-page h2 { font-style: italic; }
|
||||
#id_repo_id { width:300px; }
|
||||
|
||||
span.small-action-link { font-size: 9px; }
|
||||
input.ccnet_id { width: 300px; }
|
||||
input.ccnet_id { width: 400px; }
|
||||
.notification { background:#FDF; width:580px; margin:10px 0; border:1px solid #faf; padding-left:2px; }
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
{% block left_panel %}
|
||||
<ul>
|
||||
<li><a href="{% url profile_setting %}">绑定 Ccnet 公钥 ID</a></li>
|
||||
<li><a href="{% url profile_setting %}">绑定 Seafile 公钥 ID</a></li>
|
||||
<li><a href="{{ SITE_ROOT }}accounts/password/change/">修改网站帐号密码</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
@@ -12,7 +12,7 @@
|
||||
{% block right_panel %}
|
||||
|
||||
<h3>当前设置</h3>
|
||||
<p>Ccnet 公钥 ID: {{ profile.ccnet_user_id }}</p>
|
||||
<p>Seafile 公钥 ID: {{ profile.ccnet_user_id }}</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<p class="error">{{ error_msg }}</p>
|
||||
{% endif %}
|
||||
<label>公钥 ID:</label><br/>
|
||||
<input id="id_ccnet_user_id" class="ccnet_id" type="text" name="ccnet_user_id" value="{{ origin_id }}" maxlength="40" /><br/>
|
||||
<input id="id_ccnet_user_id" class="ccnet_id" type="text" name="ccnet_user_id" value="{{ origin_id }}" /><br/>
|
||||
<input type="submit" value="提交" />
|
||||
</form>
|
||||
|
||||
|
@@ -28,12 +28,12 @@ def set_profile(request):
|
||||
error_msg = None
|
||||
origin_id = None
|
||||
if request.method == 'POST':
|
||||
ccnet_user_id = request.POST.get('ccnet_user_id', None)
|
||||
ccnet_user_id = request.POST.get('ccnet_user_id', '').strip()
|
||||
origin_id = ccnet_user_id
|
||||
if not ccnet_user_id:
|
||||
error_msg = "You must specify ccnet user id"
|
||||
error_msg = "You must specify Key ID"
|
||||
elif len(ccnet_user_id) != 40:
|
||||
error_msg = "Ccnet User ID must be of length 40"
|
||||
error_msg = "Key ID must be of length 40"
|
||||
else:
|
||||
try:
|
||||
profile = request.user.get_profile()
|
||||
@@ -42,7 +42,7 @@ def set_profile(request):
|
||||
profile.save()
|
||||
try:
|
||||
ccnet_rpc.add_client(ccnet_user_id)
|
||||
except:
|
||||
except Exception, e:
|
||||
error_msg = "Ccnet Deamon is not available, try again later"
|
||||
else:
|
||||
profile.ccnet_user_id = ccnet_user_id
|
||||
|
@@ -114,6 +114,7 @@ AUTHENTICATION_BACKENDS = (
|
||||
|
||||
ACCOUNT_ACTIVATION_DAYS = 7
|
||||
|
||||
REGISTRATION_SEND_MAIL = True
|
||||
|
||||
try:
|
||||
import local_settings
|
||||
|
21
templates/add_user_form.html
Normal file
21
templates/add_user_form.html
Normal file
@@ -0,0 +1,21 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
{% block title %}添加用户{% endblock %}
|
||||
{% block main_panel %}
|
||||
<h2>添加用户</h2>
|
||||
<form action="" method="post" class="reg">
|
||||
<label for="id_email">邮箱:</label>
|
||||
{{ form.email }}
|
||||
{% if form.email.errors %}
|
||||
{{ form.email.errors }}
|
||||
{% endif %}<br />
|
||||
<label for="id_password1">密码:</label>
|
||||
{{ form.password1 }}
|
||||
{% if form.password1.errors %}
|
||||
{{ form.password1.errors }}
|
||||
{% endif %}<br />
|
||||
<label for="id_password2">确认密码:</label>
|
||||
{{ form.password2 }}<br />
|
||||
<input type="submit" value="提交" class="submit" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@@ -3,11 +3,6 @@
|
||||
{% block main_panel %}
|
||||
<h2>用户注册</h2>
|
||||
<form action="" method="post" class="reg">
|
||||
<label for="id_username">公钥 ID:</label>
|
||||
{{ form.userid }} (可以以后再绑定)
|
||||
{% if form.userid.errors %}
|
||||
{{ form.userid.errors }}
|
||||
{% endif %}<br />
|
||||
<label for="id_email">邮箱:</label>
|
||||
{{ form.email }}<span>(我们将给您发送帐号激活邮件.)</span>
|
||||
{% if form.email.errors %}
|
||||
|
@@ -1,5 +1,13 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
|
||||
|
||||
{% block left_panel %}
|
||||
<ul>
|
||||
<li><a href="{{ SITE_ROOT }}useradmin/add/">添加用户</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block right_panel %}
|
||||
|
||||
<h2>所有用户</h2>
|
||||
@@ -7,7 +15,7 @@
|
||||
<tr>
|
||||
<th>邮件</th>
|
||||
<td>是否激活</td>
|
||||
<td>Ccnet ID</td>
|
||||
<td>公钥 ID</td>
|
||||
<td>角色</td>
|
||||
<td>操作</td>
|
||||
</tr>
|
||||
|
5
urls.py
5
urls.py
@@ -4,7 +4,7 @@ from django.views.generic.simple import direct_to_template
|
||||
|
||||
from seahub.views import root, peers, groups, myhome, \
|
||||
repo, group, modify_token, remove_repo, seafadmin, useradmin, \
|
||||
role_add, role_remove, activate_user
|
||||
role_add, role_remove, activate_user, user_add
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
@@ -31,7 +31,8 @@ urlpatterns = patterns('',
|
||||
(r'^repo/remove/(?P<repo_id>[^/]+)/$', remove_repo),
|
||||
|
||||
(r'^seafadmin/$', seafadmin),
|
||||
(r'^useradmin/$', useradmin),
|
||||
url(r'^useradmin/$', useradmin, name='useradmin'),
|
||||
(r'^useradmin/add/$', user_add),
|
||||
(r'^useradmin/(?P<user_id>[^/]+)/role/add/$', role_add),
|
||||
(r'^useradmin/(?P<user_id>[^/]+)/role/remove/$', role_remove),
|
||||
(r'^useradmin/activate/(?P<user_id>[^/]+)/$', activate_user),
|
||||
|
25
views.py
25
views.py
@@ -13,7 +13,7 @@ from seaserv import cclient, ccnet_rpc, get_groups, get_users, get_repos, \
|
||||
from seahub.profile.models import UserProfile
|
||||
from seahub.share.models import GroupShare, UserShare
|
||||
from seahub.share.forms import GroupAddRepoForm
|
||||
|
||||
from forms import AddUserForm
|
||||
|
||||
@login_required
|
||||
def root(request):
|
||||
@@ -242,3 +242,26 @@ def activate_user(request, user_id):
|
||||
return HttpResponseRedirect(request.META['HTTP_REFERER'])
|
||||
|
||||
|
||||
@login_required
|
||||
def user_add(request):
|
||||
"""Add a user"""
|
||||
|
||||
if not request.user.is_staff:
|
||||
raise Http404
|
||||
|
||||
if request.method == 'POST':
|
||||
form = AddUserForm(request.POST)
|
||||
if form.is_valid():
|
||||
email = form.cleaned_data['email']
|
||||
username = email
|
||||
password = form.cleaned_data['password1']
|
||||
new_user = User.objects.create_user(username, email, password)
|
||||
new_user.is_active = True
|
||||
new_user.save()
|
||||
return HttpResponseRedirect(reverse('useradmin', args=[]))
|
||||
else:
|
||||
form = AddUserForm()
|
||||
|
||||
return render_to_response("add_user_form.html", {
|
||||
'form': form,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
Reference in New Issue
Block a user