当前位置: 首页>>代码示例>>Python>>正文


Python User.follow方法代码示例

本文整理汇总了Python中models.User.follow方法的典型用法代码示例。如果您正苦于以下问题:Python User.follow方法的具体用法?Python User.follow怎么用?Python User.follow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.follow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: callback

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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'
开发者ID:Syntaf,项目名称:flask-liblogger,代码行数:35,代码来源:views.py

示例2: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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_unique_nickname(nickname)
        user = User(nickname=nickname, email=resp.email)
        db.session.add(user)
        db.session.commit()
        # make the user follow him/herself
        db.session.add(user.follow(user))
        db.session.commit()
    # when user has not self, then follow self
    if len(user.followed.all()) == 0:
        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'))
开发者ID:doyeonOh,项目名称:flask_tutorial,代码行数:29,代码来源:views.py

示例3: test_follow_posts

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
 def test_follow_posts(self):
     # make four users
     u1 = User(nickname="john", email="[email protected]")
     u2 = User(nickname="susan", email="[email protected]")
     u3 = User(nickname="mary", email="[email protected]")
     u4 = User(nickname="david", email="[email protected]")
     db.session.add(u1)
     db.session.add(u2)
     db.session.add(u3)
     db.session.add(u4)
     # make four posts
     utcnow = datetime.utcnow()
     p1 = Post(body="post from john", author=u1, timestamp=utcnow + timedelta(seconds=1))
     p2 = Post(body="post from susan", author=u2, timestamp=utcnow + timedelta(seconds=2))
     p3 = Post(body="post from mary", author=u3, timestamp=utcnow + timedelta(seconds=3))
     p4 = Post(body="post from david", author=u4, timestamp=utcnow + timedelta(seconds=4))
     db.session.add(p1)
     db.session.add(p2)
     db.session.add(p3)
     db.session.add(p4)
     db.session.commit()
     # setup the followers
     u1.follow(u1)  # john follows himself
     u1.follow(u2)  # john follows susan
     u1.follow(u4)  # john follows david
     u2.follow(u2)  # susan follows herself
     u2.follow(u3)  # susan follows mary
     u3.follow(u3)  # mary follows herself
     u3.follow(u4)  # mary follows david
     u4.follow(u4)  # david follows himself
     db.session.add(u1)
     db.session.add(u2)
     db.session.add(u3)
     db.session.add(u4)
     db.session.commit()
     # check the followed posts of each user
     f1 = u1.followed_posts().all()
     f2 = u2.followed_posts().all()
     f3 = u3.followed_posts().all()
     f4 = u4.followed_posts().all()
     assert len(f1) == 3
     assert len(f2) == 2
     assert len(f3) == 2
     assert len(f4) == 1
     assert f1 == [p4, p2, p1]
     assert f2 == [p3, p2]
     assert f3 == [p4, p3]
     assert f4 == [p4]
开发者ID:Red82,项目名称:Blog-by-Flask,代码行数:50,代码来源:tests.py

示例4: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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()

        # Make the user follow him/herself
        db.session.add(user.follow(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)

    return redirect(request.args.get('next') or url_for('index'))
开发者ID:nyghtowl,项目名称:Flask_Mega,代码行数:33,代码来源:views.py

示例5: sign_up

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def sign_up():
    form = SignUpForm()
    user = User()
    if form.validate_on_submit():
        user_name = request.form.get('user_name')
        password = request.form.get('password')
        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.password = password
            user.email = user_email
            user.role = ROLE_USER
            try:
                db.session.add(user)
                db.session.add(user.follow(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)
开发者ID:qdzzyb2014,项目名称:flask-weibo,代码行数:33,代码来源:views.py

示例6: auth

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def auth(provider_name):
	print "user made response"
        response = make_response()
        result = authomatic.login(WerkzeugAdapter(request, response), provider_name)
        if result:
		print "result has been made"
                if result.user:
                        result.user.update()
                #return redirect(request.args.get('next') or url_for('index', result == result))
		if result.user.email is None or result.user.email =="":
                	flash('Invalid Login. Please try again.')
                	return redirect(url_for('login'))
        	user = User.query.filter_by(email = result.user.email).first()
        	if user is None:
			print "user is none"
                	nickname = result.user.name
                	if nickname is None or nickname == "":
                        	nickname = result.user.email.split('@')[0]
                	nickname = User.make_unique_nickname(nickname)
			user = User(nickname = nickname, email = result.user.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()
			print "put user in a database"
		print "trying to log user in"
		login_user(user)
		print "logged user in"
        	return redirect(url_for('index'))
	return response
开发者ID:kenjinp,项目名称:microblog,代码行数:33,代码来源:views.py

示例7: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def after_login(resp):
    # check valid email
    print resp.email
    if resp.email is None or resp.email == "":
        flash('Invalid login. Please, try again.')
        return redirect(url_for('login'))
    
    # login logic for signup or signin
    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]
        # signup
        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'))
开发者ID:lolongcovas,项目名称:microblog,代码行数:29,代码来源:views.py

示例8: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def after_login(resp):
  """
  Callback after authentication using Flask-OpenID

  Args:
    resp: response from OpenID provider
  """
  if resp.email is None or resp.email == '':
    flash('ERROR: Invalid login. Please try again.')
    return redirect(url_for('login'))
  user = User.query.filter_by(email=resp.email).first()
  if user is None:
    # no such user, create a new user
    nickname = resp.nickname
    if nickname is None or nickname == '':
      # could not get nickname from OpenID provider
      # get a nickname from the email address
      nickname = resp.email.split('@')[0]
    # make the nickname unique
    nickname = User.make_unique_nickname(nickname)
    # create a new user and add to database
    user = User(nickname=nickname, email=resp.email, role=ROLE_USER)
    db.session.add(user)
    db.session.commit()
    # make every new user follow himself
    # so that a user's posts appear on his feed
    user = user.follow(user)
    db.session.add(user)
    db.session.commit()
  remember_me = False
  if 'remember_me' in session:
    remember_me = session['remember_me']
    session.pop('remember_me', False)
  login_user(user, remember=remember_me)  # register this is a valid login
  return redirect(request.args.get('next') or url_for('index'))
开发者ID:bhsaurabh,项目名称:microblog,代码行数:37,代码来源:views.py

示例9: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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'))
开发者ID:mosbasik,项目名称:microblog,代码行数:37,代码来源:views.py

示例10: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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_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(url_for('user', nickname=user.nickname))
开发者ID:frimmy,项目名称:microblog,代码行数:33,代码来源:views.py

示例11: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def after_login(resp):
    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 user is None:
        username = resp.username
        if username is None or username == "":
            username = resp.email.split('@')[0]

        username = User.make_valid_username(username)
        username = User.make_unique_username(username)
        user = User(username=username, email=resp.email)
        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'))
开发者ID:jmjuanico,项目名称:likereader,代码行数:28,代码来源:views.py

示例12: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def after_login(resp):
    if resp.identity_url is None or resp.identity_url == "":
        flash(_('Invalid login. Please try again'))
        return redirect(url_for('login'))
    user = User.query.filter_by(identity_url = resp.identity_url).first()
    if user is None:
        nickname = resp.nickname
        email = resp.email
        if nickname is None or nickname == "":
            if email is None or email == "":
                nickname = resp.identity_url.strip("/").split("/")[-1]
            else:
                nickname = resp.email.split('@')[0]

        nickname = User.make_unique_nickname(nickname)

        user = User(identity_url = resp.identity_url, 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'))
开发者ID:recfab,项目名称:learn-flask,代码行数:30,代码来源:views.py

示例13: login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def login():

    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form_l = LoginForm()
    form_s = SignUpForm()

    if form_l.validate_on_submit() and (len(form_l.openid.data) < 100) and (len(form_l.password.data) < 100):
        session['remember_me'] = form_l.remember_me.data
        user = db.session.query(User).filter(User.email == form_l.openid.data).filter(User.password == md5(form_l.password.data).hexdigest()).first()
        if user is not None:
            login_user(user, remember = form_l.remember_me.data)
            return redirect(url_for('index')) 
        else: 
            print("NOT FOUND")
        
    if form_s.validate_on_submit() and (len(form_s.email.data) < 100) and (len(form_s.login.data) < 50) and (len(form_s.password.data) < 100):
        k = False
        user = db.session.query(User).filter(User.email == form_s.email.data  or  User.nickname == form_s.login.data).first()
        if user is None:
            u = User(nickname=form_s.login.data, email=form_s.email.data, password=md5(form_s.password.data).hexdigest())
            db.session.add(u)
            db.session.commit()
            db.session.add(u.follow(u))
            db.session.commit()
            login_user(u)
            return redirect(url_for('index')) 
        else:
            print("EXISTS")
             
    return render_template('login1.html',
        form_l = form_l,
        form_s = form_s)
开发者ID:charepushko,项目名称:microblogging,代码行数:35,代码来源:views.py

示例14: authorized

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [as 别名]
def authorized():
    if not current_user.is_anonymous:
        return redirect(url_for('index'))
    resp = weibo.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    session['oauth_token'] = (resp['access_token'], '')
    social_id = resp['uid']
    if social_id is None:
        flash('Authentication failed.')
        return "social_id is none"
    #access_token = resp['access_token']
    resp = weibo.get('users/show.json', {'uid' : social_id})
    username = resp.data['screen_name']
    user = User.query.filter_by(social_id=social_id).first()
    if not user:
        user = User(social_id=social_id, nickname=username)
        db.session.add(user)
        db.session.add(user.follow(user))
        db.session.commit()
    login_user(user, True)
    return redirect(url_for('index'))
开发者ID:clown139880,项目名称:YggDraSil,代码行数:27,代码来源:views.py

示例15: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import follow [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:
        # This is a new user, add then to the DB
        nickname = resp.nickname
        if nickname is None or nickname == "":
            nickname = resp.email.split('@')[0]
        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)

    # Log the user in - this will create a flask session
    login_user(user, remember = remember_me)
    return redirect(request.args.get('next') or url_for('index'))
开发者ID:jettagozoom,项目名称:microblog,代码行数:28,代码来源:views.py


注:本文中的models.User.follow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。