コード例 #1
0
    def post(self):
        try:
            args = self.creation_parser.parse_args()
        except werkzeug.exceptions.BadRequest as e:
            self.logger.warning(
                f'{dir(e), str(e), e.args, e.data, e.name, e.description}')
            return_msg = '\n'.join(
                [f'{v}: {k}.' for k, v in e.data['errors'].items()])
            return {'return_code': 400, 'return_msg': return_msg}
        key = args['appid']
        secret = args['secret']

        redis_ins = RedisInstance()
        secret_ = redis_ins.client.hget("appId:{}".format(key), "secret")
        if secret_ is None:
            return {'return_code': 530, 'return_msg': '"appid secret无效"'}
        if secret_.decode("utf-8") != secret:
            return {'return_code': 530, 'return_msg': '"appid secret无效"'}
        expire_ = redis_ins.client.hget("appId:{}".format(key), "expire")
        if not expire_:
            return dict(return_code=531,
                        return_msg="appid expire_ error",
                        data={})
        if time.time() > float(expire_):
            return {'return_code': 531, 'return_msg': "appid 已过期"}
        return {
            'return_code': 200,
            "data": {
                'token': auth.generate_token(key=key)
            }
        }
コード例 #2
0
def get_token():
    incoming = request.get_json()
    user = User.get_user_with_email_and_password(incoming["email"],
                                                 incoming["password"])
    if user:
        return jsonify(token=generate_token(user))

    return jsonify(error=True), 403
コード例 #3
0
def create_user():
    incoming = request.get_json()

    success = User.create_user(incoming)

    if not success:
        return jsonify(message="User with that email already exists"), 409

    new_user = User.query.filter_by(email=incoming["email"]).first()

    return jsonify(id=new_user.id, token=generate_token(new_user))
コード例 #4
0
    def post(self):
        args = self.req_parser.parse_args()

        user = db.session.query(AppUser).filter(AppUser.email==args['email']).first()
        if user and bcrypt.check_password_hash(user.password, args['password']):

            return {
                'id': user.id,
                'token': generate_token(user)
            }

        return BAD_CREDENTIALS
コード例 #5
0
ファイル: api.py プロジェクト: outhanchazima/Baobab
def user_info(user, roles):
    return {
        'id': user.id,
        'token': generate_token(user),
        'firstname': user.firstname,
        'lastname': user.lastname,
        'email': user.email,
        'title': user.user_title,
        'is_admin': user.is_admin,
        'primary_language': user.user_primaryLanguage,
        'roles': [{'event_id': event_role.event_id, 'role': event_role.role} for event_role in roles]
    }
コード例 #6
0
 def on_post(self, req, res):
     user_doc = {
         'email': req.context['data']['email'],
         'password': hash_password(req.context['data']['password'])
     }
     try:
         new_user = self.add_user(user_doc)
     except IntegrityError:
         title = 'Conflict'
         description = 'Email in use'
         raise falcon.HTTPConflict(title, description)
     req.context['result'] = {'token': generate_token(new_user)}
     res.status = falcon.HTTP_CREATED
コード例 #7
0
ファイル: handlers.py プロジェクト: projectweekend/makerdb
 def on_post(self, req, res):
     user_doc = {
         'email': req.context['data']['email'],
         'password': hash_password(req.context['data']['password'])
     }
     try:
         new_user = self.add_user(user_doc)
     except IntegrityError:
         title = 'Conflict'
         description = 'Email in use'
         raise falcon.HTTPConflict(title, description)
     req.context['result'] = {'token': generate_token(new_user)}
     res.status = falcon.HTTP_CREATED
コード例 #8
0
def user_info(user):
    return {
        'id': user.id,
        'token': generate_token(user),
        'firstname': user.firstname,
        'lastname': user.lastname,
        'email': user.email,
        'camera1Ip': user.camera1Ip,
        'camera1Name': user.camera1Name,
        'camera2Ip': user.camera2Ip,
        'camera2Name': user.camera2Name,
        'camera3Ip': user.camera3Ip,
        'camera3Name': user.camera3Name
    }
コード例 #9
0
    def post(self):
        args = self.req_parser.parse_args()

        user = AppUser(email=args['email'], password=args['password'])
        db.session.add(user)

        try:
            db.session.commit()
        except IntegrityError:
            return EMAIL_IN_USE

        return {
            'id': user.id,
            'token': generate_token(user)
        }, 201
コード例 #10
0
    def on_post(self, req, res):
        email = req.context["data"]["email"]
        password = hash_password(req.context["data"]["password"])

        try:
            self.cursor.callproc("sp_user_insert", [email, password])
        except IntegrityError:
            title = "Conflict"
            description = "Email in use"
            raise falcon.HTTPConflict(title, description)

        result = self.cursor.fetchone()[0]

        res.status = falcon.HTTP_201
        res.body = json.dumps({"token": generate_token(result)})
コード例 #11
0
ファイル: handlers.py プロジェクト: projectweekend/makerdb
    def on_post(self, req, res):
        unauthorized_title = 'Unauthorized'
        unauthorized_description = 'Invalid credentials'

        email = req.context['data']['email']
        password = req.context['data']['password']

        user = self.find_user_by_email(email)
        if user is None:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        valid_password = verify_password(password, user.pop('password'))
        if not valid_password:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        req.context['result'] = {'token': generate_token(user)}
        res.status = falcon.HTTP_OK
コード例 #12
0
    def on_post(self, req, res):
        email = req.context['data']['email']
        password = hash_password(req.context['data']['password'])

        try:
            self.cursor.callproc('sp_user_insert', [email, password])
        except IntegrityError:
            title = 'Conflict'
            description = 'Email in use'
            raise falcon.HTTPConflict(title, description)

        result = self.cursor.fetchone()[0]

        res.status = falcon.HTTP_201
        res.body = json.dumps({
            'token': generate_token(result)
        })
コード例 #13
0
    def on_post(self, req, res):
        unauthorized_title = 'Unauthorized'
        unauthorized_description = 'Invalid credentials'

        email = req.context['data']['email']
        password = req.context['data']['password']

        user = self.find_user_by_email(email)
        if user is None:
            raise falcon.HTTPUnauthorized(unauthorized_title,
                                          unauthorized_description)

        valid_password = verify_password(password, user.pop('password'))
        if not valid_password:
            raise falcon.HTTPUnauthorized(unauthorized_title,
                                          unauthorized_description)

        req.context['result'] = {'token': generate_token(user)}
        res.status = falcon.HTTP_OK
コード例 #14
0
    def on_post(self, req, res):
        unauthorized_title = "Unauthorized"
        unauthorized_description = "Invalid credentials"

        email = req.context["data"]["email"]
        password = req.context["data"]["password"]

        self.cursor.callproc("sp_lookup_user_by_email", [email])

        result = self.cursor.fetchone()
        if result is None:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        result = result[0]

        valid_password = verify_password(password, result.pop("password"))
        if not valid_password:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        res.status = falcon.HTTP_200
        res.body = json.dumps({"token": generate_token(result)})
コード例 #15
0
    def on_post(self, req, res):
        unauthorized_title = 'Unauthorized'
        unauthorized_description = 'Invalid credentials'

        email = req.context['data']['email']
        password = req.context['data']['password']

        self.cursor.callproc('sp_lookup_user_by_email', [email, ])

        result = self.cursor.fetchone()
        if result is None:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        result = result[0]

        valid_password = verify_password(password, result.pop('password'))
        if not valid_password:
            raise falcon.HTTPUnauthorized(unauthorized_title, unauthorized_description)

        res.status = falcon.HTTP_200
        res.body = json.dumps({
            'token': generate_token(result)
        })