本文整理匯總了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/')
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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')
示例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
示例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
示例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
示例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
示例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