本文整理汇总了Python中django.contrib.auth.models.BaseUserManager.normalize_email方法的典型用法代码示例。如果您正苦于以下问题:Python BaseUserManager.normalize_email方法的具体用法?Python BaseUserManager.normalize_email怎么用?Python BaseUserManager.normalize_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.models.BaseUserManager
的用法示例。
在下文中一共展示了BaseUserManager.normalize_email方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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)
示例2: save
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例3: create_superuser
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例4: register
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例5: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例6: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例7: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例8: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例9: post
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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')
示例10: _create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例11: create_account
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例12: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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
示例14: create_user
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
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: process_request
# 需要导入模块: from django.contrib.auth.models import BaseUserManager [as 别名]
# 或者: from django.contrib.auth.models.BaseUserManager import normalize_email [as 别名]
def process_request(self, request):
django_user = get_user(request)
google_user = users.get_current_user()
# Check to see if the user is authenticated with a different backend, if so, just set
# request.user and bail
if django_user.is_authenticated():
backend_str = request.session.get(BACKEND_SESSION_KEY)
if (not backend_str) or not isinstance(load_backend(backend_str), BaseAppEngineUserAPIBackend):
request.user = django_user
return
if django_user.is_anonymous() and google_user:
# If there is a google user, but we are anonymous, log in!
# Note that if DJANGAE_FORCE_USER_PRE_CREATION is True then this may not authenticate
django_user = authenticate(google_user=google_user) or AnonymousUser()
if django_user.is_authenticated():
login(request, django_user)
if django_user.is_authenticated():
if not google_user:
# If we are logged in with django, but not longer logged in with Google
# then log out
logout(request)
django_user = AnonymousUser()
elif django_user.username != google_user.user_id():
# If the Google user changed, we need to log in with the new one
logout(request)
django_user = authenticate(google_user=google_user) or AnonymousUser()
if django_user.is_authenticated():
login(request, django_user)
# Note that the logic above may have logged us out, hence new `if` statement
if django_user.is_authenticated():
# Now make sure we update is_superuser and is_staff appropriately
is_superuser = users.is_current_user_admin()
google_email = BaseUserManager.normalize_email(google_user.email())
resave = False
if is_superuser != django_user.is_superuser:
django_user.is_superuser = django_user.is_staff = is_superuser
resave = True
# for users which already exist, we want to verify that their email is still correct
if django_user.email != google_email:
django_user.email = google_email
resave = True
if resave:
django_user.save()
request.user = django_user