本文整理汇总了Python中model.user.User.insert_user方法的典型用法代码示例。如果您正苦于以下问题:Python User.insert_user方法的具体用法?Python User.insert_user怎么用?Python User.insert_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.insert_user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_insert
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def user_insert(self, request):
email = request.creator_id + "@gmail.com"
user = User.find_user_by_email(email)
if user is None:
User.insert_user(email)
print "user " + request.creator_id + " was inserted."
else:
print "user" + request.creator_id + " already exists."
return message_types.VoidMessage()
示例2: bind_account
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def bind_account(self, request):
current_user = get_endpoints_current_user(raise_unauthorized=True)
auth_source = request.auth_source
if auth_source is None:
auth_source = 'Google'
email = current_user.email()
user = User.find_user_by_email(email)
if user is not None:
user.auth_source = auth_source
user.display_name = request.display_name
user.put()
else:
User.insert_user(current_user.email(), request.display_name, auth_source)
return message_types.VoidMessage()
示例3: bind_account
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def bind_account(self, request):
if request.user_email is None:
raise endpoints.UnauthorizedException("Oops, something went wrong. Please try later.")
auth_source = request.auth_source
if auth_source is None:
auth_source = AuthSourceType.GOOGLE
email = request.user_email
user = User.find_user_by_email(email)
if user is not None:
user.auth_source = auth_source
user.display_name = request.display_name
user.put()
else:
User.insert_user(email=email, username=request.display_name)
return message_types.VoidMessage()
示例4: authenticate
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def authenticate(self, request):
email = request.user_email
validate_email(email)
team_key = request.team_key
user = User.find_user_by_email(email, team_key)
if team_key:
team_secret = request.team_secret
validate_team_secret(team_secret)
display_name = request.display_name
image_url = request.user_image_url
if not user:
user = User.insert_user(email=email, username=display_name, account_type=team_key, image_url=image_url)
community = Community.getCommunityFromTeamKey(team_key)
UserRole.insert(user, community)
elif (display_name != user.display_name) or (image_url != user.image_url):
User.update_user(user=user, email=email, username=display_name, account_type=team_key, image_url=image_url)
if not Community.authenticate(team_key, md5(team_secret)):
raise endpoints.UnauthorizedException("Authentication failed. Team key and secret are not matched.")
elif user.auth_source == AuthSourceType.ANNO:
password = request.password
validate_password(password)
if not user:
raise endpoints.NotFoundException("Authentication failed. User account " + email + " doesn't exist.")
if not User.authenticate(email, md5(password)):
raise endpoints.UnauthorizedException("Authentication failed. Email and password are not matched.")
else:
raise endpoints.ForbiddenException("Account for '%s' is Google or Facebook OAuth account." % email)
return UserMessage(id=user.key.id(), display_name=user.display_name)
示例5: create_teams
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def create_teams():
team_key = ""
app_name = ""
community_name = ""
admin_user_email = ""
other_users_email = []
app = AppInfo.query().filter(AppInfo.lc_name == app_name.lower()).get()
if not app:
appinfo_message = AppInfoMessage()
appinfo_message.name = app_name
app = AppInfo.insert(appinfo_message)
community = Community.getCommunityFromTeamKey(team_key=team_key)
if not community:
community_message = CommunityMessage(name=community_name,
team_key=team_key,
team_secret=md5(community_name.lower()))
community_message.user = UserMessage(user_email=admin_user_email)
Community.insert(community_message)
community = Community.getCommunityFromTeamKey(team_key=team_key)
if community and app:
if not app.key in community.apps:
community.apps.append(app.key)
community.put()
for user_email in other_users_email:
user = User.find_user_by_email(email=user_email, team_key=team_key)
if not user:
user = User.insert_user(user_email, account_type=team_key, image_url="")
userrole = UserRole.insert(user, community)
示例6: insert_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def insert_user(self, request):
if not is_auth_user_admin(headers=self.request_state.headers):
return ResponseMessage(success=False)
action_user = auth_user(self.request_state.headers)
user = get_user_from_request(user_id=request.user_id,
user_email=request.user_email,
team_key=request.team_key)
if not user:
user = User.insert_user(request.user_email,
username=request.user_display_name,
account_type=request.team_key,
auth_source=AuthSourceType.PLUGIN,
password=md5(request.user_password),
image_url=request.user_image_url or "")
community = Community.getCommunityFromTeamKey(request.team_key) if request.team_key else Community.get_by_id(request.community_id)
role = request.role if request.role else UserRoleType.MEMBER
resp = None
if user and community:
circle = 0
for circle_value, circle_name in community.circles.iteritems():
if circle_name == request.circle:
circle = int(circle_value)
resp = UserRole.insert(user, community, role, circle)
send_added_user_email(community.name, user.display_name, "added", action_user.display_name, community.team_hash)
return ResponseMessage(success=True if resp else False)
示例7: handle_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def handle_user(creator_id):
current_user = get_endpoints_current_user(raise_unauthorized=False)
if current_user is None:
if creator_id is not None:
user = User.find_user_by_email(creator_id + "@gmail.com")
if user is None:
user = User.insert_user(email=creator_id + "@gmail.com")
else:
email = '[email protected]'
user = User.find_user_by_email(email)
if user is None:
user = User.insert_user(email=email)
else:
user = User.find_user_by_email(current_user.email())
if user is None:
user = User.insert_user(email=current_user.email())
return user
示例8: register
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def register(self, request):
email = request.user_email
validate_email(email)
password = request.password
validate_password(password)
user = User.find_user_by_email(email)
if user is not None:
raise endpoints.BadRequestException("Email(" + email + ") already exists.")
display_name = request.display_name
if display_name is None or display_name == '':
raise endpoints.BadRequestException("Registration failed. Display name is missing.")
user = User.find_user_by_display_name(display_name)
if user is not None:
raise endpoints.BadRequestException("Display name(" + display_name + ") already exists.")
user = User.insert_user(email=email, username=display_name, password=md5(password))
return UserMessage(id=user.key.id())
示例9: auth_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def auth_user(headers):
current_user = get_endpoints_current_user(raise_unauthorized=False)
user = None
if current_user is None:
credential_pair = get_credential(headers)
signinMethod = SignInMethod.ANNO
team_key = None
team_secret = None
display_name = None
image_url = None
if len(credential_pair) == 2:
email, password = credential_pair
elif len(credential_pair) == 5:
signinMethod, email, password, team_key, team_secret = credential_pair
else:
signinMethod, email, password, team_key, team_secret, display_name, image_url = credential_pair
validate_email(email)
user = User.find_user_by_email(email, team_key)
if signinMethod == SignInMethod.ANNO:
User.authenticate(email, md5(password))
elif signinMethod == SignInMethod.PLUGIN:
if not Community.authenticate(team_key, team_secret):
raise endpoints.UnauthorizedException("Incorrect team key or secret")
display_name = unicode(display_name, "utf-8", "ignore")
if not user:
user = User.insert_user(email=email, username=display_name, account_type=team_key, image_url=image_url)
community = Community.getCommunityFromTeamKey(team_key)
UserRole.insert(user, community)
elif (display_name and display_name != user.display_name) or (image_url and image_url != user.image_url):
User.update_user(user=user, email=email, username=display_name, account_type=team_key, image_url=image_url)
else:
user = User.find_user_by_email(current_user.email())
if user is None:
raise endpoints.UnauthorizedException("Oops, something went wrong. Please try later.")
return user
示例10: insert
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import insert_user [as 别名]
def insert(cls, message, getCommunity=False):
community, user = None, None
try:
from helper.utils import get_user_from_request
if message.name is None:
return "Community name is required" if not getCommunity else (community, user)
if message.type:
# community should be of type 'private' or 'public'
if not message.type in [CommunityType.PRIVATE, CommunityType.PUBLIC]:
return "Community should be of type 'private' or 'public'" if not getCommunity else (community, user)
# only one public community is allowed
elif message.type == CommunityType.PUBLIC:
queryResultCount = Community.query(Community.type == message.type).count()
if queryResultCount:
return "Community not created. Can't create more than one public community." if not getCommunity else (community, user)
else:
message.type = CommunityType.PRIVATE
community = cls.getCommunityFromTeamKey(team_key=message.team_key)
if not community:
from helper.utils import md5
team_hash = md5(message.team_key)[-8:]
community = cls(name=message.name, description=message.description,
welcome_msg=message.welcome_msg, type=message.type,
team_key=message.team_key, team_secret=message.team_secret,
team_hash=team_hash, plan=message.plan)
community.circles = { CircleValue.CONTRIBUTOR : CircleType.CONTRIBUTOR,
CircleValue.BETA_TESTER : CircleType.BETA_TESTER,
CircleValue.ALPHA_TESTER : CircleType.ALPHA_TESTER,
CircleValue.DEVELOPER : CircleType.DEVELOPER }
community.put()
respData = "Community created."
user = get_user_from_request(user_id=message.user.id,
user_email=message.user.user_email,
team_key=message.team_key)
userrole = None
userrole_type = UserRoleType.ADMIN if message.team_key else UserRoleType.MANAGER
if (not user) and message.team_key and message.user.user_email:
from model.user import User
from helper.utils import md5
user = User.insert_user(message.user.user_email,
username=message.user.display_name,
account_type=message.team_key,
auth_source=AuthSourceType.PLUGIN,
password=md5(message.user.password),
image_url="")
if user:
from model.userrole import UserRole
userrole = UserRole.insert(user, community, userrole_type, int(CircleValue.DEVELOPER))
if userrole is None:
community.key.delete()
respData = "Community is not created as user doesn't exist"
except Exception as e:
logging.exception("Exception while inserting community: %s" % e)
respData = e
return respData if not getCommunity else (community, user)