コード例 #1
0
 def test_make_unique_nickname(self):
     u = User(nickname='john', email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     nickname = User.make_unique_nickname('john')
     assert nickname != 'john'
     u = User(nickname=nickname, email='*****@*****.**')
     db.session.add(u)
     db.session.commit()
     nickname2 = User.make_unique_nickname('john')
     assert nickname2 != 'john'
     assert nickname2 != nickname
コード例 #2
0
    def test_make_unique_nickname(self):
        u = User(nickname='TestUser', email='*****@*****.**')
        db.session.add(u)
        db.session.commit()
        nickname = User.make_unique_nickname('TestUser')
        assert nickname != 'TestUser'

        u = User(nickname=nickname, email='*****@*****.**')
        db.session.add(u)
        db.session.commit()
        nickname2 = User.make_unique_nickname('TestUser')
        assert nickname2 != 'TestUser'
        assert nickname2 != nickname
コード例 #3
0
ファイル: login.py プロジェクト: aert/flask-microblog
def after_login(resp):
    if resp.email is None or resp.email == "":
        flash(_('Invalid login. Please try again.'), "danger")
        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, 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_me)
    return redirect(request.args.get('next') or url_for('index.home'))