Commit 628b11bd authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Update token view/url

introduce a helper view to allow user update the account api token.
``renewToken`` javascript helper method is included in forms.js.
parent 2af68e14
......@@ -54,6 +54,7 @@ ACCOUNT_USER_ACTIVATION_PENDING = 'You have not followed the activatio
ACCOUNT_UNKNOWN = 'It seems there is no account with those .'
TOKEN_UNKNOWN = 'There is no user matching this token.'
TOKEN_UPDATED = 'Your ~okeanos account token was updated.'
PROFILE_UPDATED = 'Your profile has been updated successfully.'
FEEDBACK_SENT = 'Thank you for your feedback. We will process it carefully.'
......
......@@ -123,6 +123,27 @@
});
};
var MIDDLEWARE_TOKEN_INPUT_NAME = window.MIDDLEWARE_TOKEN_INPUT_NAME || 'csrfmiddlewaretoken';
var CHANGE_TOKEN_URL = window.CHANGE_TOKEN_URL || '/im/profile/update_token';
function renewToken() {
var csrf_value = $("input[name="+MIDDLEWARE_TOKEN_INPUT_NAME+"]").val();
var url = CHANGE_TOKEN_URL;
var form = $("<form>");
var csrf = $('<input>');
form.attr('action', url);
form.attr('method', 'POST');
csrf.attr('value', csrf_value);
csrf.attr('name', MIDDLEWARE_TOKEN_INPUT_NAME);
form.append(csrf);
$("body").prepend(form);
form.submit();
}
window.renewToken= renewToken;
})( jQuery );
......
......@@ -43,6 +43,7 @@ urlpatterns = patterns(
'astakos.im.views',
url(r'^$', 'index', {}, name='index'),
url(r'^login/?$', 'index', {}, name='login'),
url(r'^profile/update_token?$', 'update_token', {}, name='update_token'),
url(r'^profile/?$','edit_profile', {}, name='edit_profile'),
url(r'^feedback/?$', 'feedback', {}, name='feedback'),
url(r'^signup/?$', 'signup', {'on_success': 'index', 'extra_context': {'login_form': LoginForm()}}, name='signup'),
......
......@@ -250,6 +250,19 @@ def index(request, login_template_name='im/login.html', profile_template_name='i
)
@require_http_methods(["POST"])
@valid_astakos_user_required
def update_token(request):
"""
Update api token view.
"""
user = request.user
user.renew_token()
user.save()
messages.success(request, astakos_messages.TOKEN_UPDATED)
return HttpResponseRedirect(reverse('edit_profile'))
@require_http_methods(["GET", "POST"])
@valid_astakos_user_required
@transaction.commit_manually
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment