Ejemplo n.º 1
0
    def authenticate(self, **credentials):
        fb = credentials.get('fb')
        request = credentials.get('request')
        if fb is None:
            return None
        
        username = '******' % (str(fb.uid))
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            # Check to see if we already have a UserProfile with the fb.uid in
            # store. This is so that we can allow users to change their default
            # Django auth usernames.
            try:
                profile = UserProfile.objects.get(facebook_id=fb.uid)
                user = profile.user
            except UserProfile.DoesNotExist:
                user = User(username=username)
                user.set_password(utils.get_random_password())
                user.save()
                profile = user.get_profile()
                profile.facebook_id = fb.uid
                try:
                    user_info = fb.users.getInfo(fb.uid, fields=['first_name'])[0]
                    profile.facebook_name = user_info['first_name']
                except:
                    pass
                profile.save()
                request.session['is_new_user_account'] = True

        return user
Ejemplo n.º 2
0
    def authenticate(self, **credentials):
        fb = credentials.get('fb')
        request = credentials.get('request')
        if fb is None:
            return None

        username = '******' % (str(fb.uid))
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            # Check to see if we already have a UserProfile with the fb.uid in
            # store. This is so that we can allow users to change their default
            # Django auth usernames.
            try:
                profile = UserProfile.objects.get(facebook_id=fb.uid)
                user = profile.user
            except UserProfile.DoesNotExist:
                user = User(username=username)
                user.set_password(utils.get_random_password())
                user.save()
                profile = user.get_profile()
                profile.facebook_id = fb.uid
                try:
                    user_info = fb.users.getInfo(fb.uid,
                                                 fields=['first_name'])[0]
                    profile.facebook_name = user_info['first_name']
                except:
                    pass
                profile.save()
                request.session['is_new_user_account'] = True

        return user
Ejemplo n.º 3
0
 def connection_made(self, conn):
     self.conn = conn
     self.conn_pass = get_random_password()
     conn.send_auth_banner(SSHTemplate.banner(self.conn_pass))
     log(
         "SSH connection received",
         self.conn,
     )
Ejemplo n.º 4
0
    def authenticate(self, **credentials):
        access_token = credentials.get('token')
        request = credentials.get('request')
        if access_token is None:
            return None

        auth = tweepy.OAuthHandler(
            settings.TWITTER_CONSUMER_KEY,
            settings.TWITTER_CONSUMER_SECRET
        )
        auth.access_token = access_token
        api = tweepy.API(auth)
        if not api.verify_credentials():
            return None
        else:
            credentials = api.me()

        username = '******' % (str(credentials.id))
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            # Check to see if there is already a UserProfile with a matching
            # screen_name. This is so that we can allow users to change their
            # default Django auth usernames.
            try:
                profile = UserProfile.objects.get(twitter_id=credentials.screen_name)
            except UserProfile.DoesNotExist:
                user = User(username=username)
                user.save()
                user.set_password(utils.get_random_password())
                profile = user.get_profile()
                profile.twitter_id = credentials.screen_name
                profile.twitter_access_token = unicode(auth.access_token)
                profile.save()
                request.session['is_new_user_account'] = True
            else:
                user = profile.user
                if profile.twitter_access_token != auth.access_token:
                    profile.twitter_access_token = unicode(auth.access_token)
                    profile.save()
        else:
            profile = user.get_profile()
            if profile.twitter_access_token != auth.access_token:
                # We have a new access token. Update the one we have
                # stored for this user.
                profile.twitter_access_token = unicode(auth.access_token)
                profile.save()

        return user
Ejemplo n.º 5
0
    async def serveme(self, ctx, region="us-east-2"):

        # Setup Variables
        password = get_random_password()
        ttl = 180
        requester_name = ctx.author.name
        location = region_to_location(region)
        request_id = f"{get_random_password(2).upper()}{Timehash.now()}"

        # Create Server
        embed = self.get_serveme_embed("Requesting a new server...", ttl,
                                       location, request_id, "...",
                                       global_config.icons.loading_icon)
        message = await ctx.send(embed=embed)
        server = create_server(server_type="tf2-competitive",
                               requester_name=requester_name,
                               request_id=request_id,
                               password=password,
                               ttl=ttl,
                               discord_channel_id=ctx.channel.id,
                               discord_message_id=message.id,
                               region=region)

        # Wait for server to boot
        embed = self.get_serveme_embed(
            "Waiting for Team Fortress 2 to start up...", ttl, location,
            request_id, "...", global_config.icons.loading_icon)
        await message.edit(embed=embed)
        ip_address = get_instance_ip(server['InstanceId'], region=region)
        await wait_for_tcp(ip_address, 27015)

        # Ready!
        connect_info = ("```nginx\n"
                        f"connect {ip_address}; password {password}\n"
                        "```")
        embed = self.get_serveme_embed("Server is ready!", ttl, location,
                                       request_id, connect_info,
                                       global_config.icons.tf2m_icon)
        await message.edit(embed=embed)