本文整理汇总了Python中auth.models.User.get_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_email方法的具体用法?Python User.get_by_email怎么用?Python User.get_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.get_by_email方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bootstrapping_via_google_accounts
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def test_bootstrapping_via_google_accounts(self):
client = Client()
# Not signed in at all? We should be redirected to a Google
# login page.
response = client.get('/auth/_bootstrap')
self.assertEqual(302, response.status_code)
# Already signed in? You should see a 403.
client.login(email='[email protected]')
response = client.get('/auth/_bootstrap')
self.assertEqual(403, response.status_code)
self.assertEqual('Already logged in', response.content)
client.logout()
# Reject people who are not superusers.
g_email = '[email protected]'
self.g_user = google_users.User(email=g_email)
self.is_superuser = False
response = client.get('/auth/_bootstrap')
self.assertEqual(403, response.status_code)
self.assertEqual('Not a chirpradio project admin', response.content)
# Create a new User object for superusers.
self.assertEqual(None, User.get_by_email(g_email))
self.is_superuser = True
response = client.get('/auth/_bootstrap')
self.assertEqual(302, response.status_code) # Redirect to login page.
user = User.get_by_email(g_email)
self.assertEqual(g_email, user.email)
# If the user already exists for the superuser, 403.
response = client.get('/auth/_bootstrap')
self.assertEqual(403, response.status_code)
self.assertEqual('User %s already exists' % g_email, response.content)
示例2: test_user_management
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def test_user_management(self):
"""
test user creation and deletion
"""
# creation
user = User.create('[email protected]', 'world')
self.assertTrue(user)
# retrieve
self.assertTrue(User.get_by_id(user.id))
self.assertTrue(User.get_by_email(user.email))
# duplicated users
self.assertFalse(User.create('[email protected]', 'world'))
try:
user2 = User(email='[email protected]', password='world')
user2.save()
except UserSaveError:
pass
else:
self.assertFalse('The user wrongly saved')
# deletion
self.assertTrue(user.delete())
user4 = User.get_by_email('[email protected]')
self.assertFalse(user4)
示例3: clean_password
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def clean_password(self):
if "email" in self.cleaned_data:
self.user = User.get_by_email(self.cleaned_data["email"])
if not self.user.password:
raise forms.ValidationError("Password not set")
if not self.user.check_password(self.cleaned_data["password"]):
raise forms.ValidationError("Incorrect password")
return self.cleaned_data["password"]
示例4: clean_email
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def clean_email(self):
self.cleaned_data["email"] = self.cleaned_data["email"].lower()
self.user = User.get_by_email(self.cleaned_data["email"])
if self.user is None:
raise forms.ValidationError("Unknown email address")
if not self.user.is_active:
raise forms.ValidationError("Account not active")
return self.cleaned_data["email"]
示例5: email
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def email(self, user):
"""
check updating and email retrieval
"""
self.assertEqual(user.email, '[email protected]')
self.assertTrue(User.get_by_email(user.email))
# change email
user.email = '[email protected]'
user.save()
self.assertEqual(user.email, '[email protected]')
self.assertTrue(User.get_by_email(user.email))
self.assertFalse(User.get_by_email('[email protected]'))
# reset email
user.email = '[email protected]'
user.save()
示例6: setUp
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def setUp(self):
from paste.deploy import appconfig
os.environ['PYRAMID_SETTINGS'] = 'development.ini#main'
self.settings = appconfig('config:{}'.format(os.environ['PYRAMID_SETTINGS']), relative_to='.')
self.config = testing.setUp(settings=self.settings)
self.created_ids = []
user = User.create('[email protected]', 'world')
self.user = User.get_by_email('[email protected]')
self.business = self.create_business()
示例7: reset
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def reset(self):
"""
clean up any remaining test users
"""
emails = ['[email protected]', '[email protected]', 'wor[email protected]']
for email in emails:
user = User.get_by_email(email)
if user:
user.delete()
示例8: edit_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def edit_user(request):
tmpl = loader.get_template('auth/user_form.html')
if request.method == 'GET':
email = request.GET.get('email')
user_to_edit = User.get_by_email(email)
user_form = auth_forms.UserForm.from_user(user_to_edit)
elif request.method == 'POST':
email = request.POST.get('email')
user_to_edit = User.get_by_email(email)
user_form = auth_forms.UserForm(request.POST)
if user_form.is_valid():
user_to_edit = user_form.to_user()
_reindex(user_to_edit)
AutoRetry(user_to_edit).save()
# When finished, redirect user back to the user list.
return http.HttpResponseRedirect('/auth/')
ctx = RequestContext(request, {
'title': 'Edit User',
'user_to_edit': user_to_edit,
'form': user_form,
})
return http.HttpResponse(tmpl.render(ctx))
示例9: reset_password
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def reset_password(request):
"""Allow a user to reset their password.
The user authenticates by presenting a security token. Users will
arrive at this page by clicking on the URL in the email they are
sent by the /auth/forgot_password page.
"""
if request.user:
return http.HttpResponseForbidden('Logged-in users prohibited.')
tmpl = loader.get_template('auth/reset_password.html')
ctx_vars = {
'Title': 'Reset Password',
}
user = None
if request.method == 'GET':
token = request.GET.get('token')
if token is None:
return http.HttpResponseForbidden('Missing token')
email = auth.parse_password_reset_token(token)
if email is None:
return http.HttpResponseForbidden('Invalid token')
ctx_vars['form'] = auth_forms.ResetPasswordForm(
initial={'token': token})
else:
form = auth_forms.ResetPasswordForm(request.POST)
if not form.is_valid():
ctx_vars['form'] = form
else:
token = form.cleaned_data['token']
email = token and auth.parse_password_reset_token(token)
if email is None:
return http.HttpResponseForbidden('Invalid token')
user = User.get_by_email(email)
if user is None:
return http.HttpResponseForbidden('No user for token')
user.set_password(form.cleaned_data['new_password'])
# We are also logging the user in automatically, so record
# the time.
user.last_login = datetime.datetime.now()
AutoRetry(user).save()
# Attach the user to the request so that our page will
# display the chrome shown to logged-in users.
request.user = user
ctx = RequestContext(request, ctx_vars)
response = http.HttpResponse(tmpl.render(ctx))
if request.user:
auth.attach_credentials(response, request.user)
return response
示例10: chirp_Client_login
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def chirp_Client_login(self, **credentials):
"""If the given credentials are valid, return a User object."""
user = None
email = credentials.get('email')
if email:
user = User.get_by_email(email)
if user is None:
user = User(email=email)
for key, value in credentials.items():
setattr(user, key, value)
user.save()
token = ''
if user:
token = auth._create_security_token(user)
self.cookies[auth._CHIRP_SECURITY_TOKEN_COOKIE] = token
if token:
return True
示例11: bootstrap
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def bootstrap(request):
"""If the visitor is a chirpradio admin, create a user for them."""
if request.user is None:
g_user = google_users.get_current_user()
if g_user is None:
return http.HttpResponseRedirect(
google_users.create_login_url(request.path))
if not google_users.is_current_user_admin():
return http.HttpResponseForbidden('Not a chirpradio project admin')
user = User.get_by_email(g_user.email())
if user:
return http.HttpResponseForbidden(
'User %s already exists' % user.email)
user = User(email=g_user.email(), is_superuser=True)
user.set_password("test")
user.save()
return http.HttpResponseRedirect(auth.create_login_url('/'))
return http.HttpResponseForbidden("Already logged in")
示例12: test_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def test_user(self):
response = self.testapp.post_json('/api/v1/users', {}, status=400)
# create new user
payload = {
'email': '[email protected]',
'password': 'hello',
}
response = self.testapp.post_json('/api/v1/users', payload, status=200)
self.assertTrue(response.json['id'])
# check duplicate
response = self.testapp.post_json('/api/v1/users', payload, status=400)
# check database
user = User.get_by_email('[email protected]')
self.assertTrue(user)
self.created.append(user)
# get user
endpoint = '/api/v1/users/{}'.format(user.id)
response = self.testapp.get(endpoint, status=200)
self.assertTrue(response.json['id'])
# update user
payload = {
'active': True,
'email': '[email protected]',
}
endpoint = '/api/v1/users/{}'.format(user.id)
response = self.testapp.put_json(endpoint, payload, status=200)
user = User.get_by_id(user.id)
self.assertTrue(user.active)
# change password
payload = {
'password': 'world',
}
endpoint = '/api/v1/users/{}/password'.format(user.id)
response = self.testapp.put_json(endpoint, payload, status=200)
user = User.authenticate_user('[email protected]', 'world')
self.assertTrue(user)
示例13: post
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def post(self):
form = self._form()
from auth.models import User
if form.validate():
email = form.email.data
pw = form.password.data
remember = form.keep_me_logged_in.data
u = User.get_by_email(email)
if u is not None:
if u.check_password(pw):
login_user(u)
if 'next' in request.args:
return redirect(request.args['next'])
else:
return self.redirect('core.index')
else:
self.flash('incorrect password')
else:
self.flash('user does not exist')
return self.redirect('auth.signup')
return self.render()
示例14: get_current_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def get_current_user(request):
"""Get the current logged-in user's.
Returns:
A User object, or None if the user is not logged in.
Raises:
UserNotAllowedError if the user is prohibited from accessing
the site.
"""
cred = None
token = request.COOKIES.get(_CHIRP_SECURITY_TOKEN_COOKIE)
if token:
cred = _parse_security_token(token)
# If this is a POST, look for a base64-encoded security token in
# the CHIRP_Auth variable.
if cred is None and request.method == 'POST':
token = request.POST.get("CHIRP_Auth")
if token:
try:
token = base64.urlsafe_b64decode(token)
except TypeError:
token = None
if token:
cred = _parse_security_token(token)
# No valid token? This is hopeless!
if cred is None:
return None
# Try to find a user for this email address.
user = User.get_by_email(cred.email)
if user is None:
return None
# Reject inactive users.
if not user.is_active:
logging.info('Rejected inactive user %s', user.email)
raise UserNotAllowedError
user._credentials = cred
return user
示例15: to_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import get_by_email [as 别名]
def to_user(self):
data = self.cleaned_data.copy()
user_roles = []
for r in roles.ALL_ROLES:
key = "is_" + r
if key in data:
if data[key]:
user_roles.append(r)
del data[key]
data["roles"] = user_roles
if data["original_email"]:
# update the user (edit form)...
user = User.get_by_email(data["original_email"])
for key, val in data.items():
# update all attributes with form values except our
# placeholder field, original_email; also handle password as a special case
if key == "password":
if val:
# only change the password if it was filled in on the edit form:
user.set_password(val)
elif key != "original_email":
setattr(user, key, val)
user.save()
else:
# creating new user...
del data["original_email"]
initial_password = None
if data["password"]:
# this is uncommon
initial_password = data["password"]
del data["password"]
user = User(**data)
if initial_password:
user.set_password(initial_password)
user.save()
return user