コード例 #1
0
ファイル: login.py プロジェクト: elvisds/eventframe
def login_event():
    if 'code' in request.args:
        code = LoginCode.query.filter_by(code=request.args['code']).first()
        if code and not code.user:
            if not g.user:
                return login(scope=code.scope, next=get_current_url())
            # Check for scope expansion
            has_scope = set(g.user.lastuser_token_scope.split(' '))
            need_scope = set(code.scope.split(' '))
            if '' in need_scope:
                need_scope.remove('')
            if need_scope - has_scope != set([]):
                # Need additional scope. Send user to Lastuser for access rights
                return login(scope=code.scope, next=get_current_url())
            code.user = g.user
            db.session.commit()
            # Redirect to event website
            if urlparse.urlsplit(code.return_url).query:
                return redirect(code.return_url + '&code=' + code.code, code=302)
            else:
                return redirect(code.return_url + '?code=' + code.code, code=302)
        elif code:
            db.session.delete(code)
            db.session.commit()
    abort(403)
コード例 #2
0
def login_event():
    if 'code' in request.args:
        code = LoginCode.query.filter_by(code=request.args['code']).first()
        if code and not code.user:
            if not g.user:
                return login(scope=code.scope, next=get_current_url())
            # Check for scope expansion
            has_scope = set(g.user.lastuser_token_scope.split(' '))
            need_scope = set(code.scope.split(' '))
            if '' in need_scope:
                need_scope.remove('')
            if need_scope - has_scope != set([]):
                # Need additional scope. Send user to Lastuser for access rights
                return login(scope=code.scope, next=get_current_url())
            code.user = g.user
            db.session.commit()
            # Redirect to event website
            if urlparse.urlsplit(code.return_url).query:
                return redirect(code.return_url + '&code=' + code.code,
                                code=302)
            else:
                return redirect(code.return_url + '?code=' + code.code,
                                code=302)
        elif code:
            db.session.delete(code)
            db.session.commit()
    abort(403)
コード例 #3
0
ファイル: eventlogin.py プロジェクト: hasgeek/eventframe
 def decorated_function(*args, **kwargs):
     if current_auth.is_anonymous:
         return redirect(url_for('login', next=get_current_url()))
     has_scope = set(current_auth.user.lastuser_token_scope.split(' '))
     need_scope = set(scope)
     if need_scope - has_scope != set([]):
         # Need additional scope. Send user to Lastuser for access rights
         return login(scope=' '.join(scope), next=get_current_url())
     return f(*args, **kwargs)
コード例 #4
0
 def decorated_function(*args, **kwargs):
     if g.user is None:
         return redirect(url_for('login', next=get_current_url()))
     has_scope = set(g.user.lastuser_token_scope.split(' '))
     need_scope = set(scope)
     if need_scope - has_scope != set([]):
         # Need additional scope. Send user to Lastuser for access rights
         return login(scope=' '.join(scope), next=get_current_url())
     return f(*args, **kwargs)
コード例 #5
0
ファイル: test_views.py プロジェクト: hasgeek/coaster
    def test_get_current_url(self):
        with self.app.test_request_context('/'):
            self.assertEqual(get_current_url(), '/')

        with self.app.test_request_context('/?q=hasgeek'):
            self.assertEqual(get_current_url(), '/?q=hasgeek')

        self.app.config['SERVER_NAME'] = 'example.com'

        with self.app.test_request_context('/somewhere', environ_overrides={'HTTP_HOST': 'example.com'}):
            self.assertEqual(get_current_url(), '/somewhere')

        with self.app.test_request_context('/somewhere', environ_overrides={'HTTP_HOST': 'sub.example.com'}):
            self.assertEqual(get_current_url(), 'http://sub.example.com/somewhere')
コード例 #6
0
 def decorated_function(*args, **kwargs):
     g.login_required = True
     if g.user is None:
         flash(u"You need to be logged in for that page", "info")
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #7
0
ファイル: helpers.py プロジェクト: pombredanne/lastuser
 def decorated_function(*args, **kwargs):
     if g.user is None:
         session["next"] = get_current_url()
         if "message" in request.args and request.args["message"]:
             flash(request.args["message"], "info")
         return redirect(url_for("login"))
     return f(*args, **kwargs)
コード例 #8
0
ファイル: __init__.py プロジェクト: anandology/flask-lastuser
 def decorated_function(*args, **kwargs):
     if g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(url_for(self._login_handler.__name__,
             next=get_current_url()))
     return f(*args, **kwargs)
コード例 #9
0
 def decorated_function(*args, **kwargs):
     if g.user is None:
         session['next'] = get_current_url()
         if 'message' in request.args and request.args['message']:
             flash(request.args['message'], 'info')
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #10
0
 def decorated_function(*args, **kwargs):
     add_auth_attribute('login_required', True)
     if not current_auth.is_authenticated:
         flash(_("You need to be logged in for that page"), 'info')
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #11
0
ファイル: helpers.py プロジェクト: hasgeek/lastuser
 def decorated_function(*args, **kwargs):
     add_auth_attribute('login_required', True)
     if not current_auth.is_authenticated:
         flash(_(u"You need to be logged in for that page"), 'info')
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #12
0
ファイル: helpers.py プロジェクト: finiterecursion/lastuser
 def decorated_function(*args, **kwargs):
     g.login_required = True
     if g.user is None:
         flash(u"You need to be logged in for that page", "info")
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #13
0
ファイル: helpers.py プロジェクト: supreethsubbaraya/lastuser
 def decorated_function(*args, **kwargs):
     add_auth_attribute('login_required', True)
     if not current_auth.is_authenticated:
         session['next'] = get_current_url()
         if 'message' in request.args and request.args['message']:
             flash(request.args['message'], 'info')
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #14
0
 def decorated_function(*args, **kwargs):
     if g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(
             url_for(self._login_handler.__name__,
                     next=get_current_url()))
     return f(*args, **kwargs)
コード例 #15
0
ファイル: helpers.py プロジェクト: finiterecursion/lastuser
 def decorated_function(*args, **kwargs):
     g.login_required = True
     if g.user is None:
         session['next'] = get_current_url()
         if 'message' in request.args and request.args['message']:
             flash(request.args['message'], 'info')
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #16
0
ファイル: helpers.py プロジェクト: hasgeek/lastuser
 def decorated_function(*args, **kwargs):
     add_auth_attribute('login_required', True)
     if not current_auth.is_authenticated:
         session['next'] = get_current_url()
         if 'message' in request.args and request.args['message']:
             flash(request.args['message'], 'info')
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #17
0
ファイル: test_views.py プロジェクト: sauravsrijan/coaster
    def test_get_current_url(self):
        with self.app.test_request_context('/'):
            assert get_current_url() == '/'

        with self.app.test_request_context('/?q=hasgeek'):
            assert get_current_url() == '/?q=hasgeek'

        self.app.config['SERVER_NAME'] = 'example.com'

        with self.app.test_request_context(
            '/somewhere', environ_overrides={'HTTP_HOST': 'example.com'}
        ):
            assert get_current_url() == '/somewhere'

        with self.app.test_request_context(
            '/somewhere', environ_overrides={'HTTP_HOST': 'sub.example.com'}
        ):
            assert get_current_url() == 'http://sub.example.com/somewhere'
コード例 #18
0
 def decorated_function(*args, **kwargs):
     g.login_required = True
     if hasattr(g, 'lastuserinfo') and g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(url_for(self._login_handler.__name__,
             next=get_current_url()))
     signal_before_wrapped_view.send(f)
     return f(*args, **kwargs)
コード例 #19
0
 def decorated_function(*args, **kwargs):
     # If the user's not logged in, log them in
     if g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(
             url_for(self._login_handler.__name__,
                     next=get_current_url()))
     # If the user is logged in, check if they have the required scope.
     # If not, send them off to Lastuser for the additional scope.
     existing = g.lastuserinfo.token_scope.split(' ')
     for item in scope:
         if item not in existing:
             required = set(self._login_handler().get(
                 'scope', 'id').split(' '))
             required.update(scope)
             return self._login_handler_internal(
                 scope=' '.join(required), next=get_current_url())
     return f(*args, **kwargs)
コード例 #20
0
 def decorated_function(*args, **kwargs):
     g.login_required = True
     if g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(
             url_for(self._login_handler.__name__,
                     next=get_current_url()))
     signal_before_wrapped_view.send(f)
     return f(*args, **kwargs)
コード例 #21
0
    def decorated_function(*args, **kwargs):
        add_auth_attribute('login_required', True)
        # If the user is not logged in, require login first
        if not current_auth.is_authenticated:
            flash(_("You need to be logged in for that page"), 'info')
            session['next'] = get_current_url()
            return redirect(url_for('login'))
        # If the user has not authenticated in some time, ask for the password again
        if not current_auth.session.has_sudo:
            # If the user doesn't have a password, ask them to set one first
            if not current_auth.user.pw_hash:
                flash(
                    _(
                        "This operation requires you to confirm your password. However,"
                        " your account does not have a password, so you must set one"
                        " first"
                    ),
                    'info',
                )
                session['next'] = get_current_url()
                return redirect(url_for('change_password'))
            # A future version of this form may accept password or 2FA (U2F or TOTP)
            form = PasswordForm(edit_user=current_auth.user)
            if form.validate_on_submit():
                # User has successfully authenticated. Update their sudo timestamp and
                # reload the page with a GET request, as the wrapped view may need to
                # render its own form
                current_auth.session.set_sudo()
                db.session.commit()
                return redirect(request.url, code=303)

            return render_form(
                form=form,
                title=_("Confirm with your password to proceed"),
                formid='password',
                submit=_("Confirm"),
                ajax=False,
                template='account_formlayout.html.jinja2',
            )
        return f(*args, **kwargs)
コード例 #22
0
ファイル: __init__.py プロジェクト: nibrahim/flask-lastuser
 def decorated_function(*args, **kwargs):
     # If the user's not logged in, log them in
     if g.lastuserinfo is None:
         if not self._login_handler:
             abort(403)
         return redirect(url_for(self._login_handler.__name__, next=get_current_url()))
     # If the user is logged in, check if they have the required scope.
     # If not, send them off to Lastuser for the additional scope.
     existing = g.lastuserinfo.token_scope.split(" ")
     for item in scope:
         if item not in existing:
             required = set(self._login_handler().get("scope", "id").split(" "))
             required.update(scope)
             return self._login_handler_internal(scope=" ".join(required), next=get_current_url())
     return f(*args, **kwargs)
コード例 #23
0
    def test_get_current_url(self):
        with self.app.test_request_context('/'):
            self.assertEqual(get_current_url(), '/')

        with self.app.test_request_context('/?q=hasgeek'):
            self.assertEqual(get_current_url(), '/?q=hasgeek')
コード例 #24
0
 def decorated_function(*args, **kwargs):
     if g.user is None:
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #25
0
ファイル: helpers.py プロジェクト: pombredanne/lastuser
 def decorated_function(*args, **kwargs):
     if g.user is None:
         flash(u"You need to be logged in for that page", "info")
         session["next"] = get_current_url()
         return redirect(url_for("login"))
     return f(*args, **kwargs)
コード例 #26
0
ファイル: helpers.py プロジェクト: gantir/lastuser
 def decorated_function(*args, **kwargs):
     if g.user is None:
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)
コード例 #27
0
 def decorated_function(*args, **kwargs):
     add_auth_attribute('login_required', True)
     if not current_auth.is_authenticated:
         session['next'] = get_current_url()
         return redirect(url_for('login'))
     return f(*args, **kwargs)