Ejemplo n.º 1
0
        def facebook_authorized(response):
            if not response:
                abort(401)

            session['facebook_access_token'] = (response['access_token'], '')

            who = self.facebook.get('/me')
            user, new = User.objects.get_or_create(facebook_id=who.data['id'])

            if new:
                user.fullname = who.data['name']
                user.email = who.data.get('email', None)
                user.gender = who.data['gender']

            user.facebook_access_token = response['access_token']
            user.facebook_expires = time() + int(response['expires'])
            user.save()

            login_user(user)
            identity_changed.send(current_app._get_current_object(),
                                  identity=Identity(user.get_id()))

            session.pop('facebook_access_token')

            return redirect(request.args.get('next') or
                            request.referrer or
                            url_for('index.index'))
Ejemplo n.º 2
0
    def _collateral(
        self,
        project_uuid: str,
        pipeline_uuid: str,
        container_ids: Dict[str, str],
        notebook_server_info: Dict[str, str],
        previous_state: str,
    ):
        # Could be none when the _transaction call sets them to None
        # because there is no session to shutdown. This is a way that
        # the _transaction function effectively tells the _collateral
        # function to not be run.
        if project_uuid is None or pipeline_uuid is None:
            return

        current_app.config["SCHEDULER"].add_job(
            StopInteractiveSession._background_session_stop,
            args=[
                current_app._get_current_object(),
                project_uuid,
                pipeline_uuid,
                container_ids,
                notebook_server_info,
                previous_state,
            ],
        )
Ejemplo n.º 3
0
def push_app_context(fn):
    app = current_app._get_current_object()

    def wrapper(*args, **kwargs):
        with app.app_context():
            return fn(*args, **kwargs)

    return wrapper
Ejemplo n.º 4
0
 def _collateral(self, project_uuid: str):
     # Needs to happen in the background because session shutdown
     # happens in the background as well. The scheduler won't be
     # given control if an endpoint is, for example, sleeping.
     current_app.config["SCHEDULER"].add_job(
         DeleteProjectEnvironmentImages._background_collateral,
         args=[current_app._get_current_object(), project_uuid],
     )
Ejemplo n.º 5
0
def logout():
    logout_user()
    for key in ('identity.name', 'identity.auth_type'):
        session.pop(key, None)
    identity_changed.send(current_app._get_current_object(),
                          identity=AnonymousIdentity())
    flash("You are now logged out")
    return redirect(url_for('.index'))
Ejemplo n.º 6
0
def start_background_task(target: Callable, *args, **kwargs):
    socketio_app: SocketIO = getattr(current_app, 'socketio_app', None)
    flask_app = current_app._get_current_object()
    if socketio_app:
        socketio_app.start_background_task(target=context_provider,
                                           func=target,
                                           flask_app=flask_app,
                                           *args,
                                           **kwargs)
Ejemplo n.º 7
0
 def send_signals(response):
     try:
         record_accepted.send(
             current_app._get_current_object(),
             record_id=rec.id,
             community_id=self.community.id,
         )
     except Exception:
         pass
     return response
Ejemplo n.º 8
0
def send_email(to, subject, template, **kwargs):
    app = current_app._get_current_object()
    msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
                  sender=app.config['FLASKY_MAIL_SENDER'],
                  recipients=[to])
    msg.body = render_template(template + '.txt', **kwargs)
    msg.html = render_template(template + '.html', **kwargs)
    thr = Thread(target=send_async_email, args=[app, msg])
    thr.start()
    return thr
Ejemplo n.º 9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = form.get_user()
        login_user(user)
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))
        flash("Logged in successfully")
        return redirect(request.args.get("next") or url_for('.index'))
    return render_template('login.jade', form=form)
Ejemplo n.º 10
0
 def send_email(self, to, subject, template, **kwargs):
     try:
         app = current_app._get_current_object()
         msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
                       sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to])
         msg.body = render_template(template + '.txt', **kwargs)
         msg.html = render_template(template + '.html', **kwargs)
         #thr = Thread(target=self.send_async_email, args=[app, msg])
         #thr.start()
         return mail.send(msg)
     except Exception as e:
         raise EmailError(e)
Ejemplo n.º 11
0
        def logout():
            logout_user()

            for key in ['identity.name', 'identity.auth_type']:
                session.pop(key, None)

            identity_changed.send(current_app._get_current_object(),
                                  identity=AnonymousIdentity())

            return redirect(request.args.get('next') or
                            request.referrer or
                            url_for('index.index'))
Ejemplo n.º 12
0
    def _collateral(
        self,
        *args,
        **kwargs,
    ):

        current_app.config["SCHEDULER"].add_job(
            CreateInteractiveSession._background_session_start,
            # From the docs:
            # Return the current object.  This is useful if you want the
            # real object behind the proxy at a time for performance
            # reasons or because you want to pass the object into a
            # different context.
            args=[current_app._get_current_object(), *args],
            kwargs=kwargs,
        )
Ejemplo n.º 13
0
    def logout(self):
        if 'oauth_method' in session:
            session.pop('oauth_method')
        if 'oauth_token' in session:
            session.pop('oauth_token')
        if 'oauth_resp' in session:
            session.pop('oauth_resp')
        if 'oauth_id' in session:
            session.pop('oauth_id')

        logout_user()

        # Remove session keys set by Flask-Principal
        for key in ('identity.name', 'identity.auth_type'):
            session.pop(key, None)

        # Tell Flask-Principal the user is anonymous
        identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())
        return redirect(url_for("general.index"))
Ejemplo n.º 14
0
    def authorized(self, resp):
        next_url = request.args.get('next') or url_for('general.index')
        if resp is None:
            flash(u'You denied the request to sign in.')
            return False, next_url

        session['oauth_method'] = self.method

        username = self.get_user_info(resp)

        u = User.objects(userid=username, method=self.method).first()
        if u == None:
            User(token=session['oauth_token'], userid=username, method=self.method).save()
        else:
            u.token = session['oauth_token'][0]
            u.save()
        login_user(u)

        session['oauth_id'] = username
        identity_changed.send(current_app._get_current_object(), identity=Identity(username))

        return redirect(next_url)