Skip to content

Commit 006aedf

Browse files
committed
Implement signup in Ember
Closes #2410 - Add signup action that posts to signup endpoint - Fix nav bar showing on signup page - Fix image link when a user hasn't set their image yet - Redirect to the ember/signin page if requesting an ember page
1 parent 11cf0ae commit 006aedf

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

core/client/controllers/application.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var ApplicationController = Ember.Controller.extend({
22
isSignedIn: Ember.computed.bool('user.isSignedIn'),
3+
hideNav: Ember.computed.match('currentPath', /(signin|signup|forgotten|reset)/),
34

45
actions: {
56
toggleMenu: function () {

core/client/routes/signup.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
1+
import ajax from 'ghost/utils/ajax';
12
import styleBody from 'ghost/mixins/style-body';
23

34
var SignupRoute = Ember.Route.extend(styleBody, {
4-
classNames: ['ghost-signup']
5+
classNames: ['ghost-signup'],
6+
7+
name: null,
8+
email: null,
9+
password: null,
10+
11+
actions: {
12+
signup: function () {
13+
var self = this,
14+
controller = this.get('controller'),
15+
data = controller.getProperties('name', 'email', 'password');
16+
17+
// TODO: Validate data
18+
19+
if (data.name && data.email && data.password) {
20+
ajax({
21+
url: '/ghost/signup/',
22+
type: 'POST',
23+
headers: {
24+
'X-CSRF-Token': this.get('csrf')
25+
},
26+
data: data
27+
}).then(function (resp) {
28+
if (resp && resp.userData) {
29+
self.send('signedIn', resp.userData);
30+
31+
self.notifications.clear();
32+
33+
self.transitionTo('posts');
34+
} else {
35+
self.transitionTo('signin');
36+
}
37+
}, function (resp) {
38+
self.notifications.showAPIError(resp);
39+
});
40+
} else {
41+
this.notifications.showError('Must provide name, email and password');
42+
}
43+
}
44+
}
545
});
646

747
export default SignupRoute;

core/client/templates/-navbar.hbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
<li id="usermenu" class="usermenu subnav">
1212
<a href="javascript:void(0);" {{action 'toggleMenu'}} class="dropdown">
13+
{{#if user.image}}
1314
<img class="avatar" {{bind-attr src="user.image"}} alt="Avatar" />
15+
{{else}}
16+
<img class="avatar" src="/shared/img/user-image.png" alt="Avatar" />
17+
{{/if}}
1418
<span class="name">{{user.name}}</span>
1519
</a>
1620
{{!-- @TODO: add functionality to allow for dropdown to work --}}

core/client/templates/application.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{{#if isSignedIn}}
1+
{{#unless hideNav}}
22
{{partial "navbar"}}
3-
{{/if}}
3+
{{/unless}}
44

55
<main role="main" id="main">
66
{{ghost-notifications}}

core/client/templates/signup.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<section class="signup-box js-signup-box fade-in">
22
<form id="signup" class="signup-form" method="post" novalidate="novalidate">
33
<div class="name-wrap">
4-
<input class="name" type="text" placeholder="Full Name" name="name" autofocus autocorrect="off" />
4+
{{input class="name" type="text" placeholder="Full Name" name="name" autofocus="autofocus" autocorrect="off" value=name }}
55
</div>
66
<div class="email-wrap">
7-
<input class="email" type="email" placeholder="Email Address" name="email" autocapitalize="off" autocorrect="off" />
7+
{{input class="email" type="email" placeholder="Email Address" name="email" autocapitalize="off" autocorrect="off" value=email }}
88
</div>
99
<div class="password-wrap">
10-
<input class="password" type="password" placeholder="Password" name="password" />
10+
{{input class="password" type="password" placeholder="Password" name="password" value=password }}
1111
</div>
12-
<button class="button-save" type="submit">Sign Up</button>
12+
<button class="button-save" type="submit" {{action "signup"}}>Sign Up</button>
1313
</form>
1414
</section>

core/server/middleware/middleware.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ var middleware = {
7979
}
8080
redirect = '?r=' + encodeURIComponent(reqPath);
8181
}
82+
83+
if (subPath.indexOf('/ember') > -1) {
84+
return res.redirect(config().paths.subdir + '/ghost/ember/signin');
85+
}
86+
8287
return res.redirect(config().paths.subdir + '/ghost/signin/' + redirect);
8388
});
8489
}

0 commit comments

Comments
 (0)