本文整理汇总了Python中models.user.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self,key):
user = User()
userInfo = UserInfo()
avatar =Avatar()
user.delete(key)
userInfo.delete(key)
avatar.delete(key)
示例2: group_member_setting
def group_member_setting(gid, memberid):
appid = request.appid
uid = request.uid
if uid != memberid:
raise ResponseMeta(400, "setting other is forbidden")
obj = json.loads(request.data)
if obj.has_key('quiet'):
User.set_group_do_not_disturb(g.rds, appid, uid, gid, obj['quiet'])
elif obj.has_key('do_not_disturb'):
User.set_group_do_not_disturb(g.rds, appid, uid, gid, obj['do_not_disturb'])
elif obj.has_key('nickname'):
Group.update_nickname(g._db, gid, uid, obj['nickname'])
v = {
"group_id":gid,
"timestamp":int(time.time()),
"nickname":obj['nickname'],
"member_id":uid
}
op = {"update_member_nickname":v}
send_group_notification(appid, gid, op, None)
else:
raise ResponseMeta(400, "no action")
resp = {"success":True}
return make_response(200, resp)
示例3: unbind_device_token
def unbind_device_token():
rds = g.rds
appid = request.appid
uid = request.uid
obj = json.loads(request.data)
device_token = obj.get("apns_device_token", "")
pushkit_device_token = obj.get("pushkit_device_token", "")
ng_device_token = obj.get("ng_device_token", "")
xg_device_token = obj.get("xg_device_token", "")
xm_device_token = obj.get("xm_device_token", "")
hw_device_token = obj.get("hw_device_token", "")
gcm_device_token = obj.get("gcm_device_token", "")
jp_device_token = obj.get("jp_device_token", "")
if not device_token and not pushkit_device_token \
and not ng_device_token and not xg_device_token \
and not xm_device_token and not hw_device_token \
and not gcm_device_token and not jp_device_token:
raise ResponseMeta(400, "invalid param")
User.reset_user_device_token(rds, appid, uid,
device_token, pushkit_device_token,
ng_device_token, xg_device_token,
xm_device_token, hw_device_token,
gcm_device_token, jp_device_token)
return make_json_response({"success":True}, 200)
示例4: createToken
def createToken(self, args):
self._start(args)
# Do a check to see if any admins exist before proceeding.
print('Create token: please authenticate...')
while True:
admin_username = raw_input('Enter admin username: ')
admin_password = getpass.getpass('Enter admin password: ')
if not User.users().get(username=admin_username).admin:
print('Please sign in using administrator credentials.')
elif not User.users().get(username=admin_username).authenticate(admin_password):
print("Username/password don't match.")
else:
break
username = raw_input('Enter username to create a token for: ')
user = User.users().get(username=username)
if user:
try:
token = Token(user=user)
token.save()
print(str('Token %s created for %s' % (token.token, username)))
except Exception as e:
print("EXCEPTION **** %s" % e)
print('A token already exists for %s. Doing nothing.' % username)
else:
print('A user with username %s does not exist.' % username)
示例5: createUser
def createUser(self, args):
self._start(args)
while True:
username = raw_input('Enter email address: ')
if User.users().get(username=username):
print('Username already exists. Please pick another username.')
else:
break
print('username: %s' % username)
while True:
is_admin = raw_input('Admininstrative user? (y/N): ')
if (len(is_admin) == 0) or (is_admin.upper() == 'N'):
admin = False
break
elif is_admin.upper() == 'Y':
admin = True
break
while True:
password_1 = getpass.getpass('Enter password: ')
password_2 = getpass.getpass('Re-enter password: ')
if password_1 != password_2:
print('Passwords do not match.')
else:
break
user = User(username, password_1, admin)
user.save()
# Db.instance().insert_user(username, password_1, admin)
print('Successfully created user %s' % username)
示例6: register_user
def register_user():
email = request.form['email']
password = request.form['password']
User.register(email, password)
return render_template('profile.html', email=session['email'])
示例7: get
def get(self):
uname = self.get_current_user()
user = User.get_user_by_name(uname)
order = get_order()
story = Story.get_by_porder(order)
sid = self.get_argument("sid",None)
if sid is not None:
story=Story.get_by_sid(sid)
article = Article.get_all_Astory(200)
usedStory = Story.get_all_story()
temp = []
for one in usedStory:
if one.porder > 0 and one.porder <= order:
temp.append(one)
usedStory = temp
reArticles = Article.get_all(200)
Rarticle = sorted(reArticles,BaseHandler.rank)
Ruser = User.get_all_user(100)
if len(Rarticle) > 6:
Rarticle=Rarticle[:6]
if len(usedStory)>3:
usedStory=usedStory[:3]
if len(Ruser)>9:
Ruser=Ruser[:9]
self.render("story.html",user=user,Rarticle=Rarticle,Article=article,usedStory=usedStory,Ruser=Ruser,story=story)
示例8: add_group_member
def add_group_member(gid):
appid = request.appid
obj = json.loads(request.data)
inviter = None
if type(obj) is dict:
if 'members' in obj:
members = obj['members']
inviter = obj.get('inviter')
else:
members = [obj]
else:
members = obj
if len(members) == 0:
return ""
group = Group.get_group(g._db, gid)
if not group:
raise ResponseMeta(400, "group non exists")
# 支持members参数为对象数组
memberIDs = map(lambda m:m['uid'] if type(m) == dict else m, members)
g._db.begin()
for member_id in memberIDs:
try:
Group.add_group_member(g._db, gid, member_id)
# 可能是重新加入群
User.reset_group_synckey(g.rds, appid, member_id, gid)
except umysql.SQLError, e:
#1062 duplicate member
if e[0] != 1062:
raise
示例9: group_member_setting
def group_member_setting(gid, memberid):
appid = request.appid
uid = memberid
group = Group.get_group(g._db, gid)
if not group:
raise ResponseMeta(400, "group non exists")
obj = json.loads(request.data)
if obj.has_key('do_not_disturb'):
User.set_group_do_not_disturb(g.rds, appid, uid, gid, obj['do_not_disturb'])
elif obj.has_key('nickname'):
Group.update_nickname(g._db, gid, uid, obj['nickname'])
v = {
"group_id":gid,
"group_name":group['name'],
"timestamp":int(time.time()),
"nickname":obj['nickname'],
"member_id":uid
}
op = {"update_member_nickname":v}
send_group_notification(appid, gid, op, None)
elif obj.has_key('mute'):
mute = 1 if obj['mute'] else 0
Group.update_mute(g._db, gid, uid, mute)
content = "%d,%d,%d" % (gid, memberid, mute)
publish_message(g.rds, "group_member_mute", content)
else:
raise ResponseMeta(400, "no action")
resp = {"success":True}
return make_response(200, resp)
示例10: from_user
def from_user(self, receivers=None, text=None, *_):
if receivers is None:
return ERR_NORECIPIENT(self.command, self.actor)
if text is None:
return ERR_NOTEXTTOSEND(self.actor)
resp = []
# TODO: check for ERR_TOOMANYTARGETS
for receiver in receivers.split(','):
if Channel.exists(receiver):
users = [user
for user in Channel.get(receiver).users
if user is not self.user]
resp.append(M(
ActorCollection(users),
self.command, str(receiver), text,
prefix=str(self.user)))
elif User.exists(receiver):
resp.append(M(
Actor.by_user(User.get(receiver)),
self.command, str(receiver), text,
prefix=str(self.user)))
# TODO: Implement wildcards
# TODO: check for ERR_WILDTOPLEVEL, RPL_AWAY, ERR_NOTOPLEVEL
else:
resp.append(ERR_NOSUCHNICK(receiver, self.actor))
return resp
示例11: client_orders_distribute
def client_orders_distribute():
if request.method == 'POST':
order_id = request.values.get('order_id', '')
operator = request.values.get('operater_ids', '')
order = ClientOrder.get(order_id)
if operator:
operater_users = User.gets(operator.split(','))
to_users = operater_users
for k in order.medium_orders:
k.operaters = operater_users
k.save()
else:
for k in order.medium_orders:
k.operaters = []
k.save()
to_users = []
if to_users:
context = {"to_users": to_users + [g.user],
"operater_users": operater_users,
"action_msg": u'分配执行人员',
"info": '',
"order": order}
outsource_distribute_signal.send(
current_app._get_current_object(), context=context)
return redirect(url_for('outsource.client_orders_distribute'))
orders = [k for k in ClientOrder.query.all() if k.medium_orders and k.contract != '']
operaters = User.gets_by_team_type(
TEAM_TYPE_OPERATER) + User.gets_by_team_type(TEAM_TYPE_OPERATER_LEADER)
return display_orders(orders, 'client_orders_distribute.html', title=u"客户订单分配", operaters=operaters)
示例12: get
def get(self):
uname = self.get_current_user()
user = User.get_user_by_name(uname)
order = get_order()
card = Card.get_by_porder(order)
cid = self.get_argument("cid",None)
if cid is not None:
card=Card.get_by_cid(cid)
article = Article.get_all_Acard(200)
usedCard = Card.get_all_card()
temp = []
for one in usedCard:
if 0 < one.porder and one.porder <= order:
temp.append(one)
usedCard = temp
reArticles = Article.get_all(200)
Rarticle = sorted(reArticles,BaseHandler.rank)
if len(Rarticle) > 6:
Rarticle = Rarticle[:6]
Ruser = User.get_all_user(100)
if len(Ruser)>9:
Ruser = Ruser[:9]
if len(usedCard)>3:
usedCard = usedCard[:3]
self.render("card.html",user=user,Rarticle=Rarticle,Article=article,usedCard=usedCard,Ruser=Ruser,card=card)
示例13: getUserObject
def getUserObject(self, user = None):
from google.appengine.api import users
from models.user import User
if user == None:
user = users.get_current_user()
userId = self.getUserId(user)
if not userId:
return None
query = User.all()
query.filter("id =", userId)
userObject = query.get()
if userObject == None:
if type(user) == users.User:
userObject = User(
id = userId,
username = user.nickname().split('@')[0],
name = user.nickname().split('@')[0]
)
else:
userObject = User(
id = userId,
username = userId,
name = userId
)
userObject.put()
return userObject
示例14: post
def post(self):
email = self.request.get('email'),
User.create_user(email, unique_properties=['email'],
password_raw=self.request.get('password'),
email=email,
name= self.request.get('name'),
image= self.request.get('image'))
示例15: _do_login
def _do_login(self, response):
username = self.get_argument("username", None)
password = self.get_argument("password", None)
if not username or not password:
# do something
self.flash.error = "You must enter a username and password to proceed. Please try again."
return
pw = hashlib.sha1(password).hexdigest()
username = User.normalize(username)
user = User.lookup(username)
#check the password.
if not user or user['password'] != pw:
# do something
self.flash.error = "Login not valid"
return
# check if user is suspended.
if user.is_suspended() :
self.flash.error = "Sorry the account you specified has been suspended."
return
user.history.last_login = datetime.datetime.utcnow()
Mongo.db.ui['users'].update({'_id': username}, {
'$set' : {'history.last_login': user.history.last_login},
'$inc' : {'history.num_logins' : 1}
})
#add to the session.
self.session['username'] = user._id
#check keep_logged_in
if self.get_argument("keep_logged_in", False) == "on" :
self.session['keep_logged_in'] = True
self.set_current_user(user)
# self.session['current_user']= user._id
self.flash.notice = "Welcome, %s" % user._id
self.write(username)
self.finish("finished")