Beispiel #1
0
 def get_context_data(self, **kwargs):
     try:
         backup_tokens = StaticDevice.objects.get(
             user=self.request.user.username).token_set.count()
     except StaticDevice.DoesNotExist:
         backup_tokens = 0
     return {
         'default_device': default_device(self.request.user),
         'default_device_type':
         default_device(self.request.user).__class__.__name__,
         'backup_tokens': backup_tokens,
     }
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     """
     Start the setup wizard. Redirect if already enabled.
     """
     if default_device(self.request.user):
         return redirect(self.redirect_url)
     return super(SetupView, self).get(request, *args, **kwargs)
Beispiel #3
0
 def get_device(self, step=None):
     """
     Returns the OTP device selected by the user, or his default device.
     """
     if not self.device_cache:
         if step == 'backup':
             try:
                 self.device_cache = StaticDevice.objects.get(
                     user=self.user.username, name='backup')
             except StaticDevice.DoesNotExist:
                 pass
         if not self.device_cache:
             self.device_cache = default_device(self.user)
     return self.device_cache
Beispiel #4
0
def log_user_in(request, user, redirect_to):
    # Ensure the user-originating redirection url is safe.
    if not is_safe_url(url=redirect_to, host=request.get_host()):
        redirect_to = settings.LOGIN_REDIRECT_URL

    if request.session.test_cookie_worked():
        request.session.delete_test_cookie()

    clear_login_failed_attempts(request, user.username)

    if two_factor_auth_enabled(user):
        if is_device_remembered(request.COOKIES.get('S2FA', ''), user):
            from seahub.two_factor.utils import default_device
            user.otp_device = default_device(user)
        else:
            return handle_two_factor_auth(request, user, redirect_to)

    # Okay, security checks complete. Log the user in.
    auth_login(request, user)

    return HttpResponseRedirect(redirect_to)
Beispiel #5
0
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))
Beispiel #6
0
 def has_token_step(self):
     return default_device(self.get_user_from_request(self.request))