示例#1
0
    def login():
        if g.current_user:
            return redirect(get_next())

        form = g.login_form

        if form.validate_on_submit():
            # Find a user matching the credentials
            user = User.by_credentials(form.email_address.data,
                                       form.password.data)

            # Check if the user wants a cookie
            remember = form.remember_me.data

            # Check if a user was found and try to login
            if user and login_user(user, remember=remember):
                user.login_ip = request.remote_addr
                user.login_time = datetime.utcnow()

                flash(
                    _('You are now logged in. Welcome back, %(user)s!',
                      user=user))
                return redirect(get_next())
            else:
                form.email_address.errors.append(
                    _('Login failed. Please check your email address.'))
                form.password.errors.append(
                    _('Login failed. Please check your password.'))

        return render_template('login.jinja', form=form, next=get_next())
示例#2
0
文件: login.py 项目: imclab/skylines
    def login():
        if g.current_user:
            return redirect(get_next())

        form = g.login_form

        if form.validate_on_submit():
            # Find a user matching the credentials
            user = User.by_credentials(form.email_address.data,
                                       form.password.data)

            # Check if the user wants a cookie
            remember = form.remember_me.data

            # Check if a user was found and try to login
            if user and login_user(user, remember=remember):
                user.login_ip = request.remote_addr
                user.login_time = datetime.utcnow()

                flash(_('You are now logged in. Welcome back, %(user)s!', user=user))
                return redirect(get_next())
            else:
                form.email_address.errors.append(_('Login failed. Please check your eMail address.'))
                form.password.errors.append(_('Login failed. Please check your password.'))

        return render_template('login.jinja', form=form, next=get_next())
示例#3
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            username = request.authorization.username
            if is_bytes(username):
                username = username.decode("utf-8")

            password = request.authorization.password
            if is_bytes(password):
                password = password.decode("utf-8")

            user = User.by_credentials(username, password)

            request.user_id = user.id if user else None
            set_sentry_user({"id": request.user_id})

            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None
            set_sentry_user({"id": request.user_id})

            return valid, req
示例#4
0
 def load_user_from_header(header_val):
     try:
         header_val = header_val.replace('Basic ', '', 1)
         header_val = base64.b64decode(header_val)
         email, password = header_val.split(':', 1)
         return User.by_credentials(email, password)
     except:
         return None
示例#5
0
 def load_user_from_header(header_val):
     try:
         header_val = header_val.replace('Basic ', '', 1)
         header_val = base64.b64decode(header_val)
         email, password = header_val.split(':', 1)
         return User.by_credentials(email, password)
     except:
         return None
示例#6
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            user = User.by_credentials(
                request.authorization.username,
                request.authorization.password,
            )

            request.user_id = user.id if user else None
            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None

            return valid, req
示例#7
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            user = User.by_credentials(
                request.authorization.username,
                request.authorization.password,
            )

            request.user_id = user.id if user else None
            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None

            return valid, req
示例#8
0
    def verify_request(self, scopes):
        if request.authorization:
            from skylines.model import User

            username = request.authorization.username
            if is_bytes(username):
                username = username.decode('utf-8')

            password = request.authorization.password
            if is_bytes(password):
                password = password.decode('utf-8')

            user = User.by_credentials(username, password)

            request.user_id = user.id if user else None
            return (user is not None), None

        else:
            valid, req = super(CustomProvider, self).verify_request(scopes)

            request.user_id = req.access_token.user_id if valid else None

            return valid, req