本文整理汇总了Python中daimaduan.models.base.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: signup_post
def signup_post():
form = SignupForm(request.forms)
if form.validate():
user = User()
form.populate_obj(user)
user.save()
login.login_user(user.id)
send_confirm_email(app.config, user.email)
return redirect('/active_email')
return {'form': form, 'token': request.csrf_token}
示例2: send_mail_post
def send_mail_post():
form = EmailForm(request.forms)
if form.validate():
user = User.objects(email=form.email.data).first()
send_confirm_email(app.config, user.email)
return redirect('/success_sendmail')
return {'form': form}
示例3: create_paste
def create_paste():
if request.method == 'GET':
# missing csrf
form = PasteForm(data={'codes': [{'title': '', 'content': ''}]})
return render_template('pastes/create.html', form=form)
else:
form = PasteForm(request.form)
if form.validate():
user = current_user.user
paste = save_paste_and_codes(form)
if not paste.is_private:
followers = User.objects(followings=user)
content = NEW_PASTE.format(user_username=user.username,
user_url=url_for('user_app.view', username=user.username),
paste_title=paste.title,
paste_url=url_for('paste_app.view_paste', hash_id=paste.hash_id))
for follower in followers:
message = Message(user=follower,
who=user,
content=content)
message.save()
return jsonify(success=True, hash_id=paste.hash_id)
else:
errors = form.errors
errors['codes'] = [code.errors for code in form.codes]
logger.info('Failed saving paste for reason: %s', errors)
return jsonify(success=False, errors=errors)
示例4: reset_password_get
def reset_password_get(token):
email = validate_token(app.config, token)
if email:
user = User.objects(email=email).first()
if user:
return {'form': PasswordForm(), 'token': token}
abort(404)
示例5: lost_password_post
def lost_password_post():
form = EmailForm(request.forms)
if form.validate():
user = User.objects(email=form.email.data).first()
send_reset_password_email(app.config, user.email)
return redirect('/reset_password_email_sent')
return {'form': form}
示例6: validate_email
def validate_email(self, field):
if session['email']:
if session['email'] != field.data:
raise ValidationError(u'不能修改第三方登录的email地址')
user = User.objects(email=field.data).first()
if user:
raise ValidationError(u'Email地址已被使用')
示例7: validate_username
def validate_username(self, field):
if current_user.is_authenticated and current_user.user.username == field.data:
return True
user = User.objects(username=field.data).first()
if user:
raise ValidationError(u'用户名已被使用')
示例8: manage
def manage():
form = UserInfoForm(request.forms)
if form.validate():
if request.user:
request.user.username = form.username.data
return redirect('/')
else:
user = User(email=form.email.data, username=form.username.data,
is_email_confirmed=True)
user.save()
login.login_user(str(user.id))
session = get_session(request)
if 'email' in session:
del(session['email'])
return redirect('/')
return {'form': form, 'token': request.csrf_token}
示例9: manage
def manage():
form = UserInfoForm(request.form)
if form.validate():
if current_user.is_authenticated:
current_user.user.username = form.username.data
return redirect('/')
else:
user = User(email=form.email.data, username=form.username.data,
is_email_confirmed=True)
user.save()
user_mixin = LoginManagerUser(user)
login_user(user_mixin)
if 'email' in session:
del(session['email'])
return redirect('/')
return render_template('users/manage.html',
form=form)
示例10: unwatch_user
def unwatch_user(username):
be_followed_user = User.objects(username=username).first_or_404()
if be_followed_user.is_followed_by(current_user.user):
be_followed_user.followers.remove(current_user.user)
be_followed_user.save()
return jsonify(watchedStatus=be_followed_user.is_followed_by(current_user.user))
示例11: send_email
def send_email():
form = EmailForm()
if form.validate_on_submit():
user = User.objects(email=form.email.data).first()
send_confirm_email(current_app.config, user.email)
return redirect('/success_sendmail')
return render_template('sendmail.html',
form=form)
示例12: unwatch_user
def unwatch_user(username):
following_user = User.objects(username=username).first_or_404()
if current_user.user.is_following(following_user):
current_user.user.followings.remove(following_user)
current_user.user.save()
return jsonify(watchedStatus=current_user.user.is_following(following_user))
示例13: oauth_callback
def oauth_callback(provider):
current_app.logger.info("Oauth callback for %s" % provider)
redirect_uri = current_app.config['OAUTH'][provider]['callback_url']
oauth_service = get_oauth_services()[provider]
data = dict(code=request.args.get('code'),
grant_type='authorization_code',
redirect_uri=redirect_uri)
if provider == 'google':
oauth_session = oauth_service.get_auth_session(data=data, decoder=json.loads)
user_info = oauth_session.get('userinfo').json()
email = session['email'] = user_info['email']
username = user_info['given_name']
elif provider == 'github':
oauth_session = oauth_service.get_auth_session(data=data)
user_info = oauth_session.get('user').json()
email = session['email'] = user_info['email']
username = user_info['login']
access_token = oauth_session.access_token
user_info['id'] = str(user_info['id'])
current_app.logger.info("%s oauth access token is: %s" % (provider, access_token))
current_app.logger.info("%s oauth user info is %s" % (provider, user_info))
user = User.find_by_oauth(provider, user_info['id'])
if user:
# TODO: 直接登录时更新 token.
user_mixin = LoginManagerUser(user)
login_user(user_mixin)
flash(u"登录成功", category='info')
return redirect('/')
else:
user = User.objects(email=email).first()
if user:
user_oauth = UserOauth(provider=provider, openid=user_info['id'], token=access_token)
user_oauth.save()
user_mixin = LoginManagerUser(user)
login_user(user_mixin)
flash(u"登录成功", category='info')
return redirect('/')
else:
return render_template('users/finish_signup.html',
form=UserInfoForm(email=email, username=username))
示例14: view_followers
def view_followers(username):
page = get_page()
user = User.objects.get_or_404(username=username)
pagination = User.objects(followings=user).paginate(page, per_page=20)
return render_template('users/followers.html',
user=user,
pagination=pagination)
示例15: view_bookmarks
def view_bookmarks(username):
page = get_page()
user = User.objects(username=username).get_or_404()
pagination = Bookmark.objects(user=user).order_by('-updated_at').paginate(page, per_page=20)
return render_template('bookmarks/index.html',
pagination=pagination)