# Path: osf/models/provider.py
# class PreprintProvider(AbstractProvider):
# 
#     def __init__(self, *args, **kwargs):
#         self._meta.get_field('share_publish_type').default = 'Preprint'
#         super().__init__(*args, **kwargs)
# 
#     PUSH_SHARE_TYPE_HELP = 'This SHARE type will be used when pushing publications to SHARE'
# 
#     REVIEWABLE_RELATION_NAME = 'preprints'
# 
#     additional_providers = fields.ArrayField(models.CharField(max_length=200), default=list, blank=True)
#     in_sloan_study = models.NullBooleanField(default=True)
# 
#     PREPRINT_WORD_CHOICES = (
#         ('preprint', 'Preprint'),
#         ('paper', 'Paper'),
#         ('thesis', 'Thesis'),
#         ('work', 'Work'),
#         ('none', 'None')
#     )
#     preprint_word = models.CharField(max_length=10, choices=PREPRINT_WORD_CHOICES, default='preprint')
#     subjects_acceptable = DateTimeAwareJSONField(blank=True, default=list)
# 
#     class Meta:
#         permissions = (
#             # custom permissions for use in the OSF Admin App
#             ('view_preprintprovider', 'Can view preprint provider details'),
#         )
# 
#     @property
#     def readable_type(self):
#         return 'preprint'
# 
#     @property
#     def all_subjects(self):
#         if self.subjects.exists():
#             return self.subjects.all()
#         else:
#             # TODO: Delet this when all PreprintProviders have a mapping
#             return rules_to_subjects(self.subjects_acceptable)
# 
#     @property
#     def has_highlighted_subjects(self):
#         return self.subjects.filter(highlighted=True).exists()
# 
#     @property
#     def highlighted_subjects(self):
#         if self.has_highlighted_subjects:
#             return self.subjects.filter(highlighted=True).order_by('text')[:10]
#         else:
#             return sorted(self.top_level_subjects, key=lambda s: s.text)[:10]
# 
#     @property
#     def top_level_subjects(self):
#         if self.subjects.exists():
#             return optimize_subject_query(self.subjects.filter(parent__isnull=True))
#         else:
#             # TODO: Delet this when all PreprintProviders have a mapping
#             if len(self.subjects_acceptable) == 0:
#                 return optimize_subject_query(Subject.objects.filter(parent__isnull=True, provider___id='osf'))
#             tops = set([sub[0][0] for sub in self.subjects_acceptable])
#             return [Subject.load(sub) for sub in tops]
# 
#     @property
#     def landing_url(self):
#         return self.domain if self.domain else '{}preprints/{}'.format(settings.DOMAIN, self._id)
# 
#     def get_absolute_url(self):
#         return '{}preprint_providers/{}'.format(self.absolute_api_v2_url, self._id)
# 
#     @property
#     def absolute_api_v2_url(self):
#         path = '/providers/preprints/{}/'.format(self._id)
#         return api_v2_url(path)


import furl
import markupsafe
from rest_framework import status as http_status
from future.moves.urllib.parse import urlencode
from django.core.exceptions import ValidationError
from django.utils import timezone
from flask import request
from addons.osfstorage.models import Region
from framework import forms, sentry, status
from framework import auth as framework_auth
from framework.auth import exceptions
from framework.auth import cas, campaigns
from framework.auth import logout as osf_logout
from framework.auth import get_user
from framework.auth.exceptions import DuplicateEmailError, ExpiredTokenError, InvalidTokenError
from framework.auth.core import generate_verification_key
from framework.auth.decorators import block_bing_preview, collect_auth, must_be_logged_in
from framework.auth.forms import ResendConfirmationForm, ForgotPasswordForm, ResetPasswordForm
from framework.auth.utils import ensure_external_identity_uniqueness, validate_recaptcha
from framework.exceptions import HTTPError
from framework.flask import redirect  # VOL-aware redirect
from framework.sessions.utils import remove_sessions_for_user, remove_session
from framework.sessions import get_session
from framework.utils import throttle_period_expired
from osf.models import OSFUser
from osf.utils.sanitize import strip_html
from website import settings, mails, language
from website.ember_osf_web.decorators import ember_flag_is_active
from api.waffle.utils import storage_i18n_flag_active
from website.util import web_url_for
from osf.exceptions import ValidationValueError, BlockedEmailError
from osf.models.provider import PreprintProvider
from osf.models.tag import Tag
from osf.utils.requests import check_select_for_update
from osf import features
from website.util.metrics import CampaignClaimedTags, CampaignSourceTags

    context = {}
    # a target campaign in `auth.campaigns`
    campaign = request.args.get('campaign')
    # the service url for CAS login or redirect url for OSF
    next_url = request.args.get('next')
    # TODO: no longer used for `claim_user_registered`, see [#PLAT-1151]
    logout = request.args.get('logout')

    # logout must have next_url
    if logout and not next_url:
        raise HTTPError(http_status.HTTP_400_BAD_REQUEST)

    data = login_and_register_handler(auth, login=False, campaign=campaign, next_url=next_url, logout=logout)

    # land on register page
    if data['status_code'] == http_status.HTTP_200_OK:
        if data['must_login_warning']:
            status.push_status_message(language.MUST_LOGIN, trust=False)
        destination = cas.get_login_url(data['next_url'])
        # "Already have and account?" link
        context['non_institution_login_url'] = destination
        # "Sign In" button in navigation bar, overwrite the default value set in routes.py
        context['login_url'] = destination
        # "Login through your institution" link
        context['institution_login_url'] = cas.get_login_url(data['next_url'], campaign='institution')
        context['preprint_campaigns'] = {k._id + '-preprints': {
            'id': k._id,
            'name': k.name,
            'logo_path': k.get_asset_url('square_color_no_transparent')

# Path: osf/models/provider.py
# class PreprintProvider(AbstractProvider):
# 
#     def __init__(self, *args, **kwargs):
#         self._meta.get_field('share_publish_type').default = 'Preprint'
#         super().__init__(*args, **kwargs)
# 
#     PUSH_SHARE_TYPE_HELP = 'This SHARE type will be used when pushing publications to SHARE'
# 
#     REVIEWABLE_RELATION_NAME = 'preprints'
# 
#     additional_providers = fields.ArrayField(models.CharField(max_length=200), default=list, blank=True)
#     in_sloan_study = models.NullBooleanField(default=True)
# 
#     PREPRINT_WORD_CHOICES = (
#         ('preprint', 'Preprint'),
#         ('paper', 'Paper'),
#         ('thesis', 'Thesis'),
#         ('work', 'Work'),
#         ('none', 'None')
#     )
#     preprint_word = models.CharField(max_length=10, choices=PREPRINT_WORD_CHOICES, default='preprint')
#     subjects_acceptable = DateTimeAwareJSONField(blank=True, default=list)
# 
#     class Meta:
#         permissions = (
#             # custom permissions for use in the OSF Admin App
#             ('view_preprintprovider', 'Can view preprint provider details'),
#         )
# 
#     @property
#     def readable_type(self):
#         return 'preprint'
# 
#     @property
#     def all_subjects(self):
#         if self.subjects.exists():
#             return self.subjects.all()
#         else:
#             # TODO: Delet this when all PreprintProviders have a mapping
#             return rules_to_subjects(self.subjects_acceptable)
# 
#     @property
#     def has_highlighted_subjects(self):
#         return self.subjects.filter(highlighted=True).exists()
# 
#     @property
#     def highlighted_subjects(self):
#         if self.has_highlighted_subjects:
#             return self.subjects.filter(highlighted=True).order_by('text')[:10]
#         else:
#             return sorted(self.top_level_subjects, key=lambda s: s.text)[:10]
# 
#     @property
#     def top_level_subjects(self):
#         if self.subjects.exists():
#             return optimize_subject_query(self.subjects.filter(parent__isnull=True))
#         else:
#             # TODO: Delet this when all PreprintProviders have a mapping
#             if len(self.subjects_acceptable) == 0:
#                 return optimize_subject_query(Subject.objects.filter(parent__isnull=True, provider___id='osf'))
#             tops = set([sub[0][0] for sub in self.subjects_acceptable])
#             return [Subject.load(sub) for sub in tops]
# 
#     @property
#     def landing_url(self):
#         return self.domain if self.domain else '{}preprints/{}'.format(settings.DOMAIN, self._id)
# 
#     def get_absolute_url(self):
#         return '{}preprint_providers/{}'.format(self.absolute_api_v2_url, self._id)
# 
#     @property
#     def absolute_api_v2_url(self):
#         path = '/providers/preprints/{}/'.format(self._id)
#         return api_v2_url(path)


# Path: framework/auth/views.py
import furl
import markupsafe
from rest_framework import status as http_status
from future.moves.urllib.parse import urlencode
from django.core.exceptions import ValidationError
from django.utils import timezone
from flask import request
from addons.osfstorage.models import Region
from framework import forms, sentry, status
from framework import auth as framework_auth
from framework.auth import exceptions
from framework.auth import cas, campaigns
from framework.auth import logout as osf_logout
from framework.auth import get_user
from framework.auth.exceptions import DuplicateEmailError, ExpiredTokenError, InvalidTokenError
from framework.auth.core import generate_verification_key
from framework.auth.decorators import block_bing_preview, collect_auth, must_be_logged_in
from framework.auth.forms import ResendConfirmationForm, ForgotPasswordForm, ResetPasswordForm
from framework.auth.utils import ensure_external_identity_uniqueness, validate_recaptcha
from framework.exceptions import HTTPError
from framework.flask import redirect  # VOL-aware redirect
from framework.sessions.utils import remove_sessions_for_user, remove_session
from framework.sessions import get_session
from framework.utils import throttle_period_expired
from osf.models import OSFUser
from osf.utils.sanitize import strip_html
from website import settings, mails, language
from website.ember_osf_web.decorators import ember_flag_is_active
from api.waffle.utils import storage_i18n_flag_active
from website.util import web_url_for
from osf.exceptions import ValidationValueError, BlockedEmailError
from osf.models.provider import PreprintProvider
from osf.models.tag import Tag
from osf.utils.requests import check_select_for_update
from osf import features
from website.util.metrics import CampaignClaimedTags, CampaignSourceTags


    context = {}
    # a target campaign in `auth.campaigns`
    campaign = request.args.get('campaign')
    # the service url for CAS login or redirect url for OSF
    next_url = request.args.get('next')
    # TODO: no longer used for `claim_user_registered`, see [#PLAT-1151]
    logout = request.args.get('logout')

    # logout must have next_url
    if logout and not next_url:
        raise HTTPError(http_status.HTTP_400_BAD_REQUEST)

    data = login_and_register_handler(auth, login=False, campaign=campaign, next_url=next_url, logout=logout)

    # land on register page
    if data['status_code'] == http_status.HTTP_200_OK:
        if data['must_login_warning']:
            status.push_status_message(language.MUST_LOGIN, trust=False)
        destination = cas.get_login_url(data['next_url'])
        # "Already have and account?" link
        context['non_institution_login_url'] = destination
        # "Sign In" button in navigation bar, overwrite the default value set in routes.py
        context['login_url'] = destination
        # "Login through your institution" link
        context['institution_login_url'] = cas.get_login_url(data['next_url'], campaign='institution')
        context['preprint_campaigns'] = {k._id + '-preprints': {
            'id': k._id,
            'name': k.name,
            'logo_path': k.get_asset_url('square_color_no_transparent')

        } for k in PreprintProvider.objects.all() if k._id != 'osf'}