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
|
@ -69,7 +69,7 @@ def tick():
|
|||
q.enqueue(update_feed, feed.id)
|
||||
|
||||
|
||||
def update_feed(feed_id, content=None,
|
||||
def update_feed(feed_id, content=None,
|
||||
content_type=None, is_polling=True):
|
||||
|
||||
def is_expected_content_type(feed_type):
|
||||
|
|
|
@ -13,34 +13,35 @@
|
|||
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
|
||||
<script src="{{ url_for('static', filename='moment.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='cassis.js') }}"></script>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
{% if current_user.is_authenticated() %}
|
||||
<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;" />
|
||||
Woodwind
|
||||
</span>
|
||||
<ul id="navigation">
|
||||
<li>
|
||||
<a href="{{ url_for('.index') }}">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('.subscriptions') }}">Subscriptions</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('.settings') }}">Settings</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ current_user.url }}
|
||||
(<a href="{{ url_for('.logout') }}">Logout</a>)
|
||||
</li>
|
||||
</ul>
|
||||
<div style="overflow: auto;">
|
||||
<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;" />
|
||||
Woodwind
|
||||
</span>
|
||||
<ul id="navigation">
|
||||
<li>
|
||||
<a href="{{ url_for('.index') }}">Home</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('.subscriptions') }}">Subscriptions</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('.settings') }}">Settings</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ current_user.url }}
|
||||
(<a href="{{ url_for('.logout') }}">Logout</a>)
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<h1 class="h-x-app">
|
||||
|
@ -48,6 +49,11 @@
|
|||
Woodwind
|
||||
</h1>
|
||||
{% endif %}
|
||||
|
||||
{% for message in get_flashed_messages() %}
|
||||
<div class="flash">{{ message }}</div>
|
||||
{% endfor %}
|
||||
|
||||
{% if not current_user.is_authenticated() %}
|
||||
<form action="{{ url_for('.login') }}" method="POST">
|
||||
<input type="url" name="me" placeholder="https://yourdomain.com" />
|
||||
|
@ -59,9 +65,7 @@
|
|||
{% endif %}
|
||||
|
||||
{% block header %}{% endblock %}
|
||||
{% for message in get_flashed_messages() %}
|
||||
<div class="flash">{{ message | safe }}</div>
|
||||
{% endfor %}
|
||||
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
@ -70,27 +74,35 @@
|
|||
{% block foot %}{% endblock %}
|
||||
|
||||
<script>
|
||||
$("input[type='url']").blur(function() {
|
||||
if (this.value.trim() != '') {
|
||||
$("input[type='url']").blur(function() {
|
||||
if (this.value.trim() != '') {
|
||||
this.value = web_address_to_uri(this.value, true);
|
||||
}
|
||||
});
|
||||
|
||||
$("input[type='url']").on("invalid", function() {
|
||||
this.value = web_address_to_uri(this.value, true);
|
||||
if (this.willValidate) {
|
||||
this.setCustomValidity('');
|
||||
this.parentNode.submit();
|
||||
return false;
|
||||
} else if (document.getElementById('error')) {
|
||||
|
||||
} else {
|
||||
var html = document.createElement("div");
|
||||
html.id = 'error';
|
||||
html.innerHTML = "Oops! looks like you didn't enter a URL. Try starting with http://";
|
||||
this.parentNode.appendChild($html)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$("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);
|
||||
if (this.willValidate) {
|
||||
this.setCustomValidity('');
|
||||
this.parentNode.submit();
|
||||
return false;
|
||||
} else if (document.getElementById('error')) {
|
||||
return true;
|
||||
} else {
|
||||
var html = document.createElement("div");
|
||||
html.id = 'error';
|
||||
html.innerHTML = "Oops! looks like you didn't enter a URL. Try starting with http://";
|
||||
this.parentNode.appendChild(html);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -228,9 +228,13 @@ def logout():
|
|||
|
||||
@views.route('/login', methods=['POST'])
|
||||
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(
|
||||
flask.request.form.get('me'),
|
||||
next_url=flask.request.form.get('next'))
|
||||
me=me, next_url=flask.request.form.get('next'))
|
||||
|
||||
|
||||
@views.route('/login-callback')
|
||||
|
@ -325,7 +329,8 @@ def load_user(url):
|
|||
@views.route('/subscribe', methods=['GET', 'POST'])
|
||||
@flask_login.login_required
|
||||
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:
|
||||
type = None
|
||||
feed = None
|
||||
|
@ -390,7 +395,13 @@ def add_subscription(origin, feed_url, type, tags=None):
|
|||
|
||||
def find_possible_feeds(origin):
|
||||
# scrape an origin source to find possible alternative feeds
|
||||
resp = requests.get(origin)
|
||||
try:
|
||||
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 = []
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue