mirror of
https://github.com/yawaflua/Flask-Discord.git
synced 2025-12-10 12:29:30 +02:00
Merge pull request #21 from williamhatcher/master
Add Unauthorized redirect to basic usage
This commit is contained in:
@@ -14,7 +14,7 @@ python3 -m pip install Flask-Discord
|
||||
### Basic Example
|
||||
```python
|
||||
from flask import Flask, redirect, url_for
|
||||
from flask_discord import DiscordOAuth2Session, requires_authorization
|
||||
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -37,7 +37,12 @@ def login():
|
||||
def callback():
|
||||
discord.callback()
|
||||
return redirect(url_for(".me"))
|
||||
|
||||
|
||||
|
||||
@app.errorhandler(Unauthorized)
|
||||
def redirect_unauthorized(e):
|
||||
return redirect(url_for("login"))
|
||||
|
||||
|
||||
@app.route("/me/")
|
||||
@requires_authorization
|
||||
|
||||
@@ -43,7 +43,7 @@ in exchange for fetching user's details and display them on web page.
|
||||
.. code-block:: python3
|
||||
|
||||
from flask import Flask, redirect, url_for
|
||||
from flask_discord import DiscordOAuth2Session, requires_authorization
|
||||
from flask_discord import DiscordOAuth2Session, requires_authorization, Unauthorized
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -69,6 +69,11 @@ in exchange for fetching user's details and display them on web page.
|
||||
return redirect(url_for(".me"))
|
||||
|
||||
|
||||
@app.errorhandler(Unauthorized)
|
||||
def redirect_unauthorized(e):
|
||||
return redirect(url_for("login"))
|
||||
|
||||
|
||||
@app.route("/me/")
|
||||
@requires_authorization
|
||||
def me():
|
||||
@@ -85,4 +90,4 @@ in exchange for fetching user's details and display them on web page.
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
app.run()
|
||||
|
||||
Reference in New Issue
Block a user