mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
[API] background image of login page
This commit is contained in:
59
seahub/api2/endpoints/admin/login_bg_image.py
Normal file
59
seahub/api2/endpoints/admin/login_bg_image.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||
import os
|
||||
import logging
|
||||
|
||||
from rest_framework.authentication import SessionAuthentication
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import status
|
||||
|
||||
from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.api2.utils import api_error
|
||||
from seahub.settings import SEAHUB_DATA_ROOT, MEDIA_ROOT
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CUSTOM_LOGIN_BG_IMAGE_PATH = 'custom/login-bg.jpg'
|
||||
|
||||
|
||||
class AdminLoginBgImage(APIView):
|
||||
|
||||
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||
throttle_classes = (UserRateThrottle, )
|
||||
permission_classes = (IsAdminUser,)
|
||||
|
||||
def post(self, request):
|
||||
image_file = request.FILES.get('login_bg_image', None)
|
||||
if not image_file:
|
||||
error_msg = 'background image invalid'
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
if not os.path.exists(SEAHUB_DATA_ROOT):
|
||||
os.makedirs(SEAHUB_DATA_ROOT)
|
||||
|
||||
custom_dir = os.path.join(SEAHUB_DATA_ROOT,
|
||||
os.path.dirname(CUSTOM_LOGIN_BG_IMAGE_PATH))
|
||||
if not os.path.exists(custom_dir):
|
||||
os.makedirs(custom_dir)
|
||||
|
||||
try:
|
||||
custom_login_bg_image_file = os.path.join(SEAHUB_DATA_ROOT,
|
||||
CUSTOM_LOGIN_BG_IMAGE_PATH)
|
||||
# save login background image file to custom dir
|
||||
with open(custom_login_bg_image_file, 'w') as fd:
|
||||
fd.write(image_file.read())
|
||||
|
||||
custom_symlink = os.path.join(MEDIA_ROOT,
|
||||
os.path.dirname(CUSTOM_LOGIN_BG_IMAGE_PATH))
|
||||
# create symlink for custom dir
|
||||
if not os.path.exists(custom_symlink):
|
||||
os.symlink(custom_dir, custom_symlink)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
return Response({'success': True})
|
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from datetime import datetime
|
||||
@@ -32,6 +33,8 @@ from seahub.utils.ip import get_remote_ip
|
||||
from seahub.utils.file_size import get_quota_from_string
|
||||
from seahub.utils.two_factor_auth import two_factor_auth_enabled, handle_two_factor_auth
|
||||
from seahub.utils.user_permissions import get_user_role
|
||||
from seahub.settings import LOGIN_BG_IMAGE_PATH, MEDIA_ROOT
|
||||
from seahub.api2.endpoints.admin.login_bg_image import CUSTOM_LOGIN_BG_IMAGE_PATH
|
||||
|
||||
from constance import config
|
||||
|
||||
@@ -242,6 +245,12 @@ def login(request, template_name='registration/login.html',
|
||||
enable_krb5_login = getattr(settings, 'ENABLE_KRB5_LOGIN', False)
|
||||
enable_adfs_login = getattr(settings, 'ENABLE_ADFS_LOGIN', False)
|
||||
|
||||
login_bg_image_path = LOGIN_BG_IMAGE_PATH
|
||||
# get path that background image of login page
|
||||
custom_login_bg_image_file = os.path.join(MEDIA_ROOT, CUSTOM_LOGIN_BG_IMAGE_PATH)
|
||||
if os.path.exists(custom_login_bg_image_file):
|
||||
login_bg_image_path = CUSTOM_LOGIN_BG_IMAGE_PATH
|
||||
|
||||
return render_to_response(template_name, {
|
||||
'form': form,
|
||||
redirect_field_name: redirect_to,
|
||||
@@ -252,6 +261,7 @@ def login(request, template_name='registration/login.html',
|
||||
'enable_shib_login': enable_shib_login,
|
||||
'enable_krb5_login': enable_krb5_login,
|
||||
'enable_adfs_login': enable_adfs_login,
|
||||
'login_bg_image_path': login_bg_image_path,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
def login_simple_check(request):
|
||||
|
@@ -422,6 +422,9 @@ SITE_NAME = 'Seafile'
|
||||
# Path to the license file(relative to the media path)
|
||||
LICENSE_PATH = os.path.join(PROJECT_ROOT, '../../seafile-license.txt')
|
||||
|
||||
# Path to the background image file of login page(relative to the media path)
|
||||
LOGIN_BG_IMAGE_PATH = 'img/login-bg.jpg'
|
||||
|
||||
# Path to the favicon file (relative to the media path)
|
||||
# tip: use a different name when modify it.
|
||||
FAVICON_PATH = 'img/favicon.ico'
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<style type="text/css">
|
||||
html, body, #wrapper { height:100%; }
|
||||
#wrapper {
|
||||
background: url('{{ MEDIA_URL }}img/login-bg.jpg') center top no-repeat scroll;
|
||||
background: url('{{ MEDIA_URL }}{{login_bg_image_path}}') center top no-repeat scroll;
|
||||
background-size: cover;
|
||||
padding-top:1px;
|
||||
}
|
||||
|
@@ -33,6 +33,10 @@
|
||||
{% include "snippets/web_settings_form.html" %}
|
||||
{% endwith %}
|
||||
|
||||
{% with type="file" setting_display_name="Login_Background_Image" setting_name="login_bg_image" file_path=login_bg_image_path file_width=256 file_height=256 help_tip="login-bg.jpg, 1920px * 1080px" %}
|
||||
{% include "snippets/web_settings_form.html" %}
|
||||
{% endwith %}
|
||||
|
||||
<h4>{% trans "User" %}</h4>
|
||||
|
||||
{% with type="checkbox" setting_name="ENABLE_SIGNUP" setting_val=config_dict.ENABLE_SIGNUP %}
|
||||
@@ -277,6 +281,7 @@ $('.web-setting-file-upload-input').change(function() {
|
||||
switch(input_name) {
|
||||
case 'logo': url = '{% url 'api-v2.1-admin-logo' %}'; break;
|
||||
case 'favicon': url = '{% url 'api-v2.1-admin-favicon' %}'; break;
|
||||
case 'login_bg_image': url = '{% url 'api-v2.1-admin-login-background-image' %}'; break;
|
||||
}
|
||||
|
||||
fd.append(input_name, file);
|
||||
|
@@ -85,6 +85,7 @@ from seahub.api2.endpoints.admin.favicon import AdminFavicon
|
||||
from seahub.api2.endpoints.admin.license import AdminLicense
|
||||
from seahub.api2.endpoints.admin.invitations import InvitationsView as AdminInvitationsView
|
||||
from seahub.api2.endpoints.admin.library_history import AdminLibraryHistoryLimit
|
||||
from seahub.api2.endpoints.admin.login_bg_image import AdminLoginBgImage
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
#from django.contrib import admin
|
||||
@@ -336,6 +337,7 @@ urlpatterns = patterns(
|
||||
url(r'^api/v2.1/admin/logo/$', AdminLogo.as_view(), name='api-v2.1-admin-logo'),
|
||||
url(r'^api/v2.1/admin/favicon/$', AdminFavicon.as_view(), name='api-v2.1-admin-favicon'),
|
||||
url(r'^api/v2.1/admin/license/$', AdminLicense.as_view(), name='api-v2.1-admin-license'),
|
||||
url(r'^api/v2.1/admin/login-background-image/$', AdminLoginBgImage.as_view(), name='api-v2.1-admin-login-background-image'),
|
||||
|
||||
## admin::invitations
|
||||
url(r'^api/v2.1/admin/invitations/$', AdminInvitationsView.as_view(), name='api-v2.1-admin-invitations'),
|
||||
|
@@ -65,7 +65,9 @@ from seahub.admin_log.models import USER_DELETE, USER_ADD
|
||||
import seahub.settings as settings
|
||||
from seahub.settings import INIT_PASSWD, SITE_NAME, SITE_ROOT, \
|
||||
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, SEND_EMAIL_ON_RESETTING_USER_PASSWD, \
|
||||
ENABLE_SYS_ADMIN_VIEW_REPO, ENABLE_GUEST_INVITATION
|
||||
ENABLE_SYS_ADMIN_VIEW_REPO, ENABLE_GUEST_INVITATION, LOGIN_BG_IMAGE_PATH, \
|
||||
MEDIA_ROOT
|
||||
from seahub.api2.endpoints.admin.login_bg_image import CUSTOM_LOGIN_BG_IMAGE_PATH
|
||||
try:
|
||||
from seahub.settings import ENABLE_TRIAL_ACCOUNT
|
||||
except:
|
||||
@@ -2071,8 +2073,15 @@ def sys_settings(request):
|
||||
value = getattr(config, key)
|
||||
config_dict[key] = value
|
||||
|
||||
login_bg_image_path = LOGIN_BG_IMAGE_PATH
|
||||
# get path that background image of login page
|
||||
custom_login_bg_image_file = os.path.join(MEDIA_ROOT, CUSTOM_LOGIN_BG_IMAGE_PATH)
|
||||
if os.path.exists(custom_login_bg_image_file):
|
||||
login_bg_image_path = CUSTOM_LOGIN_BG_IMAGE_PATH
|
||||
|
||||
return render_to_response('sysadmin/settings.html', {
|
||||
'config_dict': config_dict,
|
||||
'login_bg_image_path': login_bg_image_path,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required_ajax
|
||||
|
Reference in New Issue
Block a user