From b3ad4383f40b99a8931d3d4f00152778bf60de8f Mon Sep 17 00:00:00 2001 From: Kload Date: Tue, 24 Sep 2013 16:54:33 +0200 Subject: [PATCH] Handle password fails, document API calls & domain list/add --- css/style.css | 10 +++---- index.html | 1 + js/app.js | 64 ++++++++++++++++++++++++++++++++++------ views/domain_add.ms | 69 ++++++++++++++++++++++++++++++++++++++++++++ views/domain_list.ms | 19 ++++++++++++ views/user_create.ms | 13 ++++----- 6 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 views/domain_add.ms create mode 100644 views/domain_list.ms diff --git a/css/style.css b/css/style.css index decb071d..59b34f38 100644 --- a/css/style.css +++ b/css/style.css @@ -35,11 +35,11 @@ html, body { padding: 5px; } -.panel-title { - font-size: 18px; - font-weight: bold; - line-height: 25px; -} +/*.panel-title {*/ + /*font-size: 18px;*/ + /*font-weight: bold;*/ + /*line-height: 25px;*/ +/*}*/ body .form-control { padding: 6px; diff --git a/index.html b/index.html index 2749ba89..c383add1 100644 --- a/index.html +++ b/index.html @@ -33,6 +33,7 @@ + diff --git a/js/app.js b/js/app.js index 20b68711..3d87e95b 100644 --- a/js/app.js +++ b/js/app.js @@ -63,7 +63,14 @@ app = Sammy('#main', function (sam) { callback(data); }) .fail(function(xhr) { - c.flash('fail', xhr.responseJSON.error); + console.log(xhr); + if (xhr.status == 401) { + c.flash('fail', 'Wrong password'); + } else if (typeof xhr.responseJSON !== 'undefined') { + c.flash('fail', xhr.responseJSON.error); + } else { + c.flash('fail', 'Server error'); + } c.redirect(store.get('path-1')); store.clear('slide'); }) @@ -129,7 +136,7 @@ app = Sammy('#main', function (sam) { store.set('path', req.path); // Redirect to login page if no credentials stored - if (!store.get('password')) { + if (!store.get('connected')) { req.redirect('#/login'); return false; } @@ -160,6 +167,7 @@ app = Sammy('#main', function (sam) { sam.get('#/login', function (c) { $('#disconnect-button').hide(); + store.set('path-1', '#/login'); c.view('login'); }); @@ -168,6 +176,7 @@ app = Sammy('#main', function (sam) { store.set('user', 'admin'); store.set('password', btoa(c.params['password'])); c.api('/users', function(data) { + store.set('connected', true); $('#disconnect-button').fadeIn(); if (store.get('path')) { c.redirect(store.get('path')); @@ -177,14 +186,19 @@ app = Sammy('#main', function (sam) { }); }); + /** + * Users + * + */ + sam.get('#/users', function (c) { - c.api('/users', function(data) { + c.api('/users', function(data) { // http://api.yunohost.org/#!/user/user_list_get_3 c.view('user_list', data); }); }); sam.get('#/users/create', function (c) { - c.api('/domains', function(data) { + c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_list_get_2 c.view('user_create', data); }); }); @@ -192,7 +206,7 @@ app = Sammy('#main', function (sam) { sam.post('#/users', function (c) { if (c.params['password'] == c.params['confirmation']) { c.params['mail'] = c.params['email'] + '@' + c.params['domain']; - c.api('/users', function(data) { + c.api('/users', function(data) { // http://api.yunohost.org/#!/user/user_create_post_2 c.redirect('#/users'); }, 'POST', c.params.toHash()); } else { @@ -203,13 +217,13 @@ app = Sammy('#main', function (sam) { }); sam.get('#/users/:user', function (c) { - c.api('/users/'+ c.params['user'], function(data) { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0 c.view('user_info', data); }); }); sam.get('#/users/:user/edit', function (c) { - c.api('/users/'+ c.params['user'], function(data) { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_info_get_0 c.view('user_edit', data); }); }); @@ -224,7 +238,7 @@ app = Sammy('#main', function (sam) { store.clear('slide'); c.redirect('#/users/'+ c.params['user'] + '/edit'); } else { - c.api('/users/'+ c.params['user'], function(data) { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_update_put_1 c.redirect('#/users/'+ c.params['user']); }, 'PUT', params); } @@ -232,7 +246,7 @@ app = Sammy('#main', function (sam) { sam.get('#/users/:user/delete', function (c) { if (confirm('Are you sure you want to delete '+ c.params['user'] +' ?')) { - c.api('/users/'+ c.params['user'], function(data) { + c.api('/users/'+ c.params['user'], function(data) { // http://api.yunohost.org/#!/user/user_delete_delete_4 c.redirect('#/users'); }, 'DELETE'); } else { @@ -240,6 +254,38 @@ app = Sammy('#main', function (sam) { c.redirect('#/users/'+ c.params['user']); } }); + + /** + * Domains + * + */ + + sam.get('#/domains', function (c) { + c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_list_get_2 + c.view('domain_list', data); + }); + }); + + sam.get('#/domains/add', function (c) { + c.view('domain_add', {'DDomains': ['.nohost.me', '.noho.st']}); + }); + + sam.post('#/domains', function (c) { + if (c.params['domain'] == '') { + if (c.params['ddomain'] == '') { + c.flash('fail', "You should indicate a domain"); + store.clear('slide'); + c.redirect('#/domains/add'); + } + params = { 'domains': c.params['ddomain'] + c.params['ddomain-ext'] } + } else { + params = { 'domains': c.params['domain'] } + } + + c.api('/domains', function(data) { // http://api.yunohost.org/#!/domain/domain_add_post_1 + c.redirect('#/domains'); + }, 'POST', params); + }); }); diff --git a/views/domain_add.ms b/views/domain_add.ms new file mode 100644 index 00000000..d315fd9c --- /dev/null +++ b/views/domain_add.ms @@ -0,0 +1,69 @@ +
+ Domain list +
+
+
Add domain
+ +
+ +
+ +
+
+ +
+
+ ... and I have set my DNS correctly. +
+
+ +
+ +
+
+
+
+
+
+ +
+
+ ... and I want a dynamic DNS service. +
+
+ +
+ +
+
+ +
+
+
+
+
+
+ +
+ +
+ +
+ +
diff --git a/views/domain_list.ms b/views/domain_list.ms new file mode 100644 index 00000000..4f0049be --- /dev/null +++ b/views/domain_list.ms @@ -0,0 +1,19 @@ +
+ Menu +
+
+ Add domain +
+
+
Domains
+
+ +
+{{#Domains}} + +

{{.}}

+ +
+
+{{/Domains}} +
diff --git a/views/user_create.ms b/views/user_create.ms index 56a5ad43..b7526879 100644 --- a/views/user_create.ms +++ b/views/user_create.ms @@ -32,14 +32,11 @@
-
- @ - -
+