예제 #1
0
파일: account.py 프로젝트: J4LP/J4OAuth
def application(client_id):
    """
    View for application settings and stats
    """
    client = Client.query.get(client_id)
    client_form = ClientForm(obj=client, redirect_uri=client._redirect_uris)
    if client is None:
        abort(404)
    if client.user_id != current_user.id:
        app.logger.warning('Security issue by {}'.format(current_user.id))
        flash('You are not allowed to do that', 'danger')
        return redirect(url_for('.user_account'))
    if client_form.validate_on_submit():
        client.name = client_form.name.data
        client.description = client_form.description.data
        client.homepage = client_form.homepage.data
        client._redirect_uris = client_form.redirect_uri.data
        db.session.add(client)
        try:
            db.session.commit()
        except Exception as e:
            app.logger.exception(e)
            flash('There was an issue updating your application, '
                  'please try again or contact support', 'danger')
        else:
            flash('Application updated', 'success')
        return redirect(url_for('.application', client_id=client.client_id))
    if client_form.is_submitted() is True:
        flash('There was an issue validating your informations', 'danger')
    return render_template('application.html', client=client, form=client_form)
예제 #2
0
파일: account.py 프로젝트: J4LP/J4OAuth
def new_application():
    """
    Method to create a new client associated to the current user account
    """
    if 'inpatients' not in current_user.groups:
        app.logger.warning('Security issue by {}'.format(current_user.id))
        flash('You do not belong to the right group for this', 'danger')
        return redirect(url_for('.user_account'))
    client_form = ClientForm()
    if client_form.validate_on_submit():
        client = Client()
        client.name = client_form.name.data
        client.description = client_form.description.data
        client.homepage = client_form.homepage.data
        client._redirect_uris = client_form.redirect_uri.data
        client.generate_keys()
        client.user_id = current_user.id
        client.is_confidential = True
        client._default_scopes = 'auth_info'
        db.session.add(client)
        try:
            db.session.commit()
        except Exception as e:
            app.logger.exception(e)
            flash('There was an issue saving your new application, '
                  'please try again or contact support', 'danger')
        else:
            flash('Application created', 'success')
            return redirect(url_for('.user_account'))
        return redirect(url_for('.new_application'))
    if client_form.is_submitted() is True:
        flash('There was an issue validating your demand', 'danger')
    return render_template('new_application.html', form=client_form)