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


Python User.username方法代码示例

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


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

示例1: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
    def get(self):
        if self.request.get('userid'):
            user_info = flickr.FlickrUserInfo("", self.request.get('userid'), self.request.get('userid'), "")
        else:
            frob = self.request.get('frob')                        
            
            try:
                user_info = flickr.get_user_info(frob)
            except:
                user_info = flickr.get_user_info(frob)                
        
    
        user = User.get_by_key_name(user_info.nsid)
        
        session = Session()

        if user is None:
            user = User(key_name = user_info.nsid,
                        username = user_info.username,
                        fullname = user_info.fullname, 
                        token    = user_info.token,     
                        status   = const.UserRegistred,                      
                        last_login = datetime.datetime.now())
                     
        task = None
        
        if not user.is_saved() or user.status == const.UserUnRegistred:
            task = taskqueue.Task(url="/task/user/update_contacts", 
                                  params={'key':user.key(), 'update_favorites':True, 'initial_update': True})                           
        
        user.status = const.UserRegistred
        user.username = user_info.username
        user.fullname = user.fullname
        user.token = user_info.token
        
        if os.environ.get('SERVER_SOFTWARE') == 'Development/1.0':
            user.token = '72157623100491721-4ab7039d8e6b4615' 
        #user.token = '72157622500427269-7131c791b2204f16'
        user.last_login = datetime.datetime.now()
        
        try:
            user.put()
        except:
            user.put()
        
        if task:
            task.add("non-blocking")
        
        session["username"]   = user.username
        
        if user.fullname:
            session["fullname"]   = user.fullname
            
        session["nsid"]     = user.nsid
        session["auth_token"] = user.token
        
        session["difficulty"] = user.difficulty
        session["layout"] = user.layout        
                                                                        
        self.redirect("/dashboard")
开发者ID:buger,项目名称:flick_faver,代码行数:62,代码来源:main.py

示例2: post_app

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def post_app():
    #print('form')
    signed_request = request.form.get('signed_request')
    data = facebook_tools.parse_signed_request(signed_request,
                                              FACEBOOK_APP_SECRET)
    print(signed_request)
    print(data)
    session['oauth_token'] = (data['oauth_token'],'')
    me = facebook.get('/me')
    username = me.data['name']
    email= me.data['email']
    user = User.objects(email=email).first()
    if user:
        session['user_id'] = str(user.id)
    else:
        user = User()
        user.email = email
        user.username = username
        user.save()
        Inventory(owner=user.to_dbref(),
                      name='Basic',
                      is_basic=True).save()


    return send_file('public/index.html')
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:27,代码来源:app.py

示例3: facebook_authorized

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def facebook_authorized():
    resp = facebook.authorized_response()
    if resp is None:
        return 'Access denied: reason=%s error=%s' % (
            request.args['error_reason'],
            request.args['error_description']
        )
    if isinstance(resp, OAuthException):
        return 'Access denied: %s' % resp.message

    session['oauth_token'] = (resp['access_token'], '')
    me = facebook.get('/me')
    username = me.data['name']
    email= me.data['email']
    user = User.objects(email=email).first()
    if user:
        session['user_id'] = str(user.id)
    else:
        user = User()
        user.email = email
        user.username = username
        user.save()
        Inventory(owner=user.to_dbref(),
                      name='Basic',
                      is_basic=True).save()

    return redirect('/')
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:29,代码来源:app.py

示例4: create_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
 def create_user(self):
     user = User()
     user.username = 'test_username'
     user.password = 'test_password'
     user.name = 'test_name'
     user.email = '[email protected]'
     user.save()
     return user
开发者ID:aldarionsevero,项目名称:BusinemeWeb,代码行数:10,代码来源:test_post.py

示例5: put

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
    def put(self):
        user = User()
        user.username = 'kx'
        user.password = '123456'
        user.token = 'ddd'
        user.ttl = '7200'

        db.session.add(user)
        db.session.commit()
        return {'message': 'add success'}
开发者ID:fadexiii,项目名称:api_python_back,代码行数:12,代码来源:login.py

示例6: register

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def register(email, username, password):
    user = User()
    user.email = email
    user.username = username
    user.password = password
    errors = user.validate_me()
    if errors:
        print(errors)
        return {'errors': errors}
    else:
        res = user.save_me()
        if 'id' in res.keys():
            user = User.objects(id=res['id']).first()
            Inventory(owner=user.to_dbref(),
                      name='Basic',
                      is_basic=True).save()
        return res
开发者ID:Rmanolis,项目名称:rpg-demo,代码行数:19,代码来源:authentication.py

示例7: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
 def post(self, *args, **kwargs):
     name = self.get_argument('name', '')
     family = self.get_argument('family', '')
     username = self.get_argument('username', '')
     password = self.get_argument('password', '')
     type = self.get_argument('type', '')
     permissions = Redis.get(key='permissions', type='list')
     try:
         obj = Controller()
         obj.name = name
         obj.family = family
         obj.username = username
         obj.password = password
         obj.type = type
         obj.save()
         self.write('ok')
         self.render('register.html', action='done', permissions=permissions)
     except Exception, e:
         self.write(e.message)
         self.render('register.html', action='error', permissions=permissions)
开发者ID:ehsansh84,项目名称:Customs,代码行数:22,代码来源:user.py

示例8: register

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def register():
    """
    注册一个新的用户
    """
    template_var = {}
    form = RegisterForm()
    if request.method == "POST" and form.validate():
        form = RegisterForm(request.form)
        with session_cm() as session:
            user = User()
            user.username = form.username.data
            user.nickname = form.nickname.data
            user.email = form.email.data
            user.set_password(form.password.data)
            session.add(user)
            if user is not None:
                login_user(user)
            session.commit()
            return redirect(url_for('frontend.index'))
    template_var['form'] = form
    return render_template('account/register.html', **template_var)
开发者ID:depsi,项目名称:timefly,代码行数:23,代码来源:view.py

示例9: telegramWebHook

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def telegramWebHook():
    update = Update.de_json(request.get_json(force=True))
    text = None
    if getattr(update.message, 'document'):
        gallery = Gallery().search(tgid = update.message.chat.id)
        if gallery:
            newfile = bot.getFile(update.message.document.file_id)
            file_name = update.message.document.file_id
            newfile.download(file_name)
            writed = False
            if os.path.exists(file_name):
                writed = write_file(file_name, read_file(file_name, storage = 'local', append_path = False), acl = 'public-read', mime_type = update.message.document.mime_type)
                thumbnail(file_name)
                os.remove(file_name)
                write_file('%s.json' % file_name, update.to_json())
            if writed:
                file_id = File(gallery_eid = gallery.eid, file_id = update.message.document.file_id)
                file_id.save()
                sendLink = getattr(gallery, 'sendLink', None)
                if sendLink == 'True':
                    text = 'File URL: %s' % url_for('image', file_id = file_id.eid, _external = True, disable_web_page_preview = True)
            else:
                text = 'Failed to download file'
        else:
            text = 'Gallery does not exist, please create first'
        pass
    if getattr(update.message, 'text'):
        args = update.message.text.split(' ', 2)
        if args[0] == '/register':
            text = 'Username:'
            user = User().search(tgid = update.message.from_user.id)
            if not user:
                User(tgid = update.message.from_user.id).save()
                text = 'Complete register: https://telegram.me/ACSGalleryBot?start=%s' % update.message.from_user.id
            else:
                text = 'User added to gallery'
            # set gallery permission at this point because i have chat id
        elif args[0] == '/start':
            if len(args) > 1 and int(args[1]) == int(update.message.chat.id):
                text = 'Username:'
                bot.sendMessage(update.message.from_user.id, text, reply_markup = { 'force_reply' : True })
            else:
                text = update.to_json()

        elif getattr(update.message, 'reply_to_message'):
            if update.message.reply_to_message.text == 'Username:':
                user = User().search(tgid = update.message.from_user.id)
                if user:
                    user.username = update.message.text
                    user.save()
                    bot.sendMessage(update.message.chat.id, 'Password:', reply_markup = { 'force_reply' : True })
                return 'ok'
            elif update.message.reply_to_message.text == 'Password:':
                user = User().search(tgid = update.message.from_user.id)
                user.password = update.message.text
                user.save()
                text = 'User succesfuly registered'
        elif args[0] == '/create':
            if hasattr(update.message.chat, 'title'):
                gallery = Gallery().search(tgid = update.message.chat.id)
                if not gallery:
                    gallery = Gallery(tgid = update.message.chat.id, title = update.message.chat.title).save()
                text = 'Gallery URL: %s' % url_for('gallery', id = gallery.eid, _external = True, _scheme = 'https')
            else:
                text = 'Bot only works in groups'
        elif args[0] == '/remove':
            gallery = Gallery().search(tgid = update.message.chat.id)
            if gallery:
                gallery.delete()
                text = 'Gallery deleted'
            else:
                text = 'Gallery is not registered'
            # TODO: Confirm
        elif args[0] == '/config':
            args.pop(0)
            gallery = Gallery.search(tgid = update.message.chat.id)
            if gallery:
                if len(args) == 0:
                    text = g.config(update.message.chat.id)
                elif len(args) == 1:
                    text = 'get one'
                    text = g.config(update.message.chat.id, args[0])
                else:
                    text = g.config(update.message.chat.id, args[0], args[1])
            else:
                text = 'Gallery is not registered'
        #else:
        #    text = update.to_json()
    if text:
        bot.sendMessage(update.message.chat.id, text, disable_web_page_preview=True)
    return ""
开发者ID:oromerob,项目名称:gallerybot,代码行数:93,代码来源:app.py

示例10: register

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
def register(params, device):
    rtype = params.get('rtype', None)
    name = params.get('name', None)
    phone = params.get('phone', None)
    password = params.get('password', None)
    vcode = params.get('vcode', None)
    uname = params.get('username', '')
    cname = params.get('cname', '')
    notice = params.get('notice', "true")

    if not phone or not password or not vcode or not name or not rtype or not notice or not rtype.isdigit():
        return {"error_code":20021, "msg":"parameters required"}

    rtype = int(rtype)
    if not validate.is_phone(phone):
        return {"error_code":20022, "msg":"phone invalid"}

    # freelancer: 1, client: 2, client_person: 3
    if rtype not in [1, 2, 3]:
        return {"error_code":20022, "msg":"user type invalid"}

    if rtype == 2 and not cname or len(cname) > 100:
        return {"error_code":20022, "msg":"user type invalid or cname too long"}

    if not validate.is_verify_code(vcode):
        return {"error_code":20024, "msg":"verify code invalid"}
    
    if User.select().where(User.phone == phone).first():
        return {"error_code":20025, "msg":"user is exists"}

    if rtype != 1:
        username = phone
    else:
        # freelancer do not use username, just use phone to register
        # username = uname
        username = phone
    
    if not utils.is_username(username):
        return {"error_code":20023, "msg":"username invalid"}

    if User.select().where(User.username == username).first():
        return {"error_code":20025, "msg":"user is exists"}

    res = verify_code(phone=phone, code=vcode)
    if res['error_code'] != 0:
        return res
    
    user_id = GUID.guid()
    team_id = GUID.guid()
    with database.atomic() as txn:
        try:
            pwd, salt = generate_password(password.encode('utf-8'))
            user = User()
            user.id = user_id
            user.username = username
            user.password = pwd
            user.salt = salt
            user.phone = phone
            #user.verifycode = vcode
            user.save(force_insert=True)

            profile = Profile()
            profile.user = user
            profile.name = name
            profile.avatar = widget.avatar()

            if notice == "true":
                profile.is_notice = True
            profile.save()

            party = Party()
            party.user = user
            party.vip = False
            party.connects = 60
            party.agency_connects = 60
            party.save()

            margin = Margin()
            margin.user = user
            margin.save()

            if rtype == 1:
                user.identify = 'f%s' % user.id
                user.app_identify = 'f%s' % user.id
                user.status = "unactive"
                user.to_dev = True
                user.to_req = False
                user.save()

                queue.to_queue({"type":"user_register", "user_id":user.id})
            else:
                team = Team()
                team.id = team_id
                team.user = user
                if rtype == 2:
                    team.name = cname
                else:
                    team.name = "个人需求方"
                team.team_type = 'client'
                team.status = "normal"
#.........这里部分代码省略.........
开发者ID:wdvill,项目名称:cloud_admin,代码行数:103,代码来源:user.py

示例11: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import username [as 别名]
	def get(self):
		verifier = self.request.get("oauth_verifier")
		
		if verifier:
			# Get access token
			handler = auth.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
			handler.set_request_token(self.session.get("request_token_key"), self.session.get("request_token_secret"))
			access_token = handler.get_access_token(verifier)
			
			if access_token:
				# Get user			
				logging.info("Access token: %s" %(access_token))
				user = User.all().filter("twitter_access_token_key", access_token.key).get()
				
				if((not user) or (user and user.updated < datetime.now() - timedelta(0,86400))):
					logging.info("Connecting to the Twitter API")
					api = API(handler)
					temp_user = api.verify_credentials()
					temp_image = urlfetch.Fetch(str(temp_user.profile_image_url).replace("_normal", "")).content

					# Transform image into .PNG
					image_manager = images.Image(image_data=temp_image)
					image_manager.rotate(360)
					temp_png = image_manager.execute_transforms()
					logging.info("Encoded into .PNG")

					# Save or update image in Cloud storage
					filename = config.FOLDER + "/" + str(temp_user.id)
					gcs_file = gcs.open(filename,'w',content_type="image/png",options={"x-goog-acl":"public-read"})
					gcs_file.write(temp_png)
					gcs_file.close()
					logging.info("Image saved to Google Cloud Storage")

					# Get avatar
					blob_filename = "/gs" + filename
					blobkey = blobstore.create_gs_key(blob_filename)
					temp_avatar = str(images.get_serving_url(blobkey))
								
					if not user:
						logging.info("User did not exist")

						user = User(
							twitter_id = str(temp_user.id),
							twitter_access_token_key = str(access_token.key),
							twitter_access_token_secret = str(access_token.secret),
							username = str(temp_user.screen_name).lower(),
							name = temp_user.name,
							bio = temp_user.description,
							avatar = temp_avatar,
						)
						
					else:
						logging.info("User had to be updated")

						user.twitter_id = str(temp_user.id)
						user.twitter_access_token_key = str(access_token.key)
						user.twitter_access_token_secret = str(access_token.secret)
						user.username = str(temp_user.screen_name).lower()
						user.name = temp_user.name
						user.bio = temp_user.description
						user.avatar = temp_avatar
											
					user.put()
					logging.info("User @%s saved in datastore"%(user.username))
				
				# Save user in session
				self.session["id"] = user.key().id()
				
			else:
				logging.error("No access token from Twitter")
				print "Error"
		else:
			logging.error("No verifier")
			print "Error"
		
		# Redirect users to the page they came from or the page they're supposed to head to
		next = self.session.get("next")
		redirect = self.session.get("referer")
		if next:
			redirect = next
		self.redirect(str(redirect))
开发者ID:detcherry,项目名称:gopitch,代码行数:83,代码来源:auth.py


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