예제 #1
0
 def test_make_unique_nickname(self):
     u = User(username='******', email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username = User.make_unique_username('john')
     assert username != 'john'
     u = User(username=username, email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     username2 = User.make_unique_username('john')
     assert username2 != 'john'
     assert username2 != username
예제 #2
0
def after_login(resp):
    """
    review flask-openid docs if something is not clear here
    """
    if not resp.email:
        flash('Invalid login. Please try again.')
        redirect(url_for('login'))
    user = User.query.filter_by(email=resp.email).first()
    if not user:
        username = resp.nickname or resp.email.split('@')[0]
        username = User.make_unique_username(username)
        user = User(username=username, email=resp.email)
        db.session.add(user)
        db.session.commit()
    remember_me = False
    if 'remember_me' in session:
        remember_me = session.pop('remember_me')
    login_user(user, remember=remember_me)
    return redirect(request.args.get('next') or url_for('index'))