diff --git a/seahub/profile/templates/profile/set_profile.html b/seahub/profile/templates/profile/set_profile.html index 526cf49834..85f25e73b1 100644 --- a/seahub/profile/templates/profile/set_profile.html +++ b/seahub/profile/templates/profile/set_profile.html @@ -31,6 +31,10 @@
  • {% trans "Two-Factor Authentication" %}
  • {% endif %} + {% if enable_wechat_work %} +
  • {% trans "Social Login" %}
  • + {% endif %} + {% if ENABLE_DELETE_ACCOUNT %}
  • {% trans "Delete Account" %}
  • {% endif %} @@ -175,11 +179,10 @@ {% endif %} +{% if enable_wechat_work %}

    {% trans "Social Login" %}

    - -
    +{% endif %} {% if ENABLE_DELETE_ACCOUNT %}
    diff --git a/seahub/profile/views.py b/seahub/profile/views.py index ea3b163e42..2c3773b6ef 100644 --- a/seahub/profile/views.py +++ b/seahub/profile/views.py @@ -90,6 +90,8 @@ def edit_profile(request): social_connected = UserSocialAuth.objects.filter( username=request.user.username, provider='weixin-work').count() > 0 + enable_wechat_work = True if settings.SOCIAL_AUTH_WEIXIN_WORK_KEY else False + resp_dict = { 'form': form, 'server_crypto': server_crypto, @@ -108,6 +110,7 @@ def edit_profile(request): 'email_notification_interval': email_inverval, 'social_connected': social_connected, 'social_next_page': reverse('edit_profile'), + 'enable_wechat_work': enable_wechat_work, } if has_two_factor_auth(): diff --git a/seahub/settings.py b/seahub/settings.py index 4e513f00ad..070c665668 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -277,14 +277,10 @@ AUTHENTICATION_BACKENDS = ( SOCIAL_AUTH_URL_NAMESPACE = 'social' SOCIAL_AUTH_VERIFY_SSL = True -SOCIAL_AUTH_METHODS = ( - ('weixin', 'WeChat'), -) - +SOCIAL_AUTH_LOGIN_ERROR_URL = '/profile/' SOCIAL_AUTH_WEIXIN_WORK_AGENTID = '' SOCIAL_AUTH_WEIXIN_WORK_KEY = '' SOCIAL_AUTH_WEIXIN_WORK_SECRET = '' - SOCIAL_AUTH_PIPELINE = ( 'social_core.pipeline.social_auth.social_details', 'social_core.pipeline.social_auth.social_uid', diff --git a/seahub/social_core/backends/weixin_enterprise.py b/seahub/social_core/backends/weixin_enterprise.py index 53ea054aab..69bb05e0c0 100644 --- a/seahub/social_core/backends/weixin_enterprise.py +++ b/seahub/social_core/backends/weixin_enterprise.py @@ -20,7 +20,7 @@ if WEIXIN_WORK_SP is True: _USER_INFO_URL = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info' else: _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' diff --git a/thirdpart/social_django/middleware.py b/thirdpart/social_django/middleware.py index fd0adc4be5..6d5d7f572d 100644 --- a/thirdpart/social_django/middleware.py +++ b/thirdpart/social_django/middleware.py @@ -5,7 +5,6 @@ from django.apps import apps from django.conf import settings from django.contrib import messages from django.contrib.messages.api import MessageFailure -from django.core.urlresolvers import reverse from django.shortcuts import redirect from django.utils.http import urlquote @@ -52,8 +51,6 @@ class SocialAuthExceptionMiddleware(MiddlewareMixin): if url: return redirect(url) - else: - return redirect(reverse('edit_profile')) def raise_exception(self, request, exception): strategy = getattr(request, 'social_strategy', None) diff --git a/thirdpart/social_django/migrations/0002_auto_20181115_0825.py b/thirdpart/social_django/migrations/0002_auto_20181115_0825.py deleted file mode 100644 index 48d76a3d93..0000000000 --- a/thirdpart/social_django/migrations/0002_auto_20181115_0825.py +++ /dev/null @@ -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), - ), - ] diff --git a/thirdpart/social_django/models.py b/thirdpart/social_django/models.py index 15f11e6a6b..1b420d3362 100644 --- a/thirdpart/social_django/models.py +++ b/thirdpart/social_django/models.py @@ -19,7 +19,7 @@ from .managers import UserSocialAuthManager USER_MODEL = getattr(settings, setting_name('USER_MODEL'), None) or \ getattr(settings, 'AUTH_USER_MODEL', None) or \ '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) NONCE_SERVER_URL_LENGTH = getattr( settings, setting_name('NONCE_SERVER_URL_LENGTH'), 255) @@ -148,3 +148,12 @@ class DjangoStorage(BaseDjangoStorage): @classmethod def is_integrity_error(cls, exception): 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() diff --git a/thirdpart/social_django/storage.py b/thirdpart/social_django/storage.py index 60d68fe5df..139c6f8243 100644 --- a/thirdpart/social_django/storage.py +++ b/thirdpart/social_django/storage.py @@ -74,8 +74,7 @@ class DjangoUserMixin(UserMixin): assert 'username' in kwargs user = User.objects.create_user(email=kwargs['username'], - is_active=True, - save_profile=False) + is_active=True) # try: # if hasattr(transaction, 'atomic'):