From d62f0d4a61e545f1d7b606fc915df0026d3dca76 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Thu, 1 Aug 2013 02:11:45 +0100 Subject: [PATCH] Login / Signup forms now use Backbone * Moved most of control code to `core/client` * Implemented ajax checks --- ghost/admin/router.js | 15 +++++- ghost/admin/tpl/login.hbs | 12 +++++ ghost/admin/tpl/signup.hbs | 12 +++++ ghost/admin/views/login.js | 105 +++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 ghost/admin/tpl/login.hbs create mode 100644 ghost/admin/tpl/signup.hbs create mode 100644 ghost/admin/views/login.js diff --git a/ghost/admin/router.js b/ghost/admin/router.js index 644bde56c6..1157aa77fe 100644 --- a/ghost/admin/router.js +++ b/ghost/admin/router.js @@ -11,7 +11,18 @@ 'settings(/:pane)' : 'settings', 'editor/' : 'editor', 'editor(/:id)' : 'editor', - 'debug/' : 'debug' + 'debug/' : 'debug', + 'register/' : 'register', + 'signup/' : 'signup', + 'login/' : 'login' + }, + + signup: function () { + Ghost.currentView = new Ghost.Views.Signup({ el: '.js-login-container' }); + }, + + login: function () { + Ghost.currentView = new Ghost.Views.Login({ el: '.js-login-container' }); }, blog: function () { @@ -456,4 +467,4 @@ //}); } }); -}()); \ No newline at end of file +}()); diff --git a/ghost/admin/tpl/login.hbs b/ghost/admin/tpl/login.hbs new file mode 100644 index 0000000000..e955902bf2 --- /dev/null +++ b/ghost/admin/tpl/login.hbs @@ -0,0 +1,12 @@ +
+ +
+ +
+ +
+ Forgotten password?Register new user +
+
diff --git a/ghost/admin/tpl/signup.hbs b/ghost/admin/tpl/signup.hbs new file mode 100644 index 0000000000..d016339f56 --- /dev/null +++ b/ghost/admin/tpl/signup.hbs @@ -0,0 +1,12 @@ +
+ +
+ +
+ +
+ Log in +
+
diff --git a/ghost/admin/views/login.js b/ghost/admin/views/login.js new file mode 100644 index 0000000000..d29e5b336e --- /dev/null +++ b/ghost/admin/views/login.js @@ -0,0 +1,105 @@ +/*global window, document, Ghost, $, _, Backbone, JST */ +(function () { + "use strict"; + + Ghost.Views.Login = Ghost.View.extend({ + + templateName: "login", + + events: { + 'submit #login': 'submitHandler' + }, + + initialize: function (options) { + this.render(); + }, + + template: function (data) { + return JST[this.templateName](data); + }, + + render: function () { + this.$el.html(this.template()); + return this; + }, + + submitHandler: function (event) { + event.preventDefault(); + var email = this.$el.find('.email').val(), + password = this.$el.find('.password').val(), + self = this; + + $.ajax({ + url: '/ghost/login/', + type: 'POST', + data: { + email: email, + password: password + }, + success: function (msg) { + window.location.href = msg.redirect; + }, + error: function (obj, string, status) { + self.addSubview(new Ghost.Views.NotificationCollection({ + model: [{ + type: 'error', + message: 'Invalid username or password', + status: 'passive' + }] + })); + } + }); + } + }); + + Ghost.Views.Signup = Ghost.View.extend({ + + templateName: "signup", + + events: { + 'submit #register': 'submitHandler' + }, + + initialize: function (options) { + this.render(); + }, + + template: function (data) { + return JST[this.templateName](data); + }, + + render: function () { + this.$el.html(this.template()); + return this; + }, + + submitHandler: function (event) { + event.preventDefault(); + var email = this.$el.find('.email').val(), + password = this.$el.find('.password').val(), + self = this; + + $.ajax({ + url: '/ghost/signup/', + type: 'POST', + data: { + email: email, + password: password + }, + success: function (msg) { + window.location.href = msg.redirect; + }, + error: function (obj, string, status) { + var msgobj = $.parseJSON(obj.responseText); + self.addSubview(new Ghost.Views.NotificationCollection({ + model: [{ + type: 'error', + message: msgobj.message, + status: 'passive' + }] + })); + } + }); + } + }); +}());