当前位置: 首页>>代码示例>>Python>>正文


Python User.is_staff方法代码示例

本文整理汇总了Python中forum.models.User.is_staff方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_staff方法的具体用法?Python User.is_staff怎么用?Python User.is_staff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forum.models.User的用法示例。


在下文中一共展示了User.is_staff方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def register(request):
    if request.method == 'POST':
        form = ClassicRegisterForm(request.POST.copy())
        #form = ClassicRegisterForm(request.POST)
        logging.info(form)
        if form.is_valid():
            logging.error(form.cleaned_data)
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            #email = form.cleaned_data['email']

            #user_ = User(username=username, email=email)
            user_ = User(username=username)
            user_.set_password(password)

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()
            #UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()

            return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
    else:
        #form = ClassicRegisterForm(initial={'next':'/'})
        form = ClassicRegisterForm()

    return render_to_response('auth/complete.html', {
        'form1': form
        }, context_instance=RequestContext(request))
开发者ID:zhigoo,项目名称:osqa-server,代码行数:32,代码来源:views.py

示例2: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def register(request):
    if request.method == "POST":
        form = ClassicRegisterForm(request.POST)
        email_feeds_form = SimpleEmailSubscribeForm(request.POST)

        if form.is_valid() and email_feeds_form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            email = form.cleaned_data["email"]

            user_ = User(username=username, email=email)
            user_.set_password(password)

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()

            UserJoinsAction(user=user_, ip=request.META["REMOTE_ADDR"]).save()

            if email_feeds_form.cleaned_data["subscribe"] == "n":
                user_.subscription_settings.enable_notifications = False
                user_.subscription_settings.save()

            return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
    else:
        form = ClassicRegisterForm(initial={"next": "/"})
        email_feeds_form = SimpleEmailSubscribeForm()

    return render_to_response(
        "auth/complete.html",
        {"form1": form, "email_feeds_form": email_feeds_form},
        context_instance=RequestContext(request),
    )
开发者ID:yangjiandong,项目名称:zhimaq,代码行数:37,代码来源:views.py

示例3: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def register(request):
    if request.method == 'POST':
        form = ClassicRegisterForm(request.POST)
        email_feeds_form = SimpleEmailSubscribeForm(request.POST)

        if form.is_valid() and email_feeds_form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            email = form.cleaned_data['email']

            user_ = User(username=username, email=email)
            user_.set_password(password)

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()
            UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()

            if email_feeds_form.cleaned_data['subscribe'] == 'n':
                user_.subscription_settings.enable_notifications = False
                user_.subscription_settings.save()

            return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
    else:
        form = ClassicRegisterForm(initial={'next':'/'})
        email_feeds_form = SimpleEmailSubscribeForm()

    return render_to_response('auth/complete.html', {
        'form1': form,
        'email_feeds_form': email_feeds_form
        }, context_instance=RequestContext(request))
开发者ID:p2pu,项目名称:osqa-badges,代码行数:35,代码来源:views.py

示例4: import_users

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
    def import_users(self, users):
        pkey_map = {}
        doc = dom.parse(users)

        rows = doc.getElementsByTagName('row')
        unknown_count = 0

        added_names = []

        for row in rows:
            values = self.row_to_dic(row)

            username = values.get('displayname',
                            values.get('realname',
                                values.get('email', None)))

            if username is None:
                unknown_count += 1
                username = 'Unknown User %d' % unknown_count

            if username in added_names:
                cnt = 1
                new_username = "%s %d" % (username, cnt)
                while new_username in added_names:
                    cnt += 1
                    new_username = "%s %d" % (username, cnt)

                username = new_username

            added_names.append(username)

            user = User(username=username, email=values.get('email', ''))

            user.reputation = values['reputation']
            user.last_seen = self.from_sx_time(values['lastaccessdate'])

            user.real_name = values.get('realname', '')
            user.about = values.get('aboutme', '')
            user.website = values.get('websiteurl', '')
            user.date_of_birth = self.from_sx_time(values.get('birthday', None))
            user.location = values.get('location', '')

            user.is_active = True
            user.email_isvalid = True


            if int(values['usertypeid']) == 5:
                user.is_superuser = True

            if int(values['usertypeid']) == 5:
                user.is_staff = True

            user.save()

            pkey_map[values['id']] = user

        return users
开发者ID:EzerchE,项目名称:askbot-devel,代码行数:59,代码来源:sximport.py

示例5: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def register(request):
    banned_ips = cache.get(BANNED_IPS_KEY, set())
    ip = get_client_ip(request)
    if ip in banned_ips:
        logging.warning("Spammer returned ip:%s" % ip)
        return HttpResponseRedirect("http://www.pudelek.pl/artykul/x/")

    if request.method == "POST":
        banned_emails = cache.get(BANNED_EMAILS_KEY, set())
        if request.POST["email"] in banned_emails:
            logging.warning("Spammer returned:%s, ip:%s" % (request.POST["email"], ip))
            return HttpResponseRedirect("http://www.pudelek.pl/artykul/x/")

        form = ClassicRegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password1"]
            email = form.cleaned_data["email"]

            # Honeypot checks
            if request.POST.get("age", None):
                logging.warning("Age honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
                ban(email, ip)
                return HttpResponseRedirect(reverse("index"))

            if request.POST.get("birthday", None):
                logging.warning("Birthday honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
                ban(email, ip)
                return HttpResponseRedirect(reverse("index"))

            if request.POST.get("website", None):
                logging.warning("Website honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
                ban(email, ip)
                return HttpResponseRedirect(reverse("index"))

            user_ = User(username=username, email=email)
            user_.set_password(password)

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()
            UserJoinsAction(user=user_, ip=request.META["REMOTE_ADDR"]).save()
            logging.info("New user joined with email:%s from ip:%s" % (email, ip))

            return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
    else:
        form = ClassicRegisterForm(initial={"next": "/"})

    return render_to_response(
        "auth/register.html",
        {"form1": form, "bigicon_providers": _get_bigicon_providers(request)},
        context_instance=RequestContext(request),
    )
开发者ID:konrado0,项目名称:vosqa,代码行数:57,代码来源:views.py

示例6: authenticate

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
 def authenticate(self, username=None, password=None):
     try:
         drupal_user = drupal.Users.objects.using(DRUPAL_DB).get(name=username)
     except drupal.Users.DoesNotExist:
         return None
     if User.objects.filter(username=drupal_user.name):
         # Only authenticates users that have not being migrated to the django database.
         return None
     user = User(username=username)
     pwd_valid = self.check_password(drupal_user, user, password)
     if pwd_valid:
         DrupalAuthBackend.get_user_data(drupal_user, user)
         if User.objects.all().count() == 0:
             user.is_superuser = True
             user.is_staff = True
         user.save()
         return user
     else:
         return None
开发者ID:jledbetter,项目名称:osqa-badges,代码行数:21,代码来源:drupal_auth_backend.py

示例7: authenticate

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
 def authenticate(self, username=None, password=None):
     try:
         lernanta_user = lernanta.UserProfile.objects.using(LERNANTA_DB).get(username=username)
     except lernanta.UserProfile.DoesNotExist:
         return None
     try:
         user = User.objects.get(username=lernanta_user.username)
         user.is_active = lernanta_user.user.is_active
         user.save()
     except User.DoesNotExist:
         user = User(username=username)
     if not lernanta_user.user.is_active or not lernanta_user.password:
         return None
     pwd_valid = self.check_password(lernanta_user, user, password)
     if pwd_valid:
         LernantaAuthBackend.get_user_data(lernanta_user, user)
         if User.objects.all().count() == 0:
             user.is_superuser = True
             user.is_staff = True
         user.save()
         return user
     else:
         return None
开发者ID:p2pu,项目名称:osqa-badges,代码行数:25,代码来源:backend.py

示例8: external_register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def external_register(request):
    if request.method == 'POST' and 'bnewaccount' in request.POST:
        form1 = SimpleRegistrationForm(request.POST)

        if form1.is_valid():
            user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email'])
            user_.email_isvalid = request.session.get('auth_validated_email', '') == form1.cleaned_data['email']
            user_.set_unusable_password()

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()
            UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()

            try:
                assoc_key = request.session['assoc_key']
                auth_provider = request.session['auth_provider']
            except:
                request.session['auth_error'] = _(
                        "Oops, something went wrong in the middle of this process. Please try again. Note that you need to have cookies enabled for the authentication to work."
                        )
                logging.error("Missing session data when trying to complete user registration: %s" % ", ".join(
                        ["%s: %s" % (k, v) for k, v in request.META.items()]))
                return HttpResponseRedirect(reverse('auth_signin'))

            uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider)
            uassoc.save()

            del request.session['assoc_key']
            del request.session['auth_provider']

            return login_and_forward(request, user_, message=_("A welcome email has been sent to your email address. "))
    else:
        auth_provider = request.session.get('auth_provider', None)
        if not auth_provider:
            request.session['auth_error'] = _(
                    "Oops, something went wrong in the middle of this process. Please try again.")
            logging.error("Missing session data when trying to complete user registration: %s" % ", ".join(
                    ["%s: %s" % (k, v) for k, v in request.META.items()]))
            return HttpResponseRedirect(reverse('auth_signin'))

        provider_class = AUTH_PROVIDERS[auth_provider].consumer

        # Hack: Facebook auth expects an access token, not the assoc_key.
        identifier = request.session['assoc_key']
        if auth_provider == 'facebook':
            identifier = request.session['access_token']
        user_data = provider_class.get_user_data(identifier)

        if not user_data:
            user_data = request.session.get('auth_consumer_data', {})

        username = user_data.get('username', '')
        email = user_data.get('email', '')

        if email:
            request.session['auth_validated_email'] = email

        form1 = SimpleRegistrationForm(initial={
        'next': '/',
        'username': username,
        'email': email,
        })

    provider_context = AUTH_PROVIDERS[request.session['auth_provider']].context

    return render_to_response('auth/complete.html', {
    'form1': form1,
    'provider':provider_context and mark_safe(provider_context.human_name) or _('unknown'),
    'login_type':provider_context.id,
    'gravatar_faq_url':reverse('faq') + '#gravatar',
    }, context_instance=RequestContext(request))
开发者ID:Hakayati,项目名称:paleonaut,代码行数:76,代码来源:auth.py

示例9: external_register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def external_register(request):
    if request.method == "POST" and "bnewaccount" in request.POST:
        form1 = SimpleRegistrationForm(request.POST)

        if form1.is_valid():
            user_ = User(
                username=form1.cleaned_data["username"],
                email=form1.cleaned_data["email"],
                real_name=form1.cleaned_data["real_name"],
            )
            user_.email_isvalid = request.session.get("auth_validated_email", "") == form1.cleaned_data["email"]
            user_.set_unusable_password()

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()
            UserJoinsAction(user=user_, ip=request.META["REMOTE_ADDR"]).save()

            try:
                assoc_key = request.session["assoc_key"]
                auth_provider = request.session["auth_provider"]
            except:
                request.session["auth_error"] = _(
                    "Oops, something went wrong in the middle of this process. Please try again. Note that you need to have cookies enabled for the authentication to work."
                )
                logging.error(
                    "Missing session data when trying to complete user registration: %s"
                    % ", ".join(["%s: %s" % (k, v) for k, v in request.META.items()])
                )
                return HttpResponseRedirect(reverse("auth_signin"))

            uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider)
            uassoc.save()

            del request.session["assoc_key"]
            del request.session["auth_provider"]

            return login_and_forward(request, user_, message=_("A welcome email has been sent to your email address. "))
    else:
        auth_provider = request.session.get("auth_provider", None)
        if not auth_provider:
            request.session["auth_error"] = _(
                "Oops, something went wrong in the middle of this process. Please try again."
            )
            logging.error(
                "Missing session data when trying to complete user registration: %s"
                % ", ".join(["%s: %s" % (k, v) for k, v in request.META.items()])
            )
            return HttpResponseRedirect(reverse("auth_signin"))

        provider_class = AUTH_PROVIDERS[auth_provider].consumer

        if provider_class.__class__.__name__ == "FacebookAuthConsumer":
            user_data = provider_class.get_user_data(request.session["access_token"])
        else:
            user_data = provider_class.get_user_data(request.session["assoc_key"])

        if not user_data:
            user_data = request.session.get("auth_consumer_data", {})

        username = user_data.get("username", "")
        email = user_data.get("email", "")
        real_name = user_data.get("real_name", "")

        if email:
            request.session["auth_validated_email"] = email

        form1 = SimpleRegistrationForm(
            initial={"next": "/", "username": username, "email": email, "real_name": real_name}
        )

    provider_context = AUTH_PROVIDERS[request.session["auth_provider"]].context

    return render_to_response(
        "auth/complete.html",
        {
            "form1": form1,
            "provider": provider_context and mark_safe(provider_context.human_name) or _("unknown"),
            "login_type": provider_context.id,
            "gravatar_faq_url": reverse("faq") + "#gravatar",
        },
        context_instance=RequestContext(request),
    )
开发者ID:pombredanne,项目名称:osqa-ng,代码行数:87,代码来源:auth.py

示例10: external_register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def external_register(request):
    if request.method == 'POST' and 'bnewaccount' in request.POST:
        form1 = SimpleRegistrationForm(request.POST)        

        if form1.is_valid():
            message= u''
            try:
                user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email'], 
                             real_name=form1.cleaned_data.get('real_name', ''))
                user_.email_isvalid = request.session.get('auth_validated_email', '') == form1.cleaned_data['email']
                user_.set_unusable_password()
    
                if User.objects.all().count() == 0:
                    user_.is_superuser = True
                    user_.is_staff = True
            
                assoc_key = request.session['assoc_key']
                auth_provider = request.session['auth_provider']
                
                user_.save()
                UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
                if user_.email_isvalid:
                    EmailValidationAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
                    message += _(u"A welcome email has been sent to Your email address.")
                else:
                    message += _(u"A welcome email has been sent to You.<br />Remember to validate Your email address to be able to fully participate in %s community." % settings.APP_TITLE)
                
                uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider)
                uassoc.save()
                logging.info(u"User %s joined via %s" % (user_.username, auth_provider))
            except:
                request.session['auth_error'] = _(
                        "Oops, something went wrong in the middle of this process. Please try again. Note that you need to have cookies enabled for the authentication to work."
                        )
                logging.exception("Missing session data when trying to complete user registration: %s" % ", ".join(
                        ["%s: %s" % (k, v) for k, v in request.META.items()]))
                return HttpResponseRedirect(reverse('auth_signin'))           

            _cleanup_after_external_signin(request)
            return login_and_forward(request, user_, message=message)
        else:
            logging.info("Form not validated in external_register %s", str(form1.errors))
    else:        
        auth_provider = request.session.get('auth_provider', None)
        if not auth_provider:
            request.session['auth_error'] = _(
                    "Oops, something went wrong in the middle of this process. Please try again.")
            logging.error("Missing session data when trying to complete user registration: %s" % ", ".join(
                    ["%s: %s" % (k, v) for k, v in request.META.items()]))
            return HttpResponseRedirect(reverse('auth_signin'))

        provider_class = AUTH_PROVIDERS[auth_provider].consumer

        if provider_class.__class__.__name__ == 'FacebookAuthConsumer' or provider_class.__class__.__name__ == 'GoogleAuthConsumer':
            user_data = provider_class.get_user_data(request.session['access_token'])
        else:
            user_data = provider_class.get_user_data(request.session['assoc_key'])


        if not user_data:
            user_data = request.session.get('auth_consumer_data', {})

        username = user_data.get('username', '')
        email = user_data.get('email', '')
        real_name = user_data.get('real_name', '')

        if email:
            try:
                old_user = User.objects.get(email=email)
                message=_("Welcome back %s! You can now login via %s.") % (old_user.username, auth_provider.capitalize())
                if not old_user.email_isvalid:
                    message += _("<br />Since this email was not previously validated we cleared your password.<br />Set new one to be able to login with it")
                    old_user.set_unusable_password()
                    old_user.email_isvalid = True
                    old_user.save()
                    logging.warning("Clearing password for user %s with unvalidated email after signing with %s" % 
                                    (old_user.username, auth_provider))
                    EmailValidationAction(user=old_user, ip=request.META['REMOTE_ADDR']).save()
                uassoc = AuthKeyUserAssociation(user=old_user, key=request.session['assoc_key'], provider=auth_provider)
                uassoc.save()
                logging.info(u"User %s added %s sign in provider" % (old_user.username, auth_provider))
                _cleanup_after_external_signin(request)
                return login_and_forward(request, old_user, message=mark_safe(message))
            except:
                pass
            request.session['auth_validated_email'] = email

        form1 = SimpleRegistrationForm(initial={
        'next': '/',
        'username': username,
        'email': email,
        'real_name': real_name,
        })

    provider_context = AUTH_PROVIDERS[request.session['auth_provider']].context

    return render_to_response('auth/complete.html', {
    'form1': form1,
    'provider':provider_context and mark_safe(provider_context.human_name) or _('unknown'),
    'login_type':provider_context.id,
#.........这里部分代码省略.........
开发者ID:konrado0,项目名称:vosqa,代码行数:103,代码来源:auth.py

示例11: external_register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import is_staff [as 别名]
def external_register(request):
    if request.method == 'POST' and 'bnewaccount' in request.POST:
        form1 = SimpleRegistrationForm(request.POST)

        if form1.is_valid():
            user_ = User(username=form1.cleaned_data['username'], email=form1.cleaned_data['email'])
            user_.email_isvalid = request.session.get('auth_validated_email', '') == form1.cleaned_data['email']
            user_.set_unusable_password()

            if User.objects.all().count() == 0:
                user_.is_superuser = True
                user_.is_staff = True

            user_.save()

            try:
                assoc_key = request.session['assoc_key']
                auth_provider = request.session['auth_provider']
                if auth_provider == "weibo":
                    token = ast.literal_eval(assoc_key)
                    assoc_key = token["access_token"]
                    weibo_uid = token["uid"]
                    weibo_remind_in = token["remind_in"]
                    weibo_expires_at = token["expires_at"]

            except:
                request.session['auth_error'] = _(
                        "Oops, something went wrong in the middle of this process. Please try again. Note that you need to have cookies enabled for the authentication to work."
                        )
                logging.error("Missing session data when trying to complete user registration: %s" % ", ".join(
                        ["%s: %s" % (k, v) for k, v in request.META.items()]))
                return HttpResponseRedirect(reverse('auth_signin'))

            if auth_provider == "weibo":
                uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider,weibo_uid=weibo_uid,weibo_remind_in=weibo_remind_in,weibo_expires_at=weibo_expires_at)
            else:
                uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider)
            uassoc.save()

            UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
            del request.session['assoc_key']
            del request.session['auth_provider']

            return login_and_forward(request, user_, message=_("A welcome email has been sent to your email address. "))
    else:
        auth_provider = request.session.get('auth_provider', None)
        if not auth_provider:
            request.session['auth_error'] = _(
                    "Oops, something went wrong in the middle of this process. Please try again.")
            logging.error("Missing session data when trying to complete user registration: %s" % ", ".join(
                    ["%s: %s" % (k, v) for k, v in request.META.items()]))
            return HttpResponseRedirect(reverse('auth_signin'))

        if auth_provider == 'weibo':
            assoc_key = request.session['assoc_key']
            token = ast.literal_eval(assoc_key)
            client = weibo_client(str(settings.WEIBO_API_KEY), str(settings.WEIBO_API_SECRET),urlparse.urljoin(settings.APP_URL,'/weibo/signin/check'),token)
            user=client.get('users/show', uid=token["uid"])
            username = user["name"]
            email = None
            provider_context = None

        else: # weibo user register
            provider_class = AUTH_PROVIDERS[auth_provider].consumer
            user_data = provider_class.get_user_data(request.session['assoc_key'])

            if not user_data:
                user_data = request.session.get('auth_consumer_data', {})

            username = user_data.get('username', '')
            email = user_data.get('email', '')

            provider_context = AUTH_PROVIDERS[request.session['auth_provider']].context

        if email:
            request.session['auth_validated_email'] = email

        form1 = SimpleRegistrationForm(initial={
        'next': '/',
        'username': username,
        'email': email,
        })


    return render_to_response('auth/complete.html', {
    'form1': form1,
    #'provider':provider_context and mark_safe(provider_context.human_name) or _('unknown'),
    #'login_type':provider_context.id,
    'gravatar_faq_url':reverse('faq') + '#gravatar',
    }, context_instance=RequestContext(request))
开发者ID:dal-bhaat,项目名称:stack5,代码行数:92,代码来源:auth.py


注:本文中的forum.models.User.is_staff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。