Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

huifenqi sso login support #1

Merged
merged 2 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/schema/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
from models import Column


TEMPLATE = """
{% if record.is_deleted %}<span class="ui red label">Deleted</span>{% endif %}
{% if record.is_comment_dirty %}<span class="ui yellow label">Not Match</span>{% endif %}
"""


class ColumnTable(tables.Table):
table_comment = tables.TemplateColumn('{{ value|linebreaks }}', verbose_name='Table Comment',
accessor='table.comment')
comment = tables.TemplateColumn('{{ value|linebreaks }}')
warning_info = tables.TemplateColumn(TEMPLATE, verbose_name='Warning', orderable=False)

class Meta:
model = Column
sequence = ('name', 'table', 'data_type', 'is_null', 'default_value', 'comment', 'table_comment')
sequence = ('name', 'table', 'data_type', 'is_null', 'default_value', 'comment', 'table_comment',
'warning_info')
template_name = "django_tables2/semantic.html"
exclude = ("id",)
exclude = ("id", "is_comment_dirty", "is_enum", "is_deleted")
16 changes: 16 additions & 0 deletions dbhub/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
'django_extensions',
"django_tables2",
"django_filters",
"oauthadmin",
'apps.schema',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'oauthadmin.middleware.OauthAdminSessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -110,3 +112,17 @@

TITLE = '[DEMO] database dbhub schema'
DB_INSTANCES = []

# django-admin-oauth2
SESSION_SERIALIZER = "django.contrib.sessions.serializers.PickleSerializer"

OAUTHADMIN_CLIENT_ID = ''
OAUTHADMIN_CLIENT_SECRET = ''
OAUTHADMIN_BASE_URL = "https://sso.huifenqi.com/sso/oauth/"
OAUTHADMIN_AUTH_URL = 'https://sso.huifenqi.com/sso/authorize/'
OAUTHADMIN_TOKEN_URL = 'https://sso.huifenqi.com/sso/token/'
OAUTHADMIN_GROUPS = ['editor']
OAUTHADMIN_SCOPE = []

# replace admin login with oauth login
ENABLE_OAUTH = False
3 changes: 3 additions & 0 deletions dbhub/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

TITLE = '会分期数据库定义'
DEBUG = False
ENABLE_OAUTH = True
OAUTHADMIN_CLIENT_ID = ''
OAUTHADMIN_CLIENT_SECRET = ''
18 changes: 16 additions & 2 deletions dbhub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@
"""
from django.conf.urls import include, url
from django.contrib import admin

from django.contrib.auth.decorators import login_required
from django.conf import settings
from apps.schema.views import ColumnListView

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r"^$", ColumnListView.as_view(), name="index"),
]

if settings.ENABLE_OAUTH:
old_admin_login = admin.site.login
admin.site.login = login_required(admin.site.login)
urlpatterns += [
url(r'^admin-login/', old_admin_login),
url(r'^oauth/', include('oauthadmin.urls')),
]
settings.LOGIN_URL = '/oauth/login/'
settings.LOGOUT_REDIRECT_URL = '/oauth/logout_redirect/'

urlpatterns += [
url(r'^admin/', include(admin.site.urls)),
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ django-tables2==1.21.2
MySQL-python==1.2.5
uwsgi==2.0.17.1
git+ssh://[email protected]/huifenqi/[email protected]
git+ssh://[email protected]/bastionhost/django-admin-oauth2.git
6 changes: 6 additions & 0 deletions templates/columns.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h1 id="title">{{ title }}</h1>
<button class="ui green button" type="submit">Search</button>
</div>
</form>
<h3 id="login"><a href="/admin-login/">登录</a>&nbsp;/&nbsp;<a href="/oauth/login/">SSO 登录</a></h3>
{% render_table table %}
&nbsp;
{% endblock %}
Expand All @@ -30,6 +31,11 @@ <h1 id="title">{{ title }}</h1>
margin-top: 10px;
}

#login {
margin-top: 10px;
float: right;
}

#id_word {
margin-bottom: 10px;
}
Expand Down