Beispiel #1
0
def cancel_account():
    """
    user can cancel their account, if get this api their token will be added into blacklist.
    once token has been added into blacklist, user's account will be deleted from database
    :return:
    """
    if request.json:
        try:
            #添加用户的去重
            name = request.json.get('name',None)
            get_user = User.query.filter_by(name=name).first()
            if not get_user:
                return  http_response(250, 'bad', 'user not exist')
            try:
                current_user = get_jwt_identity()
                if current_user == get_user.name:
                    try:
                        db.session.delete(get_user)
                        db.session.commit()
                    except:
                        db.session.rollback()
                    jti = get_raw_jwt()['jti']
                    blacklist.add(jti)

            except Exception:
                return http_response(250, 'bad', 'user cancel failed')
            # pass
        except Exception as e:
            print(e.args)
            return http_response(250, 'bad', 'user cancel failed')

        return http_response(460,'ok','user canceled, thanks for using pan')

    else:
        return http_response(250, 'bad', 'json data required')
Beispiel #2
0
    def delete(self):
        jti = get_raw_jwt()["jti"]
        blacklist.add(jti)
        emp_id = get_jwt_identity()

        last_login_entry = models.Employees_Logins.query.filter_by(Emp_id=emp_id).first()
        db.session.commit()

        return {"message": "Successfully logged out"}, 200
def logout():
    try:
        jti = get_raw_jwt()['jti']
        blacklist.add(jti)
    except Exception as e:
        logger.warning(
            f'logout failed with errors: {e}')
        return {'message': str(e)}, 400
    return {"msg": "Successfully logged out"}, 200
Beispiel #4
0
 def post(self):
     jti = get_raw_jwt()['jti']
     blacklist.add(jti)
     response = jsonify({
         "message": "Successfully logout",
         "code": 200,
         "email": get_jwt_identity()
     })
     response.status_code = 200
     return response
Beispiel #5
0
def logout():
    try:
        # current_user = get_jwt_identity()
        jti = get_raw_jwt()['jti']
        blacklist.add(jti)

    except:
        return http_response(250, 'bad', 'user logout failed')

    return http_response(460, 'ok', 'user logout, thanks for using pan')
Beispiel #6
0
 def delete(self):
     try:
         jti = get_raw_jwt()['jti']
         blacklist.add(jti)
         responseObject = {
             'status': 'success',
             'message': 'Successfully logged out.'
         }
         return make_response(jsonify(responseObject)), 200
     except Exception as e:
         responseObject = {'status': 'fail', 'message': str(e)}
         return make_response(jsonify(responseObject)), 200
Beispiel #7
0
 def delete(self):
     """
     This method is used to revoke Token/clear token if user access token is valid
     :return: dict
     """
     jti = get_raw_jwt()['jti']
     blacklist.add(jti)
     return make_response(
         jsonify({
             'message': "Successfully logged out",
             'status_code': 200
         }), 200)
def logout(jti):
    blacklist.add(jti)
Beispiel #9
0
def logout2():
    jti = get_raw_jwt()['jti']
    blacklist.add(jti)
    return jsonify({"msg": "Successfully logged out"}), 200
Beispiel #10
0
 def get(self):
   from app import blacklist
   jti = get_raw_jwt()['jti']
   blacklist.add(jti)
   return {"message": "Successfully logged out"}, 200