コード例 #1
0
ファイル: client.py プロジェクト: rverdi642/CS10-labor-pos
    def mutate(
        # data that can be mutated
        self,
        info,
        first_name,
        last_name,
        email,
        street_address,
        city,
        state,
        zipcode,
        deadline=None,
        business_name="",
    ):

        user = info.context.user
        # verifies you are working with existing user
        if user.is_anonymous:
            return CreateClient(ok=False, status="Must be logged in.")
        else:
            new_client = Client(
                # sets entered info as new client info
                business_name=business_name,
                first_name=first_name,
                last_name=last_name,
                email=email,
                street_address=street_address,
                city=city,
                state=state,
                zipcode=zipcode,
                user=user,
            )
            new_client.save()
            return CreateClient(client=new_client, ok=True, status="ok")
コード例 #2
0
ファイル: client.py プロジェクト: nphillips78/CS10-labor-pos
    def mutate(
        self,
        info,
        first_name,
        last_name,
        email,
        street_address,
        city,
        state,
        zipcode,
        deadline=None,
        business_name="",
    ):

        user = info.context.user
        if user.is_anonymous:
            return CreateClient(ok=False, status="Must be logged in.")
        else:
            new_client = Client(
                business_name=business_name,
                first_name=first_name,
                last_name=last_name,
                email=email,
                street_address=street_address,
                city=city,
                state=state,
                zipcode=zipcode,
                user=user,
            )
            new_client.save()
            return CreateClient(client=new_client, ok=True, status="ok")
コード例 #3
0
def create_autograder_token(user_id):
    autograder_client = Client.query.get('autograder')
    if not autograder_client:
        autograder_client = Client(
            name='Autograder',
            client_id='autograder',
            client_secret='autograder',
            redirect_uris=[],
            is_confidential=False,
            description='The Autopy autograder system',
            default_scopes=['all'],
        )
        db.session.add(autograder_client)
        db.session.commit()
    token = Token(
        client=autograder_client,
        user_id=user_id,
        token_type='bearer',
        access_token=oauthlib.common.generate_token(),
        expires=datetime.datetime.utcnow() + datetime.timedelta(hours=2),
        scopes=['all'],
    )
    db.session.add(token)
    db.session.commit()
    return token
コード例 #4
0
def test_client():
    client = Client(id='1',
                    name='name',
                    phone_number='71112223344',
                    email='*****@*****.**')
    assert client.name == 'name'
    assert client.phone_number == '71112223344'
    assert client.email == '*****@*****.**'
    assert client.id == '1'
コード例 #5
0
    def _setup_clients(self, scope='email'):
        self.setup_course()

        self.oauth_client = Client(
            name='Testing Client',
            client_id='normal',
            client_secret='normal',
            redirect_uris=['http://127.0.0.1:8000/authorized'],
            is_confidential=False,
            active=True,
            description='Sample App for testing OAuth',
            default_scopes=scope)
        db.session.add(self.oauth_client)
        db.session.commit()

        self.temp_grant = Grant(user_id=self.user1.id,
                                client_id='normal',
                                code='12345',
                                scopes=['email'],
                                expires=dt.datetime.utcnow() +
                                dt.timedelta(seconds=100))
        db.session.add(self.temp_grant)

        self.expired_token = Token(user_id=self.user1.id,
                                   client_id='normal',
                                   scopes=[scope],
                                   access_token='expired',
                                   expires=dt.datetime.utcnow() -
                                   dt.timedelta(seconds=1))
        db.session.add(self.expired_token)

        self.valid_token = Token(user_id=self.user1.id,
                                 client_id='normal',
                                 scopes=[scope],
                                 access_token='soo_valid',
                                 expires=dt.datetime.utcnow() +
                                 dt.timedelta(seconds=3600))
        db.session.add(self.valid_token)

        self.valid_token_bad_scope = Token(user_id=self.user1.id,
                                           client_id='normal',
                                           scopes=['invalid'],
                                           access_token='soo_valid12',
                                           expires=dt.datetime.utcnow() +
                                           dt.timedelta(seconds=3600))
        db.session.add(self.valid_token_bad_scope)

        self.valid_token_all_scope = Token(user_id=self.user1.id,
                                           client_id='normal',
                                           scopes=['all'],
                                           access_token='soo_valid322',
                                           expires=dt.datetime.utcnow() +
                                           dt.timedelta(seconds=3600))
        db.session.add(self.valid_token_all_scope)
        db.session.commit()
コード例 #6
0
def seed_oauth():
    print("Seeding OAuth...")
    client1 = Client(
        name='Example Application',
        client_id='example-app',
        client_secret='example-secret',
        redirect_uris=[
            'http://localhost:8000/authorized',
            'http://127.0.0.1:8000/authorized',
            'http://127.0.0.1:8000/login/authorized',
        ],
        is_confidential=False,
        active=True,
        description='Sample App for building OAuth',
        default_scopes=OAUTH_SCOPES,
    )
    db.session.add(client1)
    # Find a non admin staff member
    client_owner = None
    for user in User.query.filter_by(is_admin=False):
        if user.is_staff():
            client_owner = user
            break
    if client_owner:
        client2 = Client(
            name='Example Pending OAuth Application',
            user_id=client_owner.id,
            user=client_owner,
            client_id='pending-app',
            client_secret='example-secret2',
            redirect_uris=[
                'http://localhost:8000/authorized',
                'http://127.0.0.1:8000/authorized',
                'http://127.0.0.1:8000/login/authorized',
            ],
            is_confidential=False,
            active=False,
            description='Sample App for building OAuth',
            default_scopes=[OAUTH_SCOPES[1]],  # ['email']
        )
        db.session.add(client2)
    db.session.commit()
コード例 #7
0
ファイル: admin.py プロジェクト: shivasheeshyadav/ok
def clients():
    clients = Client.query.all()
    form = forms.ClientForm(client_secret=utils.generate_secret_key())
    if form.validate_on_submit():
        client = Client(user=current_user)
        form.populate_obj(client)
        db.session.add(client)
        db.session.commit()

        flash('OAuth client "{}" added'.format(client.name), "success")
        return redirect(url_for(".clients"))

    return render_template('staff/clients.html', clients=clients, form=form)
コード例 #8
0
ファイル: generate.py プロジェクト: xiaomeow/ok
def seed_oauth():
    print("Seeding OAuth...")
    client = Client(
        name='Example Application',
        client_id='example-app',
        client_secret='example-secret',
        redirect_uris=[
            'http://localhost:8000/authorized',
            'http://127.0.0.1:8000/authorized',
            'http://127.0.0.1:8000/login/authorized',
        ],
        is_confidential=False,
        description='Sample App for building OAuth',
        default_scopes=OAUTH_SCOPES,
    )
    db.session.add(client)
    db.session.commit()
コード例 #9
0
ファイル: autograder.py プロジェクト: xiaomeow/ok
def send_batch(assignment, backup_ids):
    if not assignment.autograding_key:
        raise ValueError('Assignment has no autograder key')

    # Create an access token for this run
    autograder_client = Client.query.get('autograder')
    if not autograder_client:
        autograder_client = Client(
            name='Autograder',
            client_id='autograder',
            client_secret='autograder',
            redirect_uris=[],
            is_confidential=False,
            description='The Autopy autograder system',
            default_scopes=['all'],
        )
        db.session.add(autograder_client)
        db.session.commit()
    token = Token(
        client=autograder_client,
        user=current_user,
        token_type='bearer',
        access_token=oauthlib.common.generate_token(),
        expires=datetime.datetime.utcnow() + datetime.timedelta(hours=2),
        scopes=['all'],
    )
    db.session.add(token)
    db.session.commit()

    return send_autograder('/api/ok/v3/grade/batch', {
        'subm_ids': [utils.encode_id(bid) for bid in backup_ids],
        'assignment': assignment.autograding_key,
        'access_token': token.access_token,
        'priority': 'default',
        'backup_url': url_for('api.backup', _external=True),
        'ok-server-version': 'v3',
    })
コード例 #10
0
ファイル: api.py プロジェクト: wmgeolab/ok
 def add_redirect_url(self, client: models.Client):
     args = self.parse_args()
     url = args['url']
     client.redirect_uris = client.redirect_uris + [url]
     models.db.session.commit()
     return {}