Skip to content

Commit

Permalink
closes #1 - implemented signout post form, closes #2 - form errors no…
Browse files Browse the repository at this point in the history
…w display above submit button, closes #3 - csrf token is now handled on init and after login
  • Loading branch information
Dominic Walker authored and Dominic Walker committed Jan 31, 2017
1 parent 3d65522 commit ec47b50
Show file tree
Hide file tree
Showing 9 changed files with 1,422 additions and 24 deletions.
1,362 changes: 1,361 additions & 1 deletion src/Cofoundry.Samples.SPASite/Content/css/screen.css

Large diffs are not rendered by default.

37 changes: 27 additions & 10 deletions src/Cofoundry.Samples.SPASite/Content/js/compiled/CofoundrySPA.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/Cofoundry.Samples.SPASite/Content/js/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
app.siteView = new app.SiteView();

// Checks if user is logged in and if true sets the user data
helper.prefilter(SPACatsState.csrfToken);

if (SPACatsState.isLoggedIn === true) {
helper.prefilter(SPACatsState.csrfToken);
app.User.set({authenticated: true, token: SPACatsState.csrfToken});
app.User.getFavourites();
}

console.log(app.User.get('token'));

$(window).load(function (e) {
app.Events.trigger('app loaded', e);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
el : '.navbar',
events : {
'click .logo': 'goHome',
'click .navbar__link': 'linkNavigate',
'click .logout': 'handleLogout'
'click .navbar__link': 'linkNavigate'
},
initialize: function() {
this.$unAuthLinks = this.$el.find('.unauth');
Expand All @@ -15,7 +14,7 @@
app.router.navigate('', {trigger: true});
},
linkNavigate: function(e) {
if (e.target.pathname === '/signout') return;
if (e.target.tagName === 'BUTTON') return;

e.preventDefault();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function (pages, itemViews, models, app, $, _, Backbone) {
(function (pages, itemViews, models, app, $, _, Backbone, helper) {
pages.Login = Backbone.View.extend({
el : 'main',
template: _.template($('#login').html()),
Expand Down Expand Up @@ -42,11 +42,18 @@
console.log(errors);

_.each(errors, function(error) {
var name = error.properties[0].toLowerCase(),
if (error.properties.length > 0) {
var name = error.properties[0].toLowerCase(),
message = error.message,
$input = this.$el.find('input[name="' + name + '"] + .error');

$input.text(message).removeClass('hidden');
$input.text(message).removeClass('hidden');
} else {
var message = error.message,
$formError = this.$el.find('.form-error');

$formError.text(message).removeClass('hidden');
}
}, this);
},
clearErrors: function() {
Expand All @@ -60,7 +67,10 @@
handleLogin: function(token) {
this.showLoginMessage();

helper.prefilter(token);
app.User.set({authenticated: true, token: token});

console.log(app.User.get('token'));
},
showLoginMessage: function() {
this.$el.find('.login-form').addClass('hidden');
Expand All @@ -74,5 +84,6 @@
CofoundrySPA.App,
jQuery,
_,
Backbone
Backbone,
Helper
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function (pages, itemViews, models, app, $, _, Backbone) {
(function (pages, itemViews, models, app, $, _, Backbone, helper) {
pages.Register = Backbone.View.extend({
el : 'main',
template: _.template($('#register').html()),
Expand Down Expand Up @@ -60,7 +60,10 @@
handleRegister: function(token) {
this.showRegisteredMessage();

helper.prefilter(token);
app.User.set({authenticated: true, token: token});

console.log(app.User.get('token'));
},
showRegisteredMessage: function() {
this.$el.find('.register-form').addClass('hidden');
Expand All @@ -74,5 +77,6 @@
CofoundrySPA.App,
jQuery,
_,
Backbone
Backbone,
Helper
);
4 changes: 3 additions & 1 deletion src/Cofoundry.Samples.SPASite/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<li><a href="/" class="navbar__link">Cats</a></li>
<li><a href="/login" class="navbar__link unauth">Login</a></li>
<li><a href="/register" class="navbar__link unauth">Register</a></li>
<li><a href="/signout" class="navbar__link logout auth hidden">Logout</a></li>
<li><form action="/sign-out" method="POST"><button class="navbar__link logout auth hidden" type="submit">Logout</button></form></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -111,6 +111,7 @@
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
<span class="error hidden"></span>
</div>
<span class="error form-error hidden"></span>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<div class="message hidden">
Expand Down Expand Up @@ -147,6 +148,7 @@
<input type="password" name="password" class="form-control" id="inputPassword" placeholder="Password">
<span class="error hidden"></span>
</div>
<span class="error form-error hidden"></span>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<div class="message hidden">
Expand Down
Binary file not shown.
6 changes: 4 additions & 2 deletions src/Cofoundry.Samples.SPASite/sass/core/blocks/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
padding: 10px 0;
}

a {
.navbar__link {
background-color: transparent;
border: 0;
color: white;
display: block;
}
Expand All @@ -47,7 +49,7 @@
}
}

a {
.navbar__link {
padding: 0 15px;
}
}
Expand Down

0 comments on commit ec47b50

Please sign in to comment.