catch some common login and subscribe errors and inform the user
This commit is contained in:
parent
1da7a9130e
commit
4d6880c284
3 changed files with 71 additions and 48 deletions
|
@ -19,9 +19,9 @@
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
{% if current_user.is_authenticated() %}
|
{% if current_user.is_authenticated() %}
|
||||||
|
<div style="overflow: auto;">
|
||||||
<span class="h-x-app" style="font-weight: bold">
|
<span class="h-x-app" style="font-weight: bold">
|
||||||
<img class="u-logo" src="{{ url_for('static', filename='logo.png') }}" style="max-height: 1.5em; vertical-align: middle;" />
|
<img class="u-logo" src="{{ url_for('static', filename='logo.png') }}" style="max-height: 1.5em; vertical-align: middle;" />
|
||||||
Woodwind
|
Woodwind
|
||||||
|
@ -41,6 +41,7 @@
|
||||||
(<a href="{{ url_for('.logout') }}">Logout</a>)
|
(<a href="{{ url_for('.logout') }}">Logout</a>)
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<h1 class="h-x-app">
|
<h1 class="h-x-app">
|
||||||
|
@ -48,6 +49,11 @@
|
||||||
Woodwind
|
Woodwind
|
||||||
</h1>
|
</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="flash">{{ message }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if not current_user.is_authenticated() %}
|
{% if not current_user.is_authenticated() %}
|
||||||
<form action="{{ url_for('.login') }}" method="POST">
|
<form action="{{ url_for('.login') }}" method="POST">
|
||||||
<input type="url" name="me" placeholder="https://yourdomain.com" />
|
<input type="url" name="me" placeholder="https://yourdomain.com" />
|
||||||
|
@ -59,9 +65,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block header %}{% endblock %}
|
{% block header %}{% endblock %}
|
||||||
{% for message in get_flashed_messages() %}
|
|
||||||
<div class="flash">{{ message | safe }}</div>
|
|
||||||
{% endfor %}
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
|
@ -76,19 +80,27 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$("input[type='url']").on("invalid", function() {
|
$("input[type='url']").on("invalid", function() {
|
||||||
|
if (this.value.trim() == '') {
|
||||||
|
console.log('value is empty');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.value = web_address_to_uri(this.value, true);
|
this.value = web_address_to_uri(this.value, true);
|
||||||
if (this.willValidate) {
|
if (this.willValidate) {
|
||||||
this.setCustomValidity('');
|
this.setCustomValidity('');
|
||||||
this.parentNode.submit();
|
this.parentNode.submit();
|
||||||
return false;
|
return false;
|
||||||
} else if (document.getElementById('error')) {
|
} else if (document.getElementById('error')) {
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
var html = document.createElement("div");
|
var html = document.createElement("div");
|
||||||
html.id = 'error';
|
html.id = 'error';
|
||||||
html.innerHTML = "Oops! looks like you didn't enter a URL. Try starting with http://";
|
html.innerHTML = "Oops! looks like you didn't enter a URL. Try starting with http://";
|
||||||
this.parentNode.appendChild($html)
|
this.parentNode.appendChild(html);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -228,9 +228,13 @@ def logout():
|
||||||
|
|
||||||
@views.route('/login', methods=['POST'])
|
@views.route('/login', methods=['POST'])
|
||||||
def login():
|
def login():
|
||||||
|
me = flask.request.form.get('me')
|
||||||
|
if not me or me == 'http://':
|
||||||
|
flask.flash('Sign in with your personal web address.')
|
||||||
|
return flask.redirect(flask.url_for('.index'))
|
||||||
|
|
||||||
return micropub.authenticate(
|
return micropub.authenticate(
|
||||||
flask.request.form.get('me'),
|
me=me, next_url=flask.request.form.get('next'))
|
||||||
next_url=flask.request.form.get('next'))
|
|
||||||
|
|
||||||
|
|
||||||
@views.route('/login-callback')
|
@views.route('/login-callback')
|
||||||
|
@ -325,7 +329,8 @@ def load_user(url):
|
||||||
@views.route('/subscribe', methods=['GET', 'POST'])
|
@views.route('/subscribe', methods=['GET', 'POST'])
|
||||||
@flask_login.login_required
|
@flask_login.login_required
|
||||||
def subscribe():
|
def subscribe():
|
||||||
origin = flask.request.form.get('origin') or flask.request.args.get('origin')
|
origin = (flask.request.form.get('origin')
|
||||||
|
or flask.request.args.get('origin'))
|
||||||
if origin:
|
if origin:
|
||||||
type = None
|
type = None
|
||||||
feed = None
|
feed = None
|
||||||
|
@ -390,7 +395,13 @@ def add_subscription(origin, feed_url, type, tags=None):
|
||||||
|
|
||||||
def find_possible_feeds(origin):
|
def find_possible_feeds(origin):
|
||||||
# scrape an origin source to find possible alternative feeds
|
# scrape an origin source to find possible alternative feeds
|
||||||
|
try:
|
||||||
resp = requests.get(origin)
|
resp = requests.get(origin)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
flask.flash('Error fetching source {}'.format(repr(e)))
|
||||||
|
flask.current_app.logger.warn(
|
||||||
|
'Subscribe failed for %s with error %s', origin, repr(e))
|
||||||
|
return None
|
||||||
|
|
||||||
feeds = []
|
feeds = []
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue