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


Python User.save方法代码示例

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


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

示例1: process_authentication_request

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
    def process_authentication_request(self, request):

        # Check for the Shibboleth session header.
        if 'HTTP_SHIB_SESSION_ID' in request.META and request.META['HTTP_SHIB_SESSION_ID']:

            # Fetch the username and email from Shibboleth headers.
            utf8_username = request.META['HTTP_SSONAME'].decode('utf-8')
            # Create an ASCII compatible version of the username,
            # because OSQA/Django have bugs handling UTF8 strings in usernames.
            username = unicodedata.normalize('NFKD', utf8_username).encode('ascii', 'ignore')
            email = request.META['HTTP_SSOCONTACTMAIL']

            # Try to load the user from the database, by its email.
            user = None
            try:
                user = User.objects.get(email=email)
            except:
                pass

            if user is None:
                # The user was not found, so it must be a new user.
                # Let's create it on the database.
                user = User(username=username, email=email)
                user.email_isvalid = True
                user.set_unusable_password()
                user.save()
                UserJoinsAction(user=user, ip=request.META['REMOTE_ADDR']).save()

            # Return the User object of the authenticated user.
            return user

        else:
            raise InvalidAuthentication("Shibboleth Authentication Failure.")
开发者ID:TiagoTT,项目名称:OSQA-Shibboleth,代码行数:35,代码来源:authentication.py

示例2: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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 save [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: process_authentication_request

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
    def process_authentication_request(self, request):
        logout_request = request.POST.get('logoutRequest', None)
        if logout_request:
            if settings.CAS_LOGOUT_REQUESTS_ENABLED:
                handle_logout_request(request, logout_request)
                raise InvalidAuthentication('CAS logout request processed')
            else:
                raise InvalidAuthentication('CAS logout request ignored, disabled in configuration')

        ticket = request.GET.get('ticket', None)
        if not ticket:
            raise InvalidAuthentication(_('Login failed. CAS ticket is missing.'))

        service = service_url(request)
        username, attributes = validate(ticket, service)
        if not username:
            raise InvalidAuthentication(_('Login failed. CAS ticket is invalid.'))

        try:
            _user = User.objects.get(username=username)
            self._sync_user_attributes(_user, attributes)
        except User.DoesNotExist:
            _user = User(username=username)
            _user.set_unusable_password()
            self._sync_user_attributes(_user, attributes)
            _user.save()
            UserJoinsAction(user=_user, ip=request.META['REMOTE_ADDR']).save()

        request.session[CAS_TICKET_SESSION_ATTR] = ticket
        return _user
开发者ID:it-toolbox,项目名称:project-factory-packages,代码行数:32,代码来源:authentication.py

示例5: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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

示例6: process_authentication_request

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
    def process_authentication_request(self, request):
        username = request.POST["username"].strip()
        password = request.POST["password"]
        uid = str(settings.LDAP_USER_MASK) % username

        # an empty password will cause ldap to try an anonymous bind. This is picked up here
        if not password:
            raise InvalidAuthentication(
                _("Login failed. Please enter valid username and password (both are case-sensitive)")
            )

        ldapo = ldap.initialize(str(settings.LDAP_SERVER))
        if settings.LDAP_USE_TLS:
            ldapo.start_tls_s()
        ldapo.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
        try:
            ldapo.simple_bind_s(str(settings.LDAP_BIND_DN), str(settings.LDAP_BIND_SECRET))
            search = ldapo.search_s(str(settings.LDAP_BASE_DN), ldap.SCOPE_SUBTREE, uid)
        except ldap.LDAPError:
            # could not bind using credentials specified in ldap config
            raise InvalidAuthentication(_("Login failed - LDAP bind error. Please contact your system administrator"))

        ldapo.unbind_s()

        if not search:
            # could not find user
            raise InvalidAuthentication(
                _("Login failed. Please enter valid username and password (both are case-sensitive)")
            )

        # now try to bind as selected user; should raise exception if bind fails
        ldapo = ldap.initialize(str(settings.LDAP_SERVER))
        if settings.LDAP_USE_TLS:
            ldapo.start_tls_s()
        ldapo.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
        try:
            ldapo.simple_bind_s(search[0][1][str(settings.LDAP_DN)][0], password)
        except ldap.LDAPError:
            # could not bind as user - password is incorrect
            raise InvalidAuthentication(
                _("Login failed. Please enter valid username and password (both are case-sensitive)")
            )
        ldapo.unbind_s()

        try:
            return User.objects.get(username=username)
        except User.DoesNotExist:
            userinfo = search[0][1]
            _user = User(
                username=userinfo[str(settings.LDAP_UID)][0],
                email=userinfo[str(settings.LDAP_MAIL)][0],
                real_name=userinfo[str(settings.LDAP_NAME)][0],
            )
            _user.email_isvalid = True
            _user.set_unusable_password()
            _user.save()
            UserJoinsAction(user=_user, ip=request.META["REMOTE_ADDR"]).save()
            return _user
开发者ID:ehudtal,项目名称:osqa,代码行数:60,代码来源:authentication.py

示例7: import_users

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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

示例8: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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

示例9: register

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
def register(request):
    email = request.POST['emailRegister']
    if validateEmail(email):
        user = User(email = email,display_name = email)
        user.save();
        raw_password = randint(1000000,9999999)
        user.set_password(str(raw_password))
        user.save()
        send_mail('Welcome to Claremont Academia!','You temporary password is '+ str(raw_password) +'.', \
        '[email protected]',[email],fail_silently=False)
        return redirect('/login/')
    else: return render(request,'loginpage.html',{'invalid_email':True})
开发者ID:ClaremontAcademia,项目名称:Forum,代码行数:14,代码来源:views.py

示例10: get_openid_user

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
 def get_openid_user(cls, assoc_key):
     try:
         user_openid = lernanta.UserOpenID.objects.using(LERNANTA_DB).get(display_id__exact=assoc_key)
         lernanta_user = lernanta.UserProfile.objects.using(LERNANTA_DB).get(user=user_openid.user)
         try:
             user = User.objects.get(username=lernanta_user.username)
         except User.DoesNotExist:
             user = User(username=lernanta_user.username)
             cls.get_user_data(lernanta_user, user)
             user.save()
         return user
     except lernanta.UserOpenID.DoesNotExist, lernanta.UserProfile.DoesNotExist:
         return None
开发者ID:p2pu,项目名称:osqa-badges,代码行数:15,代码来源:backend.py

示例11: get_openid_user

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
 def get_openid_user(cls, assoc_key):
     try:
         authmap = drupal.Authmap.objects.using(DRUPAL_DB).get(authname=assoc_key)
         drupal_user = drupal.Users.objects.using(DRUPAL_DB).get(uid=authmap.uid)
         try:
             user = User.objects.get(username=drupal_user.name)
         except User.DoesNotExist:
             user = User(username=drupal_user.name)
             cls.get_user_data(drupal_user, user)
             user.save()
         return user
     except drupal.Authmap.DoesNotExist, drupal.Users.DoesNotExist:
         return None
开发者ID:jledbetter,项目名称:osqa-badges,代码行数:15,代码来源:drupal_auth_backend.py

示例12: authenticate

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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

示例13: create_user

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
def create_user(request):
    if request.method == 'POST' and request.POST['access_token'] == djsettings.BZ_QA_TOKEN:
        assoc_key = request.POST['url']
        username = request.POST['name']
        real_name = request.POST['name']
        email = request.POST['email']
        auth_provider = 'openidurl'

        user_ = User(username=username, email=email, real_name=real_name)
        user_.set_unusable_password()
        user_.email_isvalid = True
        user_.save()
        UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()

        uassoc = AuthKeyUserAssociation(user=user_, key=assoc_key, provider=auth_provider)
        uassoc.save()
 
        return HttpResponse('OK')
    else:
        raise Http404()
开发者ID:sadleb,项目名称:osqa,代码行数:22,代码来源:auth.py

示例14: update_forum_user

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [as 别名]
def update_forum_user(request):
    """ Create or Update Forum User model """

    try:
        # Customise User Model
        # username = request.user.username.split('@')[0]
        user = User.objects.get(user_ptr_id=request.user.id)
        user.user_ptr = request.user
        user.save()
    except ObjectDoesNotExist:
        obj = User()
        obj.user_ptr = request.user
        obj.email_isvalid = True

        obj.last_seen = request.user.last_login
        obj.username = request.user.username if '@' not in request.user.username else request.user.username.split('@')[0]
        obj.real_name = "%s %s" % (request.user.first_name, request.user.last_name)
        # obj.is_active = request.user.is_active
        obj.email = request.user.email
        obj.profile_image_url = request.session['profile_image'] if 'profile_image' in request.session else ''
        obj.save()
开发者ID:mahammed786,项目名称:test-repo,代码行数:23,代码来源:forum_helpers.py

示例15: authenticate

# 需要导入模块: from forum.models import User [as 别名]
# 或者: from forum.models.User import save [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


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