diff --git a/piston/register/views.py b/piston/register/views.py index 04fd2f2..2b320f7 100644 --- a/piston/register/views.py +++ b/piston/register/views.py @@ -15,7 +15,7 @@ along with Piston. If not, see . """ -from flask import Blueprint, render_template, request +from flask import Blueprint, render_template, request, url_for, current_app from urllib.parse import urlparse import piston @@ -27,12 +27,16 @@ def checkconfig(): """Retreive a configuration from a given URL and ensure that it complies with the rules.""" config = request.args.copy() - if "redirect_url" not in config: - raise exceptions.ConfigurationException("You're is missing a redirect_url!", config) - redirect = urlparse(config['redirect_url']) - if redirect.scheme != "https": - raise exceptions.InsecureRedirectException("The redirect_url must be https") - config['domain'] = redirect.netloc + if "desktop" in config: + if "name" not in config: + raise exceptions.ConfigurationException("You must specify a name for desktop tokens!") + elif "redirect_url" not in config: + raise exceptions.ConfigurationException("You're is missing a redirect_url!") + else: + redirect = urlparse(config['redirect_url']) + if redirect.scheme != "https": + raise exceptions.InsecureRedirectException("The redirect_url must be https") + config['domain'] = redirect.netloc return config @@ -43,6 +47,7 @@ def register_page(): config = checkconfig() return render_template("register.html", c=config, + desktop="desktop" in config, root=request.headers['Host']) except exceptions.ConfigurationException as e: return render_template("error.html", error=e) @@ -60,7 +65,12 @@ def post_register(): subscription=subscription) piston.db.session.add(registration) piston.db.session.commit() + token = "https://%s:%s@%s%s" % ("token", registration.token, + current_app.config.get("SERVER_NAME", "localhost"), + url_for('notification.create')) return render_template("post_register.html", redirect_url=request.form.get("redirect_url"), - registration=registration, nonce=request.form.get("nonce", None)) + registration=registration, token=token, + name=request.form.get('name'), + nonce=request.form.get("nonce")) else: return "okay, bye" diff --git a/piston/static/js/post_register.js b/piston/static/js/post_register.js index b7b4317..45c32fc 100644 --- a/piston/static/js/post_register.js +++ b/piston/static/js/post_register.js @@ -15,4 +15,10 @@ You should have received a copy of the GNU General Public License along with Piston. If not, see . */ -document.querySelector(".redirect-form").submit(); +if(document.querySelector(".redirect-form") !== null) { + document.querySelector(".redirect-form").submit(); +} + +if(document.querySelector(".token-box") !== null) { + document.querySelector(".token-box").select(); +} diff --git a/piston/templates/post_register.html b/piston/templates/post_register.html index e036bd6..456d246 100644 --- a/piston/templates/post_register.html +++ b/piston/templates/post_register.html @@ -17,22 +17,25 @@ {% extends 'base.html' %} {% block title %}Register{% endblock %} -{% block content %} -
- +{% block body %} +{% if redirect_url is none %} +
-

+

Authorization Created

- Forwarding you back to {{ redirect_url }} with token {{ registration.token }} + Below is your token, paste it into {{ name }}

- +
+ +
- +{% else %}
{% if nonce is not none %}{% endif %}
+{% endif %} {% endblock %} {% block js %} diff --git a/piston/templates/register.html b/piston/templates/register.html index acb9573..db96592 100644 --- a/piston/templates/register.html +++ b/piston/templates/register.html @@ -22,8 +22,9 @@

Allow {% if c.name is string %}{{ c.name }}{% else %}{{ c.domain }}{% endif %} to send you notifications?

- {% if c.name is string %}{{ c.name }} ({{ c.domain }}){% else %}{{ c.domain }}{% endif %} would like to send push notifications to your device. - You can edit this preference at any time by visiting {{ root }} + {% if desktop %}{{ c.name }}{% else %}{% if c.name is string %}{{ c.name }} ({{ c.domain }}){% else %}{{ c.domain }}{% endif %}{% endif %} + would like to send push notifications to your device. You can edit this preference at any time by visiting + {{ root }}

@@ -41,7 +42,7 @@

Allow {% if c.name is string %}{{ c.name }}{% else %}{{ c