def sysadmin_react_fake_view(request, **kwargs): try: expire_days = seafile_api.get_server_config_int('library_trash', 'expire_days') except Exception as e: logger.error(e) expire_days = -1 multi_institution = getattr(dj_settings, 'MULTI_INSTITUTION', False) institutions = None if multi_institution: institutions = [inst.name for inst in Institution.objects.all()] return render(request, 'sysadmin/sysadmin_react_app.html', { 'constance_enabled': dj_settings.CONSTANCE_ENABLED, 'multi_tenancy': MULTI_TENANCY, 'multi_institution': multi_institution, 'institutions': institutions, 'send_email_on_adding_system_member': SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER, 'sysadmin_extra_enabled': ENABLE_SYSADMIN_EXTRA, 'enable_guest_invitation': ENABLE_GUEST_INVITATION, 'enable_terms_and_conditions': config.ENABLE_TERMS_AND_CONDITIONS, 'enable_file_scan': ENABLE_FILE_SCAN, 'enable_work_weixin': ENABLE_WORK_WEIXIN, 'enable_dingtalk': ENABLE_DINGTALK, 'enable_sys_admin_view_repo': ENABLE_SYS_ADMIN_VIEW_REPO, 'trash_repos_expire_days': expire_days if expire_days > 0 else 30, 'available_roles': get_available_roles(), 'available_admin_roles': get_available_admin_roles(), 'have_ldap': get_ldap_info(), 'two_factor_auth_enabled': has_two_factor_auth(), 'enable_share_link_report_abuse': ENABLE_SHARE_LINK_REPORT_ABUSE, })
def post(self, request, format=None): if has_two_factor_auth() and two_factor_auth_enabled(request.user): return {} randstr = gen_token(max_length=32) token = ClientLoginToken(randstr, request.user.username) token.save() return {'token': randstr}
def post(self, request, format=None): if has_two_factor_auth() and two_factor_auth_enabled(request.user.username): return {} randstr = gen_token(max_length=32) token = ClientLoginToken(randstr, request.user.username) token.save() return {"token": randstr}
def edit_profile(request): """ Show and edit user profile. """ username = request.user.username form_class = DetailedProfileForm if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): form.save(username=username) messages.success(request, _(u'Successfully edited profile.')) return HttpResponseRedirect(reverse('edit_profile')) else: messages.error(request, _(u'Failed to edit profile')) else: profile = Profile.objects.get_profile_by_user(username) d_profile = DetailedProfile.objects.get_detailed_profile_by_user( username) init_dict = {} if profile: init_dict['nickname'] = profile.nickname init_dict['login_id'] = profile.login_id init_dict['contact_email'] = profile.contact_email if d_profile: init_dict['department'] = d_profile.department init_dict['telephone'] = d_profile.telephone form = form_class(init_dict) # common logic try: server_crypto = UserOptions.objects.is_server_crypto(username) except CryptoOptionNotSetError: # Assume server_crypto is ``False`` if this option is not set. server_crypto = False sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) default_repo_id = UserOptions.objects.get_default_repo(username) if default_repo_id: default_repo = seafile_api.get_repo(default_repo_id) else: default_repo = None owned_repos = get_owned_repo_list(request) owned_repos = filter(lambda r: not r.is_virtual, owned_repos) return render_to_response('profile/set_profile.html', { 'form': form, 'server_crypto': server_crypto, "sub_lib_enabled": sub_lib_enabled, 'force_server_crypto': settings.FORCE_SERVER_CRYPTO, 'default_repo': default_repo, 'owned_repos': owned_repos, 'is_pro': is_pro_version(), 'is_ldap_user': is_ldap_user(request.user), 'two_factor_auth_enabled': has_two_factor_auth(), }, context_instance=RequestContext(request))
def _two_factor_auth(self, request, user): if not has_two_factor_auth() or not two_factor_auth_enabled(user): return token = request.META.get('HTTP_X_SEAFILE_OTP', '') if not token: self.two_factor_auth_failed = True msg = 'Two factor auth token is missing.' raise serializers.ValidationError(msg) if not verify_two_factor_token(user.username, token): self.two_factor_auth_failed = True msg = 'Two factor auth token is invalid.' raise serializers.ValidationError(msg)
def _two_factor_auth(self, request, username): if not has_two_factor_auth() or not two_factor_auth_enabled(username): return token = request.META.get('HTTP_X_SEAFILE_OTP', '') if not token: self.two_factor_auth_failed = True msg = 'Two factor auth token is missing.' raise serializers.ValidationError(msg) if not verify_two_factor_token(username, token): self.two_factor_auth_failed = True msg = 'Two factor auth token is invalid.' raise serializers.ValidationError(msg)
def _two_factor_auth(self, request, user): if not has_two_factor_auth() or not two_factor_auth_enabled(user): return if is_device_remembered(request.META.get('HTTP_X_SEAFILE_S2FA', ''), user): return token = request.META.get('HTTP_X_SEAFILE_OTP', '') if not token: # Generate challenge(send sms/call/...) if token is not provided. default_device(user).generate_challenge() self.two_factor_auth_failed = True msg = 'Two factor auth token is missing.' raise serializers.ValidationError(msg) if not verify_two_factor_token(user, token): self.two_factor_auth_failed = True msg = 'Two factor auth token is invalid.' raise serializers.ValidationError(msg)
def edit_profile(request): """ Show and edit user profile. """ username = request.user.username form_class = DetailedProfileForm if request.method == 'POST': form = form_class(user=request.user, data=request.POST) if form.is_valid(): form.save() messages.success(request, _(u'Successfully edited profile.')) return HttpResponseRedirect(reverse('edit_profile')) else: messages.error(request, _(u'Failed to edit profile')) else: profile = Profile.objects.get_profile_by_user(username) d_profile = DetailedProfile.objects.get_detailed_profile_by_user( username) init_dict = {} if profile: init_dict['nickname'] = profile.nickname init_dict['login_id'] = profile.login_id init_dict['contact_email'] = profile.contact_email init_dict['list_in_address_book'] = profile.list_in_address_book if d_profile: init_dict['department'] = d_profile.department init_dict['telephone'] = d_profile.telephone form = form_class(user=request.user, data=init_dict) # common logic try: server_crypto = UserOptions.objects.is_server_crypto(username) except CryptoOptionNotSetError: # Assume server_crypto is ``False`` if this option is not set. server_crypto = False sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) default_repo_id = UserOptions.objects.get_default_repo(username) if default_repo_id: default_repo = seafile_api.get_repo(default_repo_id) else: default_repo = None owned_repos = get_owned_repo_list(request) owned_repos = filter(lambda r: not r.is_virtual, owned_repos) if settings.ENABLE_WEBDAV_SECRET: decoded = UserOptions.objects.get_webdav_decoded_secret(username) webdav_passwd = decoded if decoded else '' else: webdav_passwd = '' email_inverval = UserOptions.objects.get_file_updates_email_interval( username) email_inverval = email_inverval if email_inverval is not None else 0 if settings.SOCIAL_AUTH_WEIXIN_WORK_KEY: enable_wechat_work = True from social_django.models import UserSocialAuth social_connected = UserSocialAuth.objects.filter( username=request.user.username, provider='weixin-work').count() > 0 else: enable_wechat_work = False social_connected = False resp_dict = { 'form': form, 'server_crypto': server_crypto, "sub_lib_enabled": sub_lib_enabled, 'ENABLE_ADDRESSBOOK_OPT_IN': settings.ENABLE_ADDRESSBOOK_OPT_IN, 'default_repo': default_repo, 'owned_repos': owned_repos, 'is_pro': is_pro_version(), 'is_ldap_user': is_ldap_user(request.user), 'two_factor_auth_enabled': has_two_factor_auth(), 'ENABLE_CHANGE_PASSWORD': settings.ENABLE_CHANGE_PASSWORD, 'ENABLE_WEBDAV_SECRET': settings.ENABLE_WEBDAV_SECRET, 'ENABLE_DELETE_ACCOUNT': ENABLE_DELETE_ACCOUNT, 'ENABLE_UPDATE_USER_INFO': ENABLE_UPDATE_USER_INFO, 'webdav_passwd': webdav_passwd, 'email_notification_interval': email_inverval, 'social_connected': social_connected, 'social_next_page': reverse('edit_profile'), 'enable_wechat_work': enable_wechat_work, 'ENABLE_USER_SET_CONTACT_EMAIL': settings.ENABLE_USER_SET_CONTACT_EMAIL, 'user_unusable_password': request.user.enc_password == UNUSABLE_PASSWORD, } if has_two_factor_auth(): from seahub.two_factor.models import StaticDevice, default_device try: backup_tokens = StaticDevice.objects.get( user=request.user.username).token_set.count() except StaticDevice.DoesNotExist: backup_tokens = 0 resp_dict['default_device'] = default_device(request.user) resp_dict['backup_tokens'] = backup_tokens #template = 'profile/set_profile.html' template = 'profile/set_profile_react.html' return render(request, template, resp_dict)
def edit_profile(request): """ Show and edit user profile. """ username = request.user.username form_class = DetailedProfileForm if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): form.save(username=username) messages.success(request, _(u'Successfully edited profile.')) return HttpResponseRedirect(reverse('edit_profile')) else: messages.error(request, _(u'Failed to edit profile')) else: profile = Profile.objects.get_profile_by_user(username) d_profile = DetailedProfile.objects.get_detailed_profile_by_user( username) init_dict = {} if profile: init_dict['nickname'] = profile.nickname init_dict['login_id'] = profile.login_id init_dict['contact_email'] = profile.contact_email init_dict['list_in_address_book'] = profile.list_in_address_book if d_profile: init_dict['department'] = d_profile.department init_dict['telephone'] = d_profile.telephone form = form_class(init_dict) # common logic try: server_crypto = UserOptions.objects.is_server_crypto(username) except CryptoOptionNotSetError: # Assume server_crypto is ``False`` if this option is not set. server_crypto = False sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) default_repo_id = UserOptions.objects.get_default_repo(username) if default_repo_id: default_repo = seafile_api.get_repo(default_repo_id) else: default_repo = None owned_repos = get_owned_repo_list(request) owned_repos = filter(lambda r: not r.is_virtual, owned_repos) resp_dict = { 'form': form, 'server_crypto': server_crypto, "sub_lib_enabled": sub_lib_enabled, 'ENABLE_ADDRESSBOOK_OPT_IN': settings.ENABLE_ADDRESSBOOK_OPT_IN, 'default_repo': default_repo, 'owned_repos': owned_repos, 'is_pro': is_pro_version(), 'is_ldap_user': is_ldap_user(request.user), 'two_factor_auth_enabled': has_two_factor_auth(), } if has_two_factor_auth(): from seahub.two_factor.models import StaticDevice from seahub.two_factor.utils import default_device try: backup_tokens = StaticDevice.objects.get( user=request.user.username).token_set.count() except StaticDevice.DoesNotExist: backup_tokens = 0 resp_dict['default_device'] = default_device(request.user) resp_dict['backup_tokens'] = backup_tokens return render_to_response('profile/set_profile.html', resp_dict, context_instance=RequestContext(request))
def edit_profile(request): """ Show and edit user profile. """ username = request.user.username form_class = DetailedProfileForm if request.method == 'POST': form = form_class(user=request.user, data=request.POST) if form.is_valid(): form.save() messages.success(request, _(u'Successfully edited profile.')) return HttpResponseRedirect(reverse('edit_profile')) else: messages.error(request, _(u'Failed to edit profile')) else: profile = Profile.objects.get_profile_by_user(username) d_profile = DetailedProfile.objects.get_detailed_profile_by_user( username) init_dict = {} if profile: init_dict['nickname'] = profile.nickname init_dict['login_id'] = profile.login_id init_dict['contact_email'] = profile.contact_email init_dict['list_in_address_book'] = profile.list_in_address_book if d_profile: init_dict['department'] = d_profile.department init_dict['telephone'] = d_profile.telephone form = form_class(user=request.user, data=init_dict) # common logic try: server_crypto = UserOptions.objects.is_server_crypto(username) except CryptoOptionNotSetError: # Assume server_crypto is ``False`` if this option is not set. server_crypto = False sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username) default_repo_id = UserOptions.objects.get_default_repo(username) if default_repo_id: default_repo = seafile_api.get_repo(default_repo_id) else: default_repo = None owned_repos = get_owned_repo_list(request) owned_repos = filter(lambda r: not r.is_virtual, owned_repos) if settings.ENABLE_WEBDAV_SECRET: decoded = UserOptions.objects.get_webdav_decoded_secret(username) webdav_passwd = decoded if decoded else '' else: webdav_passwd = '' email_inverval = UserOptions.objects.get_file_updates_email_interval(username) email_inverval = email_inverval if email_inverval is not None else 0 if settings.SOCIAL_AUTH_WEIXIN_WORK_KEY: enable_wechat_work = True from social_django.models import UserSocialAuth social_connected = UserSocialAuth.objects.filter( username=request.user.username, provider='weixin-work').count() > 0 else: enable_wechat_work = False social_connected = False resp_dict = { 'form': form, 'server_crypto': server_crypto, "sub_lib_enabled": sub_lib_enabled, 'ENABLE_ADDRESSBOOK_OPT_IN': settings.ENABLE_ADDRESSBOOK_OPT_IN, 'default_repo': default_repo, 'owned_repos': owned_repos, 'is_pro': is_pro_version(), 'is_ldap_user': is_ldap_user(request.user), 'two_factor_auth_enabled': has_two_factor_auth(), 'ENABLE_CHANGE_PASSWORD': settings.ENABLE_CHANGE_PASSWORD, 'ENABLE_WEBDAV_SECRET': settings.ENABLE_WEBDAV_SECRET, 'ENABLE_DELETE_ACCOUNT': ENABLE_DELETE_ACCOUNT, 'ENABLE_UPDATE_USER_INFO': ENABLE_UPDATE_USER_INFO, 'webdav_passwd': webdav_passwd, 'email_notification_interval': email_inverval, 'social_connected': social_connected, 'social_next_page': reverse('edit_profile'), 'enable_wechat_work': enable_wechat_work, 'ENABLE_USER_SET_CONTACT_EMAIL': settings.ENABLE_USER_SET_CONTACT_EMAIL, 'user_unusable_password': request.user.enc_password == UNUSABLE_PASSWORD, } if has_two_factor_auth(): from seahub.two_factor.models import StaticDevice, default_device try: backup_tokens = StaticDevice.objects.get( user=request.user.username).token_set.count() except StaticDevice.DoesNotExist: backup_tokens = 0 resp_dict['default_device'] = default_device(request.user) resp_dict['backup_tokens'] = backup_tokens #template = 'profile/set_profile.html' template = 'profile/set_profile_react.html' return render(request, template, resp_dict)