-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gen) added passport boilerplate question
generates * Passport configuration and a User model * API routes for account creation/sign in * Login and signup views with form validation, including handling server validation errors * Settings view for changing your password * Angular Auth service for creating accounts/logining closes #25, #36
- Loading branch information
Showing
52 changed files
with
1,369 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller 'NavbarCtrl', ['$scope', '$location', ($scope, $location) -> | ||
$scope.menu = [ | ||
title: 'Home' | ||
link: '/' | ||
, | ||
title: 'About' | ||
link: '#' | ||
, | ||
title: 'Contact' | ||
link: '#' | ||
] | ||
$scope.isActive = (route) -> | ||
route is $location.path() | ||
] | ||
.controller 'NavbarCtrl', ['$scope', '$location', ($scope, $location) -> | ||
$scope.menu = [ | ||
title: 'Home' | ||
link: '/' | ||
, | ||
title: 'About' | ||
link: '#' | ||
, | ||
title: 'Contact' | ||
link: '#' | ||
<% if(mongo && mongoPassportUser) { %>, | ||
title: 'Sign Up' | ||
link: '#/signup' | ||
, | ||
title: 'Login' | ||
link: '#/login' | ||
}<% } %> | ||
] | ||
$scope.isActive = (route) -> | ||
route is $location.path() | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>', [<%= angularModules %>])<% if (ngRoute) { %> | ||
.config ($routeProvider, $locationProvider) -> | ||
.config ($routeProvider, $locationProvider<% if (mongoPassportUser) { %>, $httpProvider<% } %>) -> | ||
$routeProvider | ||
.when '/', | ||
templateUrl: 'partials/main' | ||
controller: 'MainCtrl' | ||
<% if(mongoPassportUser) {%> | ||
.when '/login', | ||
templateUrl: 'partials/login' | ||
controller: 'LoginCtrl' | ||
.when '/signup', | ||
templateUrl: 'partials/signup' | ||
controller: 'SignupCtrl' | ||
.when '/settings', | ||
templateUrl: 'partials/settings' | ||
controller: 'SettingsCtrl' | ||
authenticate: true<% } %> | ||
.otherwise | ||
redirectTo: '/' | ||
$locationProvider.html5Mode(true)<% } %> | ||
|
||
$locationProvider.html5Mode true<% if (mongoPassportUser) { %> | ||
|
||
$httpProvider.interceptors.push ['$q', '$location', ($q, $location) -> | ||
responseError: (response) -> | ||
if response.status is 401 or response.status is 403 | ||
$location.path '/login' | ||
$q.reject response | ||
else | ||
$q.reject response | ||
] | ||
.run ($rootScope, $location, Auth) -> | ||
|
||
# Redirect to login if route requires auth and you're not logged in | ||
$rootScope.$on '$routeChangeStart', (event, next) -> | ||
$location.path '/login' if next.authenticate and not Auth.isLoggedIn()<% } %><% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller 'LoginCtrl', ($scope, Auth, $location) -> | ||
$scope.user = {} | ||
$scope.errors = {} | ||
|
||
$scope.login = (form) -> | ||
$scope.submitted = true | ||
|
||
if form.$valid | ||
Auth.login( | ||
email: $scope.user.email | ||
password: $scope.user.password | ||
) | ||
.then -> | ||
# Logged in, redirect to home | ||
$location.path '/' | ||
.catch (err) -> | ||
err = err.data; | ||
$scope.errors.other = err.message; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller 'NavbarCtrl', ($scope, $location<% if (mongoPassportUser) { %>, Auth<% } %>) -> | ||
$scope.menu = [ | ||
title: 'Home' | ||
link: '/' | ||
<% if(mongoPassportUser) { %>, | ||
title: 'Settings' | ||
link: '/settings' | ||
<% } %>] | ||
<% if(mongoPassportUser) { %> | ||
$scope.logout = -> | ||
Auth.logout().then -> | ||
$location.path "/login" | ||
<% } %> | ||
$scope.isActive = (route) -> | ||
route is $location.path() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller 'SettingsCtrl', ($scope, User, Auth) -> | ||
$scope.errors = {} | ||
|
||
$scope.changePassword = (form) -> | ||
$scope.submitted = true | ||
|
||
if form.$valid | ||
Auth.changePassword($scope.user.oldPassword, $scope.user.newPassword) | ||
.then(-> | ||
$scope.message = 'Password successfully changed.' | ||
).catch( -> | ||
form.password.$setValidity 'mongoose', false | ||
$scope.errors.other = 'Incorrect password' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
angular.module('<%= scriptAppName %>') | ||
.controller 'SignupCtrl', ($scope, Auth, $location) -> | ||
$scope.user = {} | ||
$scope.errors = {} | ||
|
||
$scope.register = (form) -> | ||
$scope.submitted = true | ||
|
||
if form.$valid | ||
Auth.createUser( | ||
name: $scope.user.name | ||
email: $scope.user.email | ||
password: $scope.user.password | ||
).then( -> | ||
# Account created, redirect to home | ||
$location.path '/' | ||
).catch( (err) -> | ||
err = err.data | ||
$scope.errors = {} | ||
|
||
# Update validity of form fields that match the mongoose errors | ||
angular.forEach err.errors, (error, field) -> | ||
form[field].$setValidity 'mongoose', false | ||
$scope.errors[field] = error.type | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
### | ||
Removes server error when user updates input | ||
### | ||
angular.module('<%= scriptAppName %>') | ||
.directive 'mongooseError', -> | ||
restrict: 'A' | ||
require: 'ngModel' | ||
link: (scope, element, attrs, ngModel) -> | ||
element.on 'keydown', -> | ||
ngModel.$setValidity 'mongoose', true | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.