本文整理汇总了Python中models.User.make_valid_nickname方法的典型用法代码示例。如果您正苦于以下问题:Python User.make_valid_nickname方法的具体用法?Python User.make_valid_nickname怎么用?Python User.make_valid_nickname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.make_valid_nickname方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: after_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def after_login(resp):
if resp.email is None or resp.email == "":
flash(gettext('Invalid login. Please try again.'))
redirect(url_for('login'))
user = User.query.filter_by(email = resp.email).first()
if user is None:
nickname = resp.nickname
if nickname is None or nickname == "":
nickname = resp.email.split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
db.session.add(user)
db.session.commit()
# make the user follow him/herself
db.session.add(user.follow(user))
db.session.commit()
remember_me = False
if 'remember_me' in session:
remember_me = session['remember_me']
session.pop('remember_me', None)
login_user(user, remember = remember_me)
return redirect(request.args.get('next') or url_for('index'))
示例2: callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def callback():
if 'code' in request.args:
#step 2
code = request.args.get('code')
data = dict(code=code,
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
grant_type='authorization_code')
r = requests.post(token_uri, data=data)
#step 3
access_token = r.json()['access_token']
r = requests.get(profile_uri, params={'access_token': access_token})
session['email'] = r.json()['email']
user = User.query.filter_by(email = session['email']).first()
if user is None:
nickname = session['email'].split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname = nickname, email = session['email'], role = ROLE_USER)
db.session.add(user)
db.session.commit()
# make the user follow him/herself
db.session.add(user.follow(user))
db.sesstion.add(user.follow(User(nickname="liblogger.team", email="[email protected]", role = ROLE_ADMIN)))
db.session.commit()
login_user(user)
if next['URL'] == '/user':
return redirect(url_for('user', nickname = next['NICKNAME']))
else:
return redirect(url_for('index'))
else:
return 'ERROR'
示例3: after_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def after_login(resp):
# without a valid email no one can log in
if resp.email is None or resp.email == "":
flash(gettext('Invalid login. Please try again.'))
return redirect(url_for('login'))
# search database for this email
user = User.query.filter_by(email=resp.email).first()
# if we don't have this email, create a new user
if user is None:
nickname = resp.nickname
if nickname is None or nickname == "":
nickname = resp.email.split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname=nickname,
email=resp.email,
role=ROLE_USER)
db.session.add(user)
db.session.commit()
db.session.add(user.follow(user)) # make the user follow himself
db.session.commit()
# load the remember_value from the session
remember_me = False
if 'remember_me' in session:
remember_me = session['remember_me']
session.pop('remember_me', None)
# register that this is a valid login
login_user(user, remember=remember_me)
# redirect to the next page, or main page if no next specified
return redirect(request.args.get('next') or url_for('index'))
示例4: after_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def after_login(resp):
# If no email then cannot login
if resp.email is None or resp.email == "":
flash(gettext('Invalid login. Please try again.'))
return redirect(url_for('login'))
user = User.query.filter_by(email = resp.email).first()
# If email is not found then treat like new user and generate nickname from email
if user is None:
nickname = resp.nickname
if nickname is None or nickname == "":
nickname = resp.email.split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
db.session.add(user)
db.session.commit()
remember_me = False
# Check session remember_me and login user
if 'remember_me' in session:
remember_me = session['remember_me']
session.pop('remember_me', None)
login_user(user, remember = remember_me)
flash('Logged in successfully.')
return redirect(request.args.get('next') or url_for('index'))
示例5: validate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.body.data == self.original_body:
return True
if self.body.data != User.make_valid_nickname(self.body.data):
sefl.body.errors.append(gettext('This body has invalid characters. Please use letters, numbers, dots and underscores only.'))
return False
user = User.query.filter_by(body=self.body.data).first()
if user is not None:
self.body.errors.append(gettext('This body is already in use. Please choose another one.'))
return False
return True
示例6: validate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.nickname.data != User.make_valid_nickname(self.original_nickname):
self.nickname.errors.append(gettext('This nickname has invalid characters.'))
return False
if self.nickname.data == self.original_nickname:
return True
user = User.query.filter_by(nickname = self.nickname.data).first()
if user is not None:
self.nickname.errors.append(gettext('This nickname is already in use. Please choose another one.'))
return False
return True
示例7: callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def callback(self):
if 'code' not in request.args:
return None, None, None
oauth_session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': self.get_callback_url()}
)
me = oauth_session.get('me').json()
nickname = me.get('email').split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
return nickname, me.get('email')
示例8: validate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.nickname.data == self.original_nickname:
return True
if self.nickname.data != User.make_valid_nickname(self.nickname.data):
self.nickname.errors.append(gettext('This nick has invalid characters. Please use letters, numbers, spaces, underscores only.'))
return False
user = User.query.filter_by(nickname = self.nickname.data).first()
if user != None:
self.nickname.errors.append(gettext('This nickname is already in use. Might want to pick a new one m8.'))
return False
return True
示例9: validate
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def validate(self):
if not Form.validate(self):
return False
if self.nickname.data == self.original_nickname:
return True
if self.nickname.data != User.make_valid_nickname(self.nickname.data):
self.nickname.errors.append('This nickname has invalid characters. Please use letters, numbers, dots and underscores only.')
return False
user = User.query.filter_by(nickname = self.nickname.data).first()
if user != None:
self.nickname.errors.append('This nickname is already in use. Please choose another one.')
return False
return True
示例10: saveUser
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def saveUser(resp):
nickname = resp.nickname
if nickname is None or nickname == "":
nickname = resp.email.split('@')[0]
# create unique nickname
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
db.session.add(user)
db.session.commit()
# make the user follow him/herself
db.session.add(user.follow(user))
db.session.commit()
app.logger.info(' saved to database user %s ',resp.nickname)
示例11: after_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def after_login(resp):
if resp.email is None or resp.email =="":
flash("Invalid login. Please try again")
return redirect(url_for('login'))
user = User.query.filter_by(email=resp.email).first()
if user is None:
nickname = resp.nickname
if nickname is None or nickname =="":
nickname = resp.email.split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname=nickname, email=resp.email)
db.session.add(user)
db.session.commit()
#make the user follow themselves
db.session.add(user.follow(user))
db.session.commit()
remember_me = False
if "remember_me" in session:
remember_me = session["remember_me"]
session.pop("remember_me", None)
login_user(user, remember=remember_me)
return redirect(request.args.get('next') or url_for('index'))
示例12: after_login
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def after_login(response):
if response.email is None or response.email == "":
flash(gettext("Invalid login. Please try again."))
return redirect(url_for("login"))
user = User.query.filter_by(email=response.email).first()
if user is None: # email not in database, consider it as a new user
nickname = response.nickname
if nickname is None or nickname == "":
nickname = response.email.split("@")[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(nickname=nickname, email=response.email, role=ROLE_USER)
db.session.add(user)
db.session.commit()
# following self
db.session.add(user.follow(user))
db.session.commit()
remember_me = False
if "remember_me" in session:
remember_me = session["remember_me"]
session.pop("remember_me", None)
login_user(user, remember=remember_me)
return redirect(request.args.get("next") or url_for("index"))
示例13: oauth_callback
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_valid_nickname [as 别名]
def oauth_callback(provider):
if not current_user.is_anonymous():
return redirect(url_for('index'))
oauth = OAuthSignIn.get_provider(provider)
social_id, username, email = oauth.callback()
if social_id is None:
flash('Authentication failed.')
return redirect(url_for('login'))
user = User.query.filter_by(social_id=social_id).first()
if user is None:
nickname = username
if nickname is None or nickname == "":
nickname = email.split('@')[0]
nickname = User.make_valid_nickname(nickname)
nickname = User.make_unique_nickname(nickname)
user = User(social_id=social_id, nickname=nickname, email=email, role=ROLE_USER)
db.session.add(user)
db.session.commit()
# user follow himself
db.session.add(user.follow(user))
db.session.commit()
login_user(user, True)
return redirect(request.args.get('next') or url_for('index'))