mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 15:19:06 +00:00
Add authentication and registration to seahub
This commit is contained in:
0
profile/__init__.py
Normal file
0
profile/__init__.py
Normal file
4
profile/admin.py
Normal file
4
profile/admin.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from profile.models import UserProfile
|
||||
|
||||
admin.site.register(UserProfile)
|
8
profile/forms.py
Normal file
8
profile/forms.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django import forms
|
||||
|
||||
class SetUserProfileForm(forms.Form):
|
||||
|
||||
status = forms.CharField(max_length=140, required=False)
|
||||
interests = forms.CharField(max_length=256, required=False)
|
||||
|
||||
#signature = forms.CharField()
|
8
profile/models.py
Normal file
8
profile/models.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.ForeignKey(User, unique=True)
|
||||
status = models.CharField(max_length=40, blank=True)
|
||||
|
41
profile/templates/profile/profile.html
Normal file
41
profile/templates/profile/profile.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% extends "profile/profile_base.html" %}
|
||||
|
||||
|
||||
{% block left_panel %}
|
||||
<ul>
|
||||
<li><a href="{% url profile_setting %}">修改资料</a></li>
|
||||
<li><a href="{% url avatar_change %}">修改头像</a></li>
|
||||
<li><a href="{% url avatar_delete %}">删除不用的头像</a></li>
|
||||
<li><a href="{{ SITE_ROOT }}accounts/password/change/">修改密码</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block right_panel %}
|
||||
|
||||
<h3>当前头像</h3>
|
||||
{% load avatar_tags %}
|
||||
{% avatar user 90 %}
|
||||
|
||||
<h3>基本信息</h3>
|
||||
<p>当前状态:{{ user.get_profile.status }}</p>
|
||||
<p>我的兴趣:{{ user.get_profile.interests }}</p>
|
||||
|
||||
{% if peer %}
|
||||
<h3>Ccnet 当前设置</h3>
|
||||
<p>Ccnet ID: {{ peer.peer_id }}</p>
|
||||
<p>Ccnet Name: {{ peer.name }}</p>
|
||||
{% endif %}
|
||||
|
||||
{% if groups %}
|
||||
<h3>加入的组</h3>
|
||||
<div id="ccnet-groups">
|
||||
<ul>
|
||||
{% for group in groups %}
|
||||
<li>{{ group.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
7
profile/templates/profile/profile_base.html
Normal file
7
profile/templates/profile/profile_base.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% extends "myhome_base.html" %}
|
||||
|
||||
{% block title %}帐号设置{% endblock %}
|
||||
|
||||
{% block subnav %}
|
||||
|
||||
{% endblock %}
|
20
profile/templates/profile/set_profile.html
Normal file
20
profile/templates/profile/set_profile.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{% extends "profile/profile_base.html" %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form action="" method="post">
|
||||
<labeld>当前状态:</label><br/>
|
||||
{{ profile_form.status }}
|
||||
{% if profile_form.status.errors %}
|
||||
{{ profile_form.status.errors }}
|
||||
{% endif %}<br />
|
||||
<label for="id_message">兴趣:</label><br />
|
||||
{{ profile_form.interests }}<br />
|
||||
{% if profile_form.interests.errors %}
|
||||
{{ profile_form.interests.errors }}
|
||||
{% endif %}<br />
|
||||
<input type="submit" value="更新个人资料" />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
23
profile/tests.py
Normal file
23
profile/tests.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
This file demonstrates two different styles of tests (one doctest and one
|
||||
unittest). These will both pass when you run "manage.py test".
|
||||
|
||||
Replace these with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.failUnlessEqual(1 + 1, 2)
|
||||
|
||||
__test__ = {"doctest": """
|
||||
Another way to test that 1 + 1 is equal to 2.
|
||||
|
||||
>>> 1 + 1 == 2
|
||||
True
|
||||
"""}
|
||||
|
6
profile/urls.py
Normal file
6
profile/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('profile.views',
|
||||
url(r'^$', 'show_profile'),
|
||||
url(r'^edit/$', 'set_profile', name="profile_setting"),
|
||||
)
|
47
profile/views.py
Normal file
47
profile/views.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context, RequestContext
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
import datetime
|
||||
|
||||
from forms import SetUserProfileForm
|
||||
from models import UserProfile
|
||||
|
||||
|
||||
@login_required
|
||||
def show_profile(request):
|
||||
groups = []
|
||||
return render_to_response('profile/profile.html',
|
||||
{ 'groups': groups, },
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@login_required
|
||||
def set_profile(request):
|
||||
if request.method == 'POST':
|
||||
form = SetUserProfileForm(request.POST)
|
||||
if form.is_valid():
|
||||
try:
|
||||
profile = request.user.get_profile()
|
||||
except UserProfile.DoesNotExist:
|
||||
profile = UserProfile(user=request.user)
|
||||
profile.save() # save the profile first, otherwise
|
||||
# status.save() would fail.
|
||||
|
||||
profile.save()
|
||||
return HttpResponseRedirect(reverse(show_profile))
|
||||
else:
|
||||
try:
|
||||
profile = request.user.get_profile()
|
||||
except UserProfile.DoesNotExist:
|
||||
profile = UserProfile(user=request.user)
|
||||
|
||||
profile_form = SetUserProfileForm(profile.__dict__)
|
||||
|
||||
return render_to_response('profile/set_profile.html',
|
||||
{ 'profile_form': profile_form, },
|
||||
context_instance=RequestContext(request))
|
||||
|
Reference in New Issue
Block a user