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


Python User.make_unique_nickname方法代码示例

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


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

示例1: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [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:
        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()
    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember=remember_me)
    nickname = User.make_valid_nickname(nickname)
    nickname = User.make_unique_nickname(nickname)
    user = User(nickname=nickname, email=resp.email)
    return redirect(request.args.get('next') or url_for('index'))
开发者ID:omriSaadon1,项目名称:flask-blog,代码行数:27,代码来源:views.py

示例2: test_make_unique_nickname

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
	def test_make_unique_nickname(self):
		u = User(nickname = 'john', email = '[email protected]')
		models.session.add(u)
		models.session.commit()
		nickname = User.make_unique_nickname('john')
		assert nickname != 'john'
		u = User(nickname = nickname, email = '[email protected]')
		models.session.add(u)
		models.session.commit()
		nickname2 = User.make_unique_nickname('john')
		assert nickname2 != 'john'
		assert nickname2 != nickname
开发者ID:bessiec,项目名称:PlayShortFlix-Hackbright-Project,代码行数:14,代码来源:test.py

示例3: test_make_unique_nickname

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
 def test_make_unique_nickname(self):
     u = User(nickname="john", email="[email protected]")
     db.session.add(u)
     db.session.commit()
     nickname = User.make_unique_nickname("john")
     assert nickname != "john"
     u = User(nickname=nickname, email="[email protected]")
     db.session.add(u)
     db.session.commit()
     nickname2 = User.make_unique_nickname("john")
     assert nickname2 != "john"
     assert nickname2 != nickname
开发者ID:Red82,项目名称:Blog-by-Flask,代码行数:14,代码来源:tests.py

示例4: after_login

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

示例5: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
def after_login(resp):
    """After login function

    If authentication is successful, Flask-OpenID will call a function
    registered with the @oid.after_login decorator.
    """
    # The resp arg contains info returned by the OpenID provider
    if resp.email is None or resp.email == "":
        flash('Invalid login. Please try again.')
        return redirect(url_for('login'))
    # Search for user in DB by their email
    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 DIFFERENT from a Flask session
        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
    # Load 'remember_me' value from the Flask session
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(user, remember=remember_me)
    # Next page used to store page user tried to get to, but was not
    # logged in yet
    return redirect(request.args.get('next') or url_for('index'))
开发者ID:dlavelle7,项目名称:LavelleBlog,代码行数:35,代码来源:views.py

示例6: callback

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

示例7: after_login

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

        user = User(nickname=nickname, email=resp.email)
        db.session.add(user)
        db.session.commit()
        send_email("Hello %s, Welcome to Reretailer" % user.nickname,
               ADMINS[0],
               [user.email],
               render_template("registration_email.txt", 
                               user=user),
               render_template("registration_email.html", 
                               user=user))
    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:dhineshns,项目名称:reretailer,代码行数:29,代码来源:views.py

示例8: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_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_unique_nickname(nickname) #Prevent nickname duplication
        user = User(nickname=nickname, email= resp.email, role=ROLE_USER)
        db.session.add(user)
        db.session.commit()
        # make the user follow himself/herself
        db.session.add(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:josuebrunel,项目名称:microblog,代码行数:28,代码来源:views.py

示例9: facebook_authorized

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
def facebook_authorized(resp):
    next_url = request.args.get('next') or url_for('index')
    if resp is None or 'access_token' not in resp:
        flash('Invalid login. Please try again.')
        return redirect(url_for('login'))

    session['facebook_token'] = (resp['access_token'], '')

    data = facebook.get('/me').data
    if 'id' in data and 'name' in data:
        user_id = data['id']
        user_name = data['name']
    if 'email' in data:
        user_email = data['email']

    user = User.query.filter_by(facebook_id = user_id).first()

    if user is None:
        nickname = user_name
        nickname = User.make_unique_nickname(nickname)
        if user_name in ADMIN_NAMES:
            role = ROLE_ADMIN
        else:
            role = ROLE_USER
        user = User(nickname = nickname, email = user_email,facebook_id = user_id, role = role)
        db.session.add(user)
        db.session.commit()

    login_user(user)
    return redirect(request.args.get('next') or url_for('index'))
开发者ID:JrtPec,项目名称:coopkot,代码行数:32,代码来源:views.py

示例10: auth

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

示例11: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
def after_login(resp):
    if resp.email is None or resp.email == "":
        flash('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_unique_nickname(nickname)
        user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
        models.session.add(user)
        models.session.commit()
        models.session.add(user.follow(user))
        models.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('demo'))
    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('demo'))
开发者ID:bessiec,项目名称:SNAPBasket,代码行数:29,代码来源:views.py

示例12: after_login

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

示例13: after_login

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

示例14: after_login

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

示例15: after_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import make_unique_nickname [as 别名]
def after_login(resp):
    if resp.email is None or resp.email == "":  #We have asked for email
        flash('Invalid login. Please try again.')
        return redirect(url_for('login'))
    user = dboper.get_user_by_email(resp.email)             #Search the local database for the email
    if user is None:                                        #If it doesn't exist, add it
        nickname = resp.nickname
        if nickname is None or nickname == "":              #In case that nickname is empty, take of from the email
            nickname = resp.email.split('@')[0]
        nickname = User.make_unique_nickname(nickname)      #Make sure that nickname is unique
        user = User(nickname = nickname, email = resp.email, role = ROLE_USER)
        dboper.add_user(user)
        #Add default options
        dboper.set_user_option(user, config.MARK_UNREAD_ON_SCROLL_KEY, config.MARK_UNREAD_ON_SCROLL_DEFAULT)
        dboper.set_user_option(user, config.DISPLAY_READ_KEY, config.DISPLAY_READ_DEFAULT)

    remember_me = False
    if 'remember_me' in session:                             #Read 'remember_me' from the session if exists
        remember_me = session['remember_me']
        session.pop('remember_me', None)
        
    login_user(user, remember = remember_me)                #Flask-Login's function
    
    session[config.MARK_UNREAD_ON_SCROLL_KEY] = dboper.get_user_option(user, config.MARK_UNREAD_ON_SCROLL_KEY)
    session[config.DISPLAY_READ_KEY] = dboper.get_user_option(user, config.DISPLAY_READ_KEY)
    app.logger.info("read_on_scroll=%s" % session[config.MARK_UNREAD_ON_SCROLL_KEY])      
    app.logger.info("display_read=%s" % session[config.DISPLAY_READ_KEY])      
    
    return redirect(request.args.get('next') or url_for('index'))  # 'next' is the page the the user initially asked but was marked as @login_required
开发者ID:ifer,项目名称:conread,代码行数:31,代码来源:views.py


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