本文整理汇总了Python中model.User.get_by_email方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_email方法的具体用法?Python User.get_by_email怎么用?Python User.get_by_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.get_by_email方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def post(self):
user = self.get_user()
if not user:
return
user_email = self.request.get('user_email')
query_id = self.request.get('query_id')
csv_data = self.request.get('csv_data')
user = User.get_by_email(user_email)
query = Query.get_by_id(query_id)
for duple in self.parse_csv_data(csv_data):
timestamp = duple[0]
text = duple[1]
# for testing
self.response.out.write("<p>%s: %s\n</p>" % (timestamp, text))
dp = DataPoint(
timestamp = duple[0],
query = query,
text = duple[1])
dp.lt_put()
self.redirect('/data')
示例2: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def post(self):
user = self.get_user()
if not user:
return
user_email = self.request.get('user_email', None)
phone = self.request.get('phone_number', None)
medium = self.request.get('medium', None)
first_time = self.request.get('first_time', None)
user = User.get_by_email(user_email)
if phone != None and len(phone) == 10:
# need to check that no one has this phone number yet
# also, validate the phone number somewhat
user.phone = phone
if medium != None:
medium = medium.lower()
if medium == 'sms' or medium == 'email':
user.query_medium = medium
user.put()
if first_time != None and user.phone != None:
self.first_time_message(user)
self.response.out.write('success')
示例3: test_password_reset
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def test_password_reset(self):
user = User.get_by_email(self.email)
old_password = user.password
self.admin_client.user.request_reset_password(self.email)
self.assertEquals(len(mail.outbox), 1)
new_password = "new_password12345"
token = self.do_password_reset_from_email(new_password)
self.assertNotEqual(old_password, User.get_by_email(self.email).password)
# ensure token is no longer active
with self.expect_error(errors.PasswordResetTokenInvalid):
self.admin_client.user.reset_password_valid(token)
with self.expect_error(errors.PasswordResetTokenInvalid):
self.admin_client.user.reset_password(token, new_password)
self.admin_client.user.request_reset_password(self.email)
with self.expect_error(errors.PasswordResetTokenInvalid):
self.do_password_reset_from_email("1")
示例4: receive
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def receive(self, mail_message):
# we need to make a new data point
# get the user from the sender field
user_email = mail_message.sender[ mail_message.sender.find('<') + 1 : mail_message.sender.rfind('>') ]
user = User.get_by_email(user_email)
if is_admin(user) and mail_message.to.find('[email protected]') != -1:
forward_to_users(mail_message)
return
if mail_message.to.find('[email protected]') != -1:
forward_to_admins(mail_message)
return
# get the datapoint from the body
data = ''
query_name = mail_message.subject[ mail_message.subject.rfind("Re:") + 4: ]
query = Query.get_by_user_and_name(user, query_name)
for content_type, body in mail_message.bodies('text/html'):
# basically deprecated, since we're having users submit forms
# straight from the emails now.
logging.info('Message Body: ' + body.decode())
data = body.decode()[ : body.decode().find('<')]
if data == None:
data = ''
# get the time from now()
timestamp = datetime.now()
log_str = "Want to create a new datapoint for user %s and with value %s and query name %s and query %s and timestamp %s" % (user_email, data, query_name, query.key(), timestamp)
logging.info("Received a message from " + mail_message.sender)
logging.info(log_str)
# create and put the datapoint
# dp = DataPoint(...)
dp = DataPoint(
text = data,
query = query,
timestamp = timestamp)
dp.lt_put()
ActionLog.log('ReceivedEmail')
ActionLog.log('NewDatapoint', data=query.name, user=user)
query.refresh()
示例5: get_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def get_user(self, invite_code_name=None):
user = None
google_user = users.get_current_user()
# not logged in to google
if google_user == None:
self.redirect(users.create_login_url(self.request.uri))
return None
user = User.get_by_google_user(google_user)
# user was not in our database, so its a first-time login
if user == None:
user = User(google_user = google_user,
first_name='',
last_name='',
email=google_user.email()
)
user.put()
# now we have a user, but are they whitelisted
# or do they have an invite?
if invite_code_name != None:
invite_code = InviteCode.get_by_name(invite_code_name)
# is this code valid?
if invite_code != None and invite_code.use_code() == True:
user.is_whitelisted = True
user.put()
else:
user = None
elif user.is_whitelisted != True:
user = None
# this enables admins to see pages in any user's context
if self.request.get('admin', None) == 'true' and user.email in admins:
user_email = self.request.get('user_email')
user = User.get_by_email(user_email)
# if we've gotten this far and the user is none, it means this user is
# not whitelisted
if user == None:
self.redirect(users.create_logout_url('/no-invite'))
return user
示例6: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def get(self):
user = self.get_user()
if not user:
return
user_email = self.request.get('user_email')
user = User.get_by_email(user_email)
queries = Query.get_by_user(user)
query_ids = []
for query in queries:
query_ids.append(str(query.key()))
self.response.out.write(json.dumps(query_ids))
示例7: registration_process
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def registration_process():
"""Process registration."""
email = request.form["register-email"]
password = request.form["password"]
if User.get_by_email(email):
flash("That email is already registered. ")
flash("Please register with a different email.")
print "email already taken"
return redirect("/")
User.add(email, password)
flash("Registration successful. Welcome %s!" % email)
return render_template("homepage.html")
示例8: send_password_reset_email
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def send_password_reset_email(email, base_url, for_new_user=False):
from task.mail import send_email
user = User.get_by_email(email, include_deleted=False)
if user is None:
raise errors.UserNotFound()
token = PasswordResetToken.create(user)
url = urljoin(base_url, posixpath.join(UserApi.ADMIN_FRONTEND_PATH,
"set-password/{}".format(token.id)))
template_id = MessageTemplate.NEW_USER if for_new_user else MessageTemplate.USER_PASSWORD_RESET
url_name = "activate_url" if for_new_user else "password_reset_url"
params = {url_name: url}
subject, body = MessageTemplate.get_rendered_message(template_id, language=preferred_language(),
user_name=user.name, **params)
send_email.delay(email, subject, body)
return user
示例9: validate_token
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def validate_token(self, *args, **kwargs):
token = self['token']
if not token:
return self.write(json.dumps({'errors' : [INVALID_TOKEN]}), 401, APP_JSON)
email = memcache.get(token)
if not email:
token_obj = Token.get_by_key_name(token)
if not token_obj:
return self.write(json.dumps({'errors' : [INVALID_TOKEN]}), 401, APP_JSON)
memcache.set(token, token_obj.user.email)
self.user = token_obj.user
else:
self.user = User.get_by_email(email)
if not self.user:
return self.write(json.dumps({'errors' : [INVALID_TOKEN]}), 401, APP_JSON)
if not check_ratelimit(self, token):
return self.write(json.dumps({'errors' : [RATE_EXCEEDED]}),
503, APP_JSON)
return handler_method(self, *args, **kwargs)
示例10: login_process
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def login_process():
"""Process login."""
email = request.form["email"]
password = request.form["password"]
user = User.get_by_email(email)
if not user:
flash("No such user")
return redirect("/")
if user.password != password:
flash("Incorrect password")
return redirect("/")
session["user_id"] = user.user_id
flash("Logged in. Welcome %s!" % email)
return render_template("homepage.html")
示例11: admin_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import get_by_email [as 别名]
def admin_user(self):
return User.get_by_email("[email protected]")