Exemplo n.º 1
0
    def getCalendarAccounts(self, request:Request, auth:Auth):
        authed_id = auth.user().id
        user = User.find(authed_id)
        email_accounts = Account.where('user_id', user.id).where('type', 'connect_calendar').get()
        if email_accounts != None:
            return email_accounts

        return []
Exemplo n.º 2
0
    def oauthcallback(self, view: View, request: Request, auth: Auth):

        nylas_access_token = request.input('access_token')
        nylas_account_id = request.input('account_id')
        email_address = request.input('email_address')
        provider = request.input('provider')
        # a cookie is set so we can identify where the user started the auth process
        start_page_type = request.get_cookie('callbackpage', decrypt=False)

        user = auth.user()

        #we want to treat this as a master token so it doesnt change when auth'ing with different scopes
        if start_page_type == 'connect_personal':
            user.access_token = nylas_access_token
            user.nylas_account_id = nylas_account_id
            user.save()

        try:
            Account.update_or_create(
                {
                    "user_id": user.id,
                    "nylas_account_id": nylas_account_id,
                    "type": start_page_type
                }, {
                    "access_token": nylas_access_token,
                    "email": email_address,
                    "nylas_account_id": nylas_account_id,
                    "type": start_page_type,
                    "scopes": start_page_type,
                    "provider": provider,
                    "valid": 1
                })
        except Exception as e:
            print(str(e))

        return view.render(
            'auth.callback', {
                'email_address': email_address,
                'provider': provider,
                'nylas_access_token': nylas_access_token,
                'nylas_account_id': nylas_account_id
            })
Exemplo n.º 3
0
    def deleteAccount(self, request:Request, auth:Auth):
        authed_id = auth.user().id
        postData = request.input('data')
        account_id = postData['id']

        try:
            pprint(account_id)
            account = Account.where('user_id', authed_id).where('id',account_id).first()
            account.delete()
            return 1
        except Exception as e:
            print(str(e))
            return 0
    def run(self):
        """Run the database seeds."""
        # self.call(UserTableSeeder)
        account = Account.create(name="Acme Corporation")

        user = User.create(account_id=account.id,
                           first_name="John",
                           last_name="Doe",
                           password=password('secret'),
                           email="*****@*****.**",
                           owner=True,
                           photo_path="")

        Factory(User, 5).create({"account_id": account.id})

        Factory(Organization, 10).create({"account_id": account.id})
Exemplo n.º 5
0
    def createDemoAccounts(self, request:Request, auth:Auth):
        user_id = auth.user().id
        name = request.input('name')
        if name == "":
            return 0

        providers = [
                    'outlook',
                    'apple',
                    'gmail',
                    'yahoo',
                    'office365'
                    ]

        for provider in providers:
            fake_email = name + '@' + provider + '.com'
            type='connect_email'
            # check if this type of connection has been completed before by the email address
            the_account = Account.where('user_id', user_id).where('email', fake_email).where('type', type).first()

            if the_account is None:
                account = Account()
                account.user_id = user_id
                account.access_token = 'demo_so_doesnt_matter'
                account.email = fake_email
                account.provider = provider
                account.nylas_account_id = 'demo_so_doesnt_matter'
                account.scopes = 'demo_so_doesnt_matter'
                account.type = type
                account.valid = bool(random.getrandbits(1))
                account.save()

        for provider in providers:
            fake_email = name + '@' + provider + '.com'
            type = 'connect_calendar'
            the_account = Account.where('user_id', user_id).where('email', fake_email).where('type', type).first()

            if provider == 'yahoo':
                continue

            if the_account is None:
                account = Account()
                account.user_id = user_id
                account.access_token = 'demo_so_doesnt_matter'
                account.email = fake_email
                account.provider = provider
                account.nylas_account_id = 'demo_so_doesnt_matter'
                account.scopes = 'demo_so_doesnt_matter'
                account.type = type
                account.valid = bool(random.getrandbits(1))
                account.save()
        #
        for provider in providers:

            fake_email = name + '@' + provider + '.com'
            type = 'connect_contact'
            the_account = Account.where('user_id', user_id).where('email', fake_email).where('type', type).first()

            if the_account is None:
                account = Account()
                account.user_id = user_id
                account.access_token = 'demo_so_doesnt_matter'
                account.email = fake_email
                account.provider = provider
                account.nylas_account_id = 'demo_so_doesnt_matter'
                account.scopes = 'demo_so_doesnt_matter'
                account.type = type
                account.valid = bool(random.getrandbits(1))
                account.save()

        return True