本文整理汇总了Python中model.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clientRegister
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def clientRegister(self, data):
try:
rdata = {}
username = data['username']
if not username:
self.sendAPI(1,447,'Value empty')
return
if not isinstance(username, basestring):
self.sendAPI(1,448,'Value is wrong data type')
return
if len(username) > 50:
self.sendAPI(1,449,'Value exceeds maximum input length')
return
user = User(username)
if user.exist():
self.sendAPI(1,441,'Credentials already exist')
return
user.token = self.getNewToken()
user.password = self.getNewPassword()
user.save()
rdata['password'] = user.password
self.sendAPI(0,241,'User registered',rdata)
except (KeyError, TypeError):
self.sendAPI(1,401,'Not in reference format')
示例2: POST
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def POST(self):
if web.ctx.session.get('loggedin',0) == 1:
userid = web.ctx.session.get('userid',-1)
superuser = is_superuser(userid)
username = get_username(userid)
request = web.input()
old_password = request.old_password
new_password = request.new_password
new_password_confirm = request.new_password_confirm
if new_password != new_password_confirm:
msg = "Password doesn't match the confirmation"
error = True
elif len(new_password) < 6:
msg = "Password too short"
error = True
else:
user = User(username=username, password=old_password)
if user.is_authenticated() == True:
user.set_passwd(new_password)
user.save(update=True)
msg = "PassWord Changed"
error = False
else:
msg = "Old PassWord Error"
error = True
ctx = Storage(locals())
return render_fluid.change_passwd(ctx)
示例3: authorized
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def authorized(resp):
if resp is None:
return 'Access denied: reason=%s error=%s' % (
request.args['error_reason'],
request.args['error_description']
)
# Save token to the session for the immediately following gmail request
session['gmail_token'] = (resp['access_token'], )
# Check if that user already exists in the db
gmail_user = gmail.get('userinfo')
try:
postal_user = (db_session.query(User)
.filter_by(email_address=gmail_user.data['email'])
.one())
# Choosing to just update the token the db
postal_user.save_new_token(resp['access_token'])
session['user_email'] = gmail_user.data['email']
session['user_id'] = postal_user.id
except sqlalchemy.orm.exc.NoResultFound, e:
# If a new user, save them to the db
postal_user = User(name=gmail_user.data['name'],
email_address=gmail_user.data['email'],
access_token=resp['access_token'])
postal_user.save()
session['user_email'] = gmail_user.data['email']
session['user_id'] = postal_user.id
示例4: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def post(self):
#if self.get_current_user():
# self.redirect("/")
# return
mobile = self.get_argument("mobile", None)
password = self.get_argument("password", None)
apassword = self.get_argument("apassword", None)
vcode = self.get_argument("vcode", None)
sharer = self.get_argument("sharer", None)
realname=self.get_argument("realname",None)
user = User()
user.mobile = mobile
user.realname = realname
user.password = User.create_password(password)
try:
user.validate()
if password and apassword:
if len(password) < 6:
self.flash("请确认输入6位以上新密码")
elif password != apassword:
self.flash("请确认新密码和重复密码一致")
elif len(realname) > 32:
self.flash("微信账号超出长度限制")
elif len(realname) < 2:
self.flash("微信账号太短")
else:
#if UserVcode.select().where((UserVcode.mobile == mobile) & (UserVcode.vcode == vcode)).count() > 0:
# UserVcode.delete().where((UserVcode.mobile == mobile) & (UserVcode.vcode == vcode)).execute()
user.save()
user.updatesignin()
self.session['user'] = user
if 'oauth' in self.session:
oauth = self.session['oauth']
o = Oauth()
o.uid = user.id
o.openid = oauth['id']
o.src = oauth['src']
o.save()
del self.session['oauth']
self.session.save()
User.update(credit = User.credit + 1).where(User.mobile == mobile).execute()
#if sharer != None
User.update(credit = User.credit + 1).where(User.mobile == sharer).execute()
self.flash("注册成功,请先登录。", "ok")
url="/signup?sharer="+user.mobile
self.redirect(url,permanent=True)
return
#else:
# self.flash("请输入正确的验证码")
else:
self.flash("请输入密码和确认密码")
except Exception, ex:
self.flash(str(ex))
示例5: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def register(email, pwd):
exists = User.objects(email=email)
if len(exists):
return {'success':False, 'error':'exists user'}
user = User(email=email)
user.password = User.encrypted_password(pwd)
user.save()
login_user(user)
return {'success': True}
示例6: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def post(self):
if self.get_current_user():
self.redirect("/")
return
mobile = self.get_argument("mobile", None)
password = self.get_argument("password", None)
apassword = self.get_argument("apassword", None)
vcode = self.get_argument("vcode", None)
sharer = self.get_argument("sharer", None)
openid = self.get_argument("openid", None)
user = User()
user.mobile = mobile
user.openid = openid
print openid
user.password = User.create_password(password)
try:
user.validate()
if password and apassword:
if len(password) < 6:
self.flash("请确认输入6位以上新密码")
elif password != apassword:
self.flash("请确认新密码和重复密码一致")
else:
if UserVcode.select().where((UserVcode.mobile == mobile) & (UserVcode.vcode == vcode)).count() > 0:
UserVcode.delete().where((UserVcode.mobile == mobile) & (UserVcode.vcode == vcode)).execute()
user.save()
if 'oauth' in self.session:
oauth = self.session['oauth']
o = Oauth()
o.uid = user.id
o.openid = oauth['id']
o.src = oauth['src']
o.save()
del self.session['oauth']
self.session.save()
print sharer
User.update(credit = User.credit + 1).where(User.mobile == mobile).execute()
#if sharer != None
User.update(credit = User.credit + 1).where(User.mobile == sharer).execute()
self.flash("注册成功,请先登录。", "ok")
self.redirect("/signin")
return
else:
self.flash("请输入正确的验证码")
else:
self.flash("请输入密码和确认密码")
except Exception, ex:
self.flash(str(ex))
示例7: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def register():
if current_user.is_authenticated():
return redirect(url_for('index'))
form = RegistrationForm()
if form.validate_on_submit():
user = User()
form.populate_obj(user)
user.save()
login_user(user)
return redirect(url_for('index'))
else:
flash_errors(form)
return render_template('register.html', form=form)
示例8: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def register():
s = request.environ.get('beaker.session')
data = s.get('user.data', defaultdict(str))
print(data)
for key in ['username', 'first_name', 'last_name', 'middle_name', 'study_group',
'email', 'phone_number', 'skype', 'icq', 'password1', 'password2']:
data[key] = request.forms.get(key).encode("ISO-8859-1").decode("utf-8")
print(data)
errors = []
if "errors" in s:
del s["errors"]
if "user.data" in s:
del s['user.data']
user = User.objects(username=data['username']).first()
if user is not None:
errors.append('Login is already in use')
if data['password1'] != data['password2']:
errors.append("Passwords don't match")
if data['password1'] == '':
errors.append('Password required')
if data['first_name'] == '':
errors.append('First name is required')
if data['last_name'] == '':
errors.append('Last name is required')
if len(errors) == 0:
user = User()
user.from_dict(data)
user.save()
start_session(user)
redirect('/account')
else:
print(errors)
s["user.data"] = data
s["errors"] = errors
redirect('/register')
示例9: user_save
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def user_save():
user = User()
user.from_request(request)
if not check_login(user["username"]):
return register_view(err="Wrong login" + user["username"])
pass1 = request.forms.get("password1")
pass2 = request.forms.get("password2")
if not check_password(pass1, pass2):
return register_view(err="Wrong password '" + pass1 + "' '" + pass2 + "'")
user.save()
redirect("/account")
示例10: register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def register():
form = RegisterForm()
if form.validate_on_submit():
user = User(email=form.email.data,
username=form.username.data)
user.password = form.password.data
user.save()
token = user.generate_confirmation_token()
send_email(current_user.email, "Confirm your email", "email/confirm",
user=current_user, token=token)
# send_async_email(current_user.email, "Confirm your email", "email/confirm",
# user=current_user, token=token)
flash("A confirmation email has been sent to your email.")
return redirect(url_for("login"))
return render_template("register.html", form=form)
示例11: api_register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def api_register(*, name, email, passwd):
r = web.Response()
if not name or not name.strip():
raise APIValueError('name')
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?', [email])
if len(users) > 0:
result = APIResult(0, '', 'Email is already in use.')
else:
sha1_passwd = '%s:%s' % ('hearain', passwd)
user = User(name=name.strip(),
email=email,
password=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
logo='http://www.gravatar.com/avatar/%s?d=wavatar&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest()
)
id = yield from user.save()
#设置session
config['_session'][user.email] = user2cookie(user, 86400)
setWebCookie(r, 'user', config['_session'][user.email])
setWebCookie(r, 'email', user.email)
setWebCookie(r, 'id', id)
setWebCookie(r, 'name', user.name)
result = APIResult(1, '', '')
return jsonResult(r, result)
示例12: userRegister
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def userRegister(username, password, mail):
print "%s tries to login or register" % username
user_object = User.objects(uname = username)
if len(user_object) == 0:
try:
user_object = User(ID = User.objects.count() + 1, uname = username, mail = mail, \
password = password, confidence = 0.8, level = 0, taskCount = 0)
except Exception as e:
print e
return 0
user_object.save()
print "A new user %s has just registered" % username
return 1
else:
print "Username %s exists!" % username
return 2
示例13: api_register_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def api_register_user(*,email,name,passwd):
logging.info('comming into register post users')
if not name or not name.strip():
raise APIValueError('name')
if not name or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?',[email])
if len(users) > 0 :
raise APIError('register:failed','email','Email is already in use.')
uid = next_id()
sha1_passwd = '%s:%s' %(uid,passwd)
user = User(id=uid,name=name.strip(),email=email,passwd=hashlib.sha1(
sha1_passwd.encode('utf-8')).hexdigest(),image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
yield from user.save()
#make session cookie from here:
r = web.Response()
r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
return r
示例14: reply_game
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def reply_game(**kwargs):
from model import User
username = kwargs.get('sender')
sender = kwargs.get('receiver')
message_type = kwargs.get('type')
content = kwargs.get('content', message_type)
user = User.objects(open_id = username)
if len(user) == 0:
user = User()
user.open_id = username
user.save()
if message_type == 'text':
return weixin.reply(
username, sender=sender, content=u'回复\"猜数字\"开始按照GUNNER提示进行猜数字!')
示例15: adduser
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import save [as 别名]
def adduser(_=None):
create_tables()
username = raw_input('Username:')
user = None
try:
user = User.get(name=username)
except User.DoesNotExist:
pass # ok
if user:
sys.exit("The username has been already used.")
password = getpass.getpass()
user = User(name=username, password=password)
user.save()
print("The user was created successfully.")
database.close()