mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
Merge pull request #323 from javorszky/iss278
Login / Signup forms now use Backbone
This commit is contained in:
commit
5c0367c0d7
@ -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 () {
|
||||
|
12
ghost/admin/tpl/login.hbs
Normal file
12
ghost/admin/tpl/login.hbs
Normal file
@ -0,0 +1,12 @@
|
||||
<form id="login" method="post">
|
||||
<div class="email-wrap">
|
||||
<input class="email" type="text" placeholder="Email Address" name="email">
|
||||
</div>
|
||||
<div class="password-wrap">
|
||||
<input class="password" type="password" placeholder="Password" name="password">
|
||||
</div>
|
||||
<button class="button-save" type="submit">Log in</button>
|
||||
<section class="meta">
|
||||
<a class="forgotten-password" href="#">Forgotten password?</a> • <a href="/ghost/signup/">Register new user</a>
|
||||
</section>
|
||||
</form>
|
12
ghost/admin/tpl/signup.hbs
Normal file
12
ghost/admin/tpl/signup.hbs
Normal file
@ -0,0 +1,12 @@
|
||||
<form id="register" method="post">
|
||||
<div class="email-wrap">
|
||||
<input class="email" type="text" placeholder="Email Address" name="email">
|
||||
</div>
|
||||
<div class="password-wrap">
|
||||
<input class="password" type="password" placeholder="Password" name="password">
|
||||
</div>
|
||||
<button class="button-save" type="submit">Register</button>
|
||||
<section class="meta">
|
||||
<a href="/ghost/login/">Log in</a>
|
||||
</section>
|
||||
</form>
|
105
ghost/admin/views/login.js
Normal file
105
ghost/admin/views/login.js
Normal file
@ -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'
|
||||
}]
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}());
|
Loading…
Reference in New Issue
Block a user