def delete(self): """ Logout a user """ jti = get_raw_jwt()['jti'] blist = Blacklist(jti=jti) blist.save_to_db() return {"message": "Successfully logged out"}, 200
def blacklist_insert(): form = BlacklistForm(request.form) if request.method == 'POST': if form.validate_on_submit(): blacklist = Blacklist.query.filter_by(clid=form.clid.data).first() if blacklist: flash('Order exist') return redirect(url_for('pbx.blacklist_index')) clid = form.clid.data ticket = form.ticket.data active = form.active.data owner = current_user.fullname history = f"{clid},{ticket},{active},{owner},{time};" blacklist = Blacklist(clid=clid, ticket=ticket, owner=owner, active=active, history=history) db.session.add(blacklist) db.session.commit() flash("Blacklist Inserted Successfully") else: flash("Wrong insert") return redirect(url_for('pbx.blacklist_index'))
def reset_token(token): if current_user.is_authenticated: return redirect(url_for(('main.home'))) user = User.verify_reset_token(token) valid_token = Blacklist.verify_fresh_reset_token(token) if user is None or valid_token is not None: flash('That is an invalid or expired token', 'success') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password used_token = Blacklist(token=token) db.session.add(used_token) db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('main.home')) return render_template('reset_token.html', title='Reset Password', form=form)
def post(self): """POST request handling for current user logout """ auth_header = request.headers.get('Authorization') access_token = auth_header.split(" ")[1] try: if access_token: blacklisted = Blacklist.query.filter_by( used_token=access_token).first() if not blacklisted: new_blacklist = Blacklist(access_token) new_blacklist.save() response = {'message': 'Logged out successfully.'} return crossdomain(response, 'post'), 200 else: response = { 'message': 'Token not valid. Please log in again.' } return make_response(jsonify(response)), 401 except Exception as e: response = {'message': str(e)} return make_response(jsonify(response)), 500
def logout(): jti = get_raw_jwt()['jti'] blacklist = Blacklist(token=jti) blacklist.save() return jsonify({'message': 'Successfully logged out.'}), 200
def check_if_token_in_blacklist(decrypted_token): jti = decrypted_token['jti'] isthere = Blacklist.get_or_create(jti) return isthere