catch some common login and subscribe errors and inform the user

This commit is contained in:
Kyle Mahan 2015-08-02 22:13:46 -07:00
parent 1da7a9130e
commit 4d6880c284
3 changed files with 71 additions and 48 deletions

View file

@ -19,28 +19,29 @@
{% block head %}{% endblock %} {% block head %}{% endblock %}
</head> </head>
<body> <body>
<header> <header>
{% if current_user.is_authenticated() %} {% if current_user.is_authenticated() %}
<span class="h-x-app" style="font-weight: bold"> <div style="overflow: auto;">
<img class="u-logo" src="{{ url_for('static', filename='logo.png') }}" style="max-height: 1.5em; vertical-align: middle;" /> <span class="h-x-app" style="font-weight: bold">
Woodwind <img class="u-logo" src="{{ url_for('static', filename='logo.png') }}" style="max-height: 1.5em; vertical-align: middle;" />
</span> Woodwind
<ul id="navigation"> </span>
<li> <ul id="navigation">
<a href="{{ url_for('.index') }}">Home</a> <li>
</li> <a href="{{ url_for('.index') }}">Home</a>
<li> </li>
<a href="{{ url_for('.subscriptions') }}">Subscriptions</a> <li>
</li> <a href="{{ url_for('.subscriptions') }}">Subscriptions</a>
<li> </li>
<a href="{{ url_for('.settings') }}">Settings</a> <li>
</li> <a href="{{ url_for('.settings') }}">Settings</a>
<li> </li>
{{ current_user.url }} <li>
(<a href="{{ url_for('.logout') }}">Logout</a>) {{ current_user.url }}
</li> (<a href="{{ url_for('.logout') }}">Logout</a>)
</ul> </li>
</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>
@ -70,27 +74,35 @@
{% block foot %}{% endblock %} {% block foot %}{% endblock %}
<script> <script>
$("input[type='url']").blur(function() { $("input[type='url']").blur(function() {
if (this.value.trim() != '') { if (this.value.trim() != '') {
this.value = web_address_to_uri(this.value, true); 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> </script>
</body> </body>
</html> </html>

View file

@ -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
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 = [] feeds = []