mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-21 08:25:21 +00:00
Update social_django and profile
This commit is contained in:
parent
0efcbb10a3
commit
fd21d7838e
@ -31,6 +31,10 @@
|
|||||||
<li class="tab"><a href="#two-factor-auth">{% trans "Two-Factor Authentication" %}</a></li>
|
<li class="tab"><a href="#two-factor-auth">{% trans "Two-Factor Authentication" %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_wechat_work %}
|
||||||
|
<li class="tab"><a href="#social-auth">{% trans "Social Login" %}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if ENABLE_DELETE_ACCOUNT %}
|
{% if ENABLE_DELETE_ACCOUNT %}
|
||||||
<li class="tab" id="del-account-nav"><a href="#del-account">{% trans "Delete Account" %}</a></li>
|
<li class="tab" id="del-account-nav"><a href="#del-account">{% trans "Delete Account" %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -175,11 +179,10 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_wechat_work %}
|
||||||
<div class="setting-item" id="social-auth">
|
<div class="setting-item" id="social-auth">
|
||||||
<h3>{% trans "Social Login" %}</h3>
|
<h3>{% trans "Social Login" %}</h3>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
{% if request.LANGUAGE_CODE == 'zh-cn' %}
|
{% if request.LANGUAGE_CODE == 'zh-cn' %}
|
||||||
企业微信
|
企业微信
|
||||||
@ -193,10 +196,9 @@
|
|||||||
<a href="{% url "social:begin" 'weixin-work' %}?next={{ social_next_page }}">{% trans "Connect" %}</a>
|
<a href="{% url "social:begin" 'weixin-work' %}?next={{ social_next_page }}">{% trans "Connect" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if ENABLE_DELETE_ACCOUNT %}
|
{% if ENABLE_DELETE_ACCOUNT %}
|
||||||
<div class="setting-item" id="del-account">
|
<div class="setting-item" id="del-account">
|
||||||
|
@ -90,6 +90,8 @@ def edit_profile(request):
|
|||||||
social_connected = UserSocialAuth.objects.filter(
|
social_connected = UserSocialAuth.objects.filter(
|
||||||
username=request.user.username, provider='weixin-work').count() > 0
|
username=request.user.username, provider='weixin-work').count() > 0
|
||||||
|
|
||||||
|
enable_wechat_work = True if settings.SOCIAL_AUTH_WEIXIN_WORK_KEY else False
|
||||||
|
|
||||||
resp_dict = {
|
resp_dict = {
|
||||||
'form': form,
|
'form': form,
|
||||||
'server_crypto': server_crypto,
|
'server_crypto': server_crypto,
|
||||||
@ -108,6 +110,7 @@ def edit_profile(request):
|
|||||||
'email_notification_interval': email_inverval,
|
'email_notification_interval': email_inverval,
|
||||||
'social_connected': social_connected,
|
'social_connected': social_connected,
|
||||||
'social_next_page': reverse('edit_profile'),
|
'social_next_page': reverse('edit_profile'),
|
||||||
|
'enable_wechat_work': enable_wechat_work,
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_two_factor_auth():
|
if has_two_factor_auth():
|
||||||
|
@ -277,14 +277,10 @@ AUTHENTICATION_BACKENDS = (
|
|||||||
|
|
||||||
SOCIAL_AUTH_URL_NAMESPACE = 'social'
|
SOCIAL_AUTH_URL_NAMESPACE = 'social'
|
||||||
SOCIAL_AUTH_VERIFY_SSL = True
|
SOCIAL_AUTH_VERIFY_SSL = True
|
||||||
SOCIAL_AUTH_METHODS = (
|
SOCIAL_AUTH_LOGIN_ERROR_URL = '/profile/'
|
||||||
('weixin', 'WeChat'),
|
|
||||||
)
|
|
||||||
|
|
||||||
SOCIAL_AUTH_WEIXIN_WORK_AGENTID = ''
|
SOCIAL_AUTH_WEIXIN_WORK_AGENTID = ''
|
||||||
SOCIAL_AUTH_WEIXIN_WORK_KEY = ''
|
SOCIAL_AUTH_WEIXIN_WORK_KEY = ''
|
||||||
SOCIAL_AUTH_WEIXIN_WORK_SECRET = ''
|
SOCIAL_AUTH_WEIXIN_WORK_SECRET = ''
|
||||||
|
|
||||||
SOCIAL_AUTH_PIPELINE = (
|
SOCIAL_AUTH_PIPELINE = (
|
||||||
'social_core.pipeline.social_auth.social_details',
|
'social_core.pipeline.social_auth.social_details',
|
||||||
'social_core.pipeline.social_auth.social_uid',
|
'social_core.pipeline.social_auth.social_uid',
|
||||||
|
@ -20,7 +20,7 @@ if WEIXIN_WORK_SP is True:
|
|||||||
_USER_INFO_URL = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info'
|
_USER_INFO_URL = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info'
|
||||||
else:
|
else:
|
||||||
_AUTHORIZATION_URL = 'https://open.work.weixin.qq.com/wwopen/sso/qrConnect'
|
_AUTHORIZATION_URL = 'https://open.work.weixin.qq.com/wwopen/sso/qrConnect'
|
||||||
_ACCESS_TOKEN_URL = 'https://qyapi.weixin.qq.com/cgi-bin/token'
|
_ACCESS_TOKEN_URL = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
|
||||||
_USER_INFO_URL = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo'
|
_USER_INFO_URL = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo'
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ from django.apps import apps
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.messages.api import MessageFailure
|
from django.contrib.messages.api import MessageFailure
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.http import urlquote
|
from django.utils.http import urlquote
|
||||||
|
|
||||||
@ -52,8 +51,6 @@ class SocialAuthExceptionMiddleware(MiddlewareMixin):
|
|||||||
|
|
||||||
if url:
|
if url:
|
||||||
return redirect(url)
|
return redirect(url)
|
||||||
else:
|
|
||||||
return redirect(reverse('edit_profile'))
|
|
||||||
|
|
||||||
def raise_exception(self, request, exception):
|
def raise_exception(self, request, exception):
|
||||||
strategy = getattr(request, 'social_strategy', None)
|
strategy = getattr(request, 'social_strategy', None)
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Generated by Django 1.11.15 on 2018-11-15 08:25
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('social_django', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='usersocialauth',
|
|
||||||
name='uid',
|
|
||||||
field=models.CharField(max_length=150),
|
|
||||||
),
|
|
||||||
]
|
|
@ -19,7 +19,7 @@ from .managers import UserSocialAuthManager
|
|||||||
USER_MODEL = getattr(settings, setting_name('USER_MODEL'), None) or \
|
USER_MODEL = getattr(settings, setting_name('USER_MODEL'), None) or \
|
||||||
getattr(settings, 'AUTH_USER_MODEL', None) or \
|
getattr(settings, 'AUTH_USER_MODEL', None) or \
|
||||||
'auth.User'
|
'auth.User'
|
||||||
UID_LENGTH = getattr(settings, setting_name('UID_LENGTH'), 150)
|
UID_LENGTH = getattr(settings, setting_name('UID_LENGTH'), 255)
|
||||||
EMAIL_LENGTH = getattr(settings, setting_name('EMAIL_LENGTH'), 254)
|
EMAIL_LENGTH = getattr(settings, setting_name('EMAIL_LENGTH'), 254)
|
||||||
NONCE_SERVER_URL_LENGTH = getattr(
|
NONCE_SERVER_URL_LENGTH = getattr(
|
||||||
settings, setting_name('NONCE_SERVER_URL_LENGTH'), 255)
|
settings, setting_name('NONCE_SERVER_URL_LENGTH'), 255)
|
||||||
@ -148,3 +148,12 @@ class DjangoStorage(BaseDjangoStorage):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def is_integrity_error(cls, exception):
|
def is_integrity_error(cls, exception):
|
||||||
return exception.__class__ is IntegrityError
|
return exception.__class__ is IntegrityError
|
||||||
|
|
||||||
|
########## handle signals
|
||||||
|
from django.dispatch import receiver
|
||||||
|
from registration.signals import user_deleted
|
||||||
|
|
||||||
|
@receiver(user_deleted)
|
||||||
|
def user_deleted_cb(sender, **kwargs):
|
||||||
|
username = kwargs['username']
|
||||||
|
UserSocialAuth.objects.filter(username=username).delete()
|
||||||
|
@ -74,8 +74,7 @@ class DjangoUserMixin(UserMixin):
|
|||||||
assert 'username' in kwargs
|
assert 'username' in kwargs
|
||||||
|
|
||||||
user = User.objects.create_user(email=kwargs['username'],
|
user = User.objects.create_user(email=kwargs['username'],
|
||||||
is_active=True,
|
is_active=True)
|
||||||
save_profile=False)
|
|
||||||
|
|
||||||
# try:
|
# try:
|
||||||
# if hasattr(transaction, 'atomic'):
|
# if hasattr(transaction, 'atomic'):
|
||||||
|
Loading…
Reference in New Issue
Block a user