本文整理汇总了Python中models.User.nickname方法的典型用法代码示例。如果您正苦于以下问题:Python User.nickname方法的具体用法?Python User.nickname怎么用?Python User.nickname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.nickname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oauth2_code_callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def oauth2_code_callback(oauth_port):
code = flask.request.args.get('code')
oauth_adapter = OauthAdapter(
oauth_port,
flask.current_app.config['OAUTH2_CONFIG'],
mock=MOCK_MODE
)
oauth_adapter.client.get_access_token(code)
userinfo = oauth_adapter.client.get_userinfo()
user = User.fetchone(
oauth_id=userinfo.oauth_id,
oauth_type=userinfo.oauth_type
)
if not user:
user = User()
user.oauth_id = userinfo.oauth_id
user.oauth_type = userinfo.oauth_type
user.nickname = userinfo.nickname
user.avatar = userinfo.avatar
user.oauth_id = userinfo.oauth_id
user.oauth_type = userinfo.oauth_type
user.save()
session_token = account_signin(user.to_dict())
response = flask.make_response(flask.redirect(flask.url_for('index')))
response.set_cookie('session_token', session_token['token'])
return response
示例2: signin
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def signin():
form = SigninForm()
if form.validate_on_submit():
if len(User.query.filter_by(nickname=form.nickname.data).all()) > 0:
flash(gettext("Selected username already exists!"), category='alert-danger')
return redirect(url_for('signin'))
new_email = form.email.data
check_mail = User.query.filter_by(email=new_email).all()
#user mail already exists
if len(check_mail) > 0:
flash(gettext('Selected email is already in use!'), category='alert-danger')
return redirect(url_for('signin'))
user = User()
user.nickname = form.nickname.data
user.password = generate_password_hash(form.password.data)
user.email = new_email
user.language = form.language.data
# default role is user, not admin
user.role = USER_ROLES['ROLE_USER']
db.session.add(user)
db.session.commit()
flash(gettext('Thank you for joining us!'))
return redirect(url_for('index'))
return render_template('login/signin.html',
title=gettext('Sign In'),
form=form)
示例3: sign_up
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def sign_up():
form = SignUpForm()
user = User()
if form.validate_on_submit():
user_name = request.form.get('user_name')
user_email = request.form.get('user_email')
register_check = User.login_check(user_name)
if register_check:
flash("error: The user's name already exists!")
return redirect('/sign-up')
if len(user_name) and len(user_email):
user.nickname = user_name
user.email = user_email
try:
session = Session()
session.add(user)
session.commit()
except:
flash("The Database error!")
return redirect('/sign-up')
flash("Sign up successful!")
return redirect('/index')
return render_template(
"sign_up.html",
form=form)
示例4: sign_up
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def sign_up():
form = SignUpForm()
user = User()
if form.validate_on_submit():
user_name = request.form.get('user_name')
user_email = request.form.get('user_email')
register_check = User.query.filter(db.or_(
User.nickname == user_name, User.email == user_email)).first()
if register_check:
flash("error: The user's name or email already exists!")
return redirect('/sign-up')
if len(user_name) and len(user_email):
user.nickname = user_name
user.email = user_email
user.role = ROLE_USER
try:
db.session.add(user)
db.session.commit()
except:
flash("The Database error!")
return redirect('/sign-up')
flash("Sign up successful!")
return redirect('/index')
return render_template(
"sign_up.html",
form=form)
示例5: make_superuser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def make_superuser(email, password):
from models import User
from app import db
u = User()
u.email = email
u.password = u.set_password(password=password)
u.nickname = u'관리자'
u.is_admin = True
db.session.add(u)
db.session.commit()
示例6: join_process
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def join_process():
if request.method == 'POST':
new_user = User()
new_user.email = request.form['user_email']
new_user.nickname = request.form['user_nickname']
new_user.set_password(request.form['user_password'])
new_user.is_admin = False
db.session.add(new_user)
db.session.commit()
return redirect(url_for('index'))
示例7: addUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def addUser():
form = AddUserForm()
customer_choices = [(a.id, a.name) for a in Customer.query.filter_by(customer_type=CUSTOMER_TYPES['TYPE_CUSTOMER']).all()]
customer_choices = [(0, '')] + customer_choices
maker_choices = [(a.id, a.name) for a in Maker.query.all()]
maker_choices = [(0, '')] + maker_choices
form.customer.choices = customer_choices
form.maker.choices = maker_choices
if form.validate_on_submit():
if len(User.query.filter_by(nickname=form.nickname.data).all()) > 0:
flash(gettext("Selected username already exists!"))
return redirect(url_for('users'))
new_email = form.email.data
check_mail = User.query.filter_by(email=new_email).all()
#user mail already exists
if len(check_mail) > 0:
flash(gettext('Selected email is already in use!'))
return redirect(url_for('users'))
user = User()
user.nickname = form.nickname.data
user.password = generate_password_hash(form.password.data)
user.email = form.email.data
user.role = form.role.data
if int(form.role.data) == USER_ROLES['ROLE_CUSTOMER']:
if form.customer.data and form.customer.data != '' and form.customer.data != 0:
user.customer_id = form.customer.data
else:
user.customer_id = None
elif int(form.role.data) == USER_ROLES['ROLE_MAKER']:
if form.maker.data and form.maker.data != '' and form.maker.data != 0:
user.maker_id = form.maker.data
else:
user.maker_id = None
else:
user.customer_id = None
user.maker_id = None
user.language = form.language.data
db.session.add(user)
db.session.commit()
flash(gettext("New user successfully added."))
return redirect(url_for("users"))
return render_template('settings/addUser.html',
title=gettext("Add New User"),
USER_ROLES=USER_ROLES,
form=form)
示例8: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def register():
form = RegisterForm()
if form.validate_on_submit():
u = User.query.filter_by(email=form.email.data).first()
if re.match(r"^[a-zA-Z0-9._]+\@[a-zA-Z0-9._]+\.[a-zA-Z]{3,}$", form.email.data) is None:
flash('Invalid Email address')
elif u is not None:
flash('Already Joined Email')
elif form.password.data != form.valid_password.data:
flash('Password Validation Failed.')
else:
user = User()
user.email = form.email.data
user.password = form.password.data
nickname = form.email.data.split('@')[0]
if User.query.filter_by(nickname=nickname).first() == None:
user.nickname = nickname
else:
version = 2
while True:
new_nickname = nickname + str(version)
if User.query.filter_by(nickname = new_nickname).first() == None:
break
version += 1
user.nickname = new_nickname
db.session.add(user)
db.session.commit()
# make the user follow him/herself
db.session.add(user.follow(user))
db.session.commit()
flash(user.email + ' registered successfully.')
return redirect('/login')
return render_template('register.html', title = 'Register', form = form)
示例9: registration
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def registration():
if 'user_id' in session:
return redirect(todo_main_url)
form = RegisterForm()
if request.method == "POST" and form.validate_on_submit():
new_user = User()
new_user.nickname = request.form['email'].split('@')[0]
new_user.email = request.form['email']
new_user.password = generate_password_hash(request.form['password'])
db.session.add(new_user)
db.session.commit()
flash('Try to login, dear {0}'.format(new_user.nickname))
return redirect(url_for(index))
return render_template('registration.html', form=form)
示例10: sign_up
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def sign_up():
form = SignUpForm()
if form.validate_on_submit():
nickname = request.form.get("nickname")
email = request.form.get("email")
pw = request.form.get("password")
re_pw = request.form.get("re_password")
name_email_check = User.query.filter(db.or_(User.nickname == nickname, User.email == email)).first()
if name_email_check:
flash("错误: 用户名或者邮件地址已经存在!")
return redirect(url_for("sign_up"))
pw_check = (pw != re_pw)
if pw_check:
flash("两次输入的密码不相同!")
return redirect(url_for("sign_up"))
import helperlib
if len(nickname) and len(email):
user = User()
user.nickname = nickname
user.email = email
user.password = helperlib.make_pw_hash(nickname, pw)
user.role = ROLE_USER
try:
db.session.add(user)
db.session.commit()
except:
flash("数据库错误!")
return redirect(url_for("sign_up"))
msg = Message("欢迎您来到行博", sender="[email protected]", recipients=[email])
msg.body = """欢迎您来到行博。
我是行博CEO 行云。
您注册的账户名称是:{0}
祝您开心健康每一天!""".format(nickname)
import helperlib
helperlib.send_mail_async(mail, msg)
flash("注册成功!注册邮件稍后发送至您的邮箱。")
logout_user()
return redirect(url_for("login"))
return render_template(
"sign_up.html",
form = form)
示例11: add_user
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def add_user():
with app.app_context():
username = raw_input("Username: ")
nickname = raw_input("Nickname: ")
password = raw_input("Password: ")
permission = raw_input("Permission: ")
user = User()
user.name = username
user.nickname = nickname
user.password = password
user.permission = permission
user.locked = False
user.failed_times = 0
str = user.regenerate_otp_token()
print str
示例12: register
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def register():
form = LoginForm()
if form.validate_on_submit():
user = User()
user.nickname = form.nickname.data
user.password = form.password.data
if User.query.filter_by(nickname=user.nickname).first():
flash('username exists')
return redirect(url_for('register'))
db.session.add(user)
db.session.commit()
flash('congrulations, you become an author')
login_user(user)
return redirect(url_for('index'))
return render_template('register.html',
title='sign up',
form=form,
titles=Title.fetch_non_empty_titles(Title()))
示例13: create_profile
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def create_profile():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
if not name:
flash(u'Error: you have to provide a name')
elif '@' not in email:
flash(u'Error: you have to enter a valid email address')
else:
flash(u'Profile successfully created')
user = User(nickname = name, email = email, role = ROLE_USER, last_seen = datetime.utcnow())
user.nickname = name
user.email = email
db.session.add(user)
db.session.commit()
login_user(user)
return redirect(url_for('index'))
return render_template('create_profile.html', next_url = url_for('login'))
示例14: page3
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def page3(id):
if request.method == 'POST':
user = get_user_by_id(id.hex)
if user is not None:
user.nickname = request.form['nickname']
db.session.commit()
else:
user = User(id.hex)
user.nickname = request.form['nickname']
db.session.add(user)
db.session.commit()
if user.sex is None:
next_page = 'page1'
elif user.sex == False:
next_page = 'page4'
else:
next_page = 'page8'
url = url_for(next_page, id=id)
return redirect(url)
return render_template('page3.html')
示例15: signup
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import nickname [as 别名]
def signup():
form = SignupForm()
if form.validate_on_submit():
# flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data))
user = User()
user.created_time = datetime.now()
user.email = form.email.data
user.nickname = form.username.data
user.username = form.username.data
user.password = auth.getPassword(user.username,form.password.data)
user.role = ROLE_DEFAULT
user.is_imported = False
user.status = STATUS_NORMAL
db.session.add(user)
db.session.commit()
auth.login(user,True)
flash(u'注册成功')
return redirect('/')
return render_template('usersignup.html',form=form)