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


Python models.BaseUserManager类代码示例

本文整理汇总了Python中django.contrib.auth.models.BaseUserManager的典型用法代码示例。如果您正苦于以下问题:Python BaseUserManager类的具体用法?Python BaseUserManager怎么用?Python BaseUserManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: forgot_password_email

def forgot_password_email(request):
    if request.method == 'POST':
        try:
            u = User.objects.get(username=request.POST['username'])
            userProfile = UserProfile.objects.get(user = u)
        except ObjectDoesNotExist:
            u = None

        if u is not None:
            bum = BaseUserManager()
            tempPass = bum.make_random_password()
            u.set_password(tempPass)
            userProfile.hasTempPassword = True
            userProfile.save()
            u.save()
            subject = 'AC3 Forgotten Password Request'
            message = 'User: {0}\n You have requested to reset your password\nYour temporary password is: {1}' \
                      ''.format(u.username, tempPass)
            EmailMessage(subject, message, to=[u.email]).send(fail_silently=True)
            messages.add_message(request, messages.SUCCESS, 'An email has been sent!')
            return HttpResponseRedirect('/ac3app/')
        else:
            messages.add_message(request, messages.ERROR, 'The user {0} could not be found'
                                 .format(request.POST['username']))
            return HttpResponseRedirect('/ac3app/')
开发者ID:BallisticBuddha,项目名称:HomeSecurityProject,代码行数:25,代码来源:emails.py

示例2: create_user

 def create_user(self, email, password=None):
     now = timezone.now()
     email = BaseUserManager.normalize_email(email)
     user = self.model(email=email, last_login=now)
     user.set_password(password)
     user.save(using=self._db)
     return user
开发者ID:django-oscar,项目名称:django-oscar,代码行数:7,代码来源:models.py

示例3: login

def login(request):
    if request.method == 'GET':
        user = request.user
        if user.is_authenticated():
            if user.is_superuser:
                return HttpResponseRedirect(reverse('basketball:commissioner-dashboard'))
            else:
                return HttpResponseRedirect(reverse('basketball:edit-player-info', args=[user.player.pk]))
        redirect_next = request.GET.get('next', reverse('basketball:leagues'))
        context = {'error': False, 'next': redirect_next}
    elif request.method == 'POST':
        username = request.POST.get('username', '')
        password = request.POST.get('password', '')
        try:
            username = User.objects.get(email=BaseUserManager.normalize_email(username)).get_username
        except User.DoesNotExist:
            pass
        user = authenticate(username=username, password=password)
        if user is not None:
            auth_login(request, user)
            redirect_next = request.POST.get('next')
            if not redirect_next:
                redirect_next = reverse('basketball:leagues')
            return HttpResponseRedirect(redirect_next)
        else:
            context = {'error': True}

    return render(request, 'basketball/login.html', context)
开发者ID:mitchellw,项目名称:league_manager,代码行数:28,代码来源:views.py

示例4: create_user

    def create_user(self, email, is_admin=False):
        """Creates a new user based on the hash of the email address."""
        email = BaseUserManager.normalize_email()
        user_id = email_hash(email)
        user = self.model(user=user_id, is_admin=is_admin)

        user.password_notify(new=True)
        user.save(using=self._db)
        return user
开发者ID:pflarr,项目名称:games_db,代码行数:9,代码来源:auth.py

示例5: save

 def save(self, commit=True):
     print(" === save === ")
     user = super(RegisterForm, self).save(commit=False)
     user.email = BaseUserManager.normalize_email(self.cleaned_data["email"])
     if commit:
         user.save()
     return user
开发者ID:XMLPro,项目名称:ManagementSystem,代码行数:7,代码来源:userRegister.py

示例6: create_superuser

    def create_superuser(self, username, email, password, **extra_fields):
        email = BaseUserManager.normalize_email(email)
        user = self.model(username=username, email=email, is_staff=True, is_active=True, is_superuser=True)

        user.set_password(password)
        user.save(using=self._db)
        return user
开发者ID:minhuyen,项目名称:intoidi,代码行数:7,代码来源:models.py

示例7: register

    def register(self, request, **cleaned_data):
        User = compat.get_user_model()
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        user_fields = {}
        # keep non password fields
        for field in compat.get_registration_fields():
            if not field.startswith('password'):
                user_fields[field] = cleaned_data[field]
            if field == 'email':
                user_fields[field] = BaseUserManager.normalize_email(user_fields[field])
        new_user = User(is_active=False, **user_fields)
        new_user.clean()
        new_user.set_password(cleaned_data['password1'])
        new_user.save()
        attributes = models.Attribute.objects.filter(
                asked_on_registration=True)
        if attributes:
            for attribute in attributes:
                attribute.set_value(new_user, cleaned_data[attribute.name])
        registration_profile = RegistrationProfile.objects.create_profile(new_user)
        registration_profile.send_activation_email(site)

        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user
开发者ID:pu239ppy,项目名称:authentic2,代码行数:29,代码来源:views.py

示例8: create_user

    def create_user(self, username, email, password=None):
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(email=BaseUserManager.normalize_email(email), username=username, date_of_birth=datetime.date(1981,12,29))
        user.set_password(password)
        user.save(using=self._db)
        return user
开发者ID:murabo,项目名称:project,代码行数:8,代码来源:models.py

示例9: create_user

 def create_user(self, email=None, password=None, **extra_fields):
     if not email:
         raise ValueError('No email!')
     email = BaseUserManager.normalize_email(email)
     user = self.model(email=email, is_superuser=False, **extra_fields)
     user.set_password(password)
     user.save(using=self._db)
     return user
开发者ID:fallenhitokiri,项目名称:django-custom-auth,代码行数:8,代码来源:managers.py

示例10: post

    def post(self, request, *args, **kwargs):
	email = request.POST.get("email", "0")
	firstname = request.POST.get("firstname", "0")
	lastname = request.POST.get("lastname", "0")
	site = request.POST.get("site","0")
        # see if it already exists
        user=User.objects.filter(email=BaseUserManager.normalize_email(email))
        if (user):
             user = user[0]
             if user.is_active:
                 # force a new email to be sent
                 user.is_registering=True
                 user.save()
                 return HttpResponse(json.dumps({"error": "already_approved"}), content_type='application/javascript')
             else:
                 return HttpResponse(json.dumps({"error": "already_pending"}), content_type='application/javascript')

        user=User.deleted_objects.filter(email=BaseUserManager.normalize_email(email))
        if (user):
            return HttpResponse(json.dumps({"error": "is_deleted"}), content_type='application/javascript')

	user = User(
            email=BaseUserManager.normalize_email(email),
            firstname=firstname,
            lastname=lastname,
	    is_active=False,
            is_admin=False,
            is_registering=True
        )
        user.save()
	user.site=Site.objects.get(name=site)
	user.save(update_fields=['site'])
	sitePriv = SitePrivilege.objects.filter(site=user.site)
	userId = user.id
	userUrl = "http://"+request.get_host()+"/admin/core/user/"+str(userId)
	for sp in sitePriv:
		subject, from_email, to = 'Authorize OpenCloud User Account', '[email protected]', str(sp.user)
		text_content = 'This is an important message.'
		html_content = """<p>Please authorize the following user on site """+site+""": <br><br>User: """+firstname+""" """+lastname+"""<br>Email: """+email+"""<br><br>
Check the checkbox next to Is Active property at <a href="""+userUrl+"""> this link</a> to authorize the user, and then click the Save button. If you do not recognize this individual, or otherwise do not want to approve this account, please ignore this email. If you do not approve this request in 48 hours, the account will automatically be deleted.</p>"""
		msg = EmailMultiAlternatives(subject,text_content, from_email, [to])
		msg.attach_alternative(html_content, "text/html")
		msg.send()
        return HttpResponse(serializers.serialize("json",[user,]), content_type='application/javascript')
开发者ID:TDJIOLee,项目名称:xos,代码行数:44,代码来源:tenant.py

示例11: _create_user

	def _create_user(self, username, email, password, is_staff, is_superuser, **extra_fields):
		if not email:
			raise ValueError("El email es obligatorio")

		email = BaseUserManager.normalize_email(email)
		user  = self.model(username=username, email=email, is_active=True, is_staff=is_staff,is_superuser=is_superuser, **extra_fields)

		user.set_password(password)
		user.save(using=self._db)
		return user 
开发者ID:gfcarbonell,项目名称:App---ERP,代码行数:10,代码来源:models.py

示例12: create_user

        def create_user(self, username, email=None, password=None, **extra_fields):
            """
            Creates and saves a User with the given username, email and password.
            """
            email = BaseUserManager.normalize_email(email)
            user = self.model(username=username, email=email, is_staff=False, is_active=True, is_superuser=False)

            user.set_password(password)
            user.save(using=self._db)
            return user
开发者ID:abhaga,项目名称:pybbm,代码行数:10,代码来源:models.py

示例13: create_account

    def create_account(self, email, password=None, **extra_fields):
        now = timezone.now()
        if not email:
            raise ValueError('The given email must be set')
        email = BaseUserManager.normalize_email(email)

        account = self.model(email=email, last_login=now, **extra_fields)
        account.set_password(password)
        account.save(using=self._db)
        return account
开发者ID:devisio,项目名称:devisio-archive,代码行数:10,代码来源:models.py

示例14: create_user

    def create_user(self, username, email, password=None):
        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(
            username=username,
            email=BaseUserManager.normalize_email(email),
        )

        user.set_password(password)
        user.save()
        return user
开发者ID:ReadRaven,项目名称:readraven,代码行数:12,代码来源:models.py

示例15: create_user

    def create_user(self, email, password=None, **extra_fields):
        now = timezone.now()
        if not email:
            raise ValueError('The given email must be set')
        email = BaseUserManager.normalize_email(email)
        validate_email(email)
        user = self.model(email=email, is_staff=False, is_active=True, is_superuser=False,
                          joined=now, updated=now, **extra_fields)

        user.set_password(password)
        user.save(using=self._db)
        return user
开发者ID:TeaWhen,项目名称:yanshen,代码行数:12,代码来源:models.py


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