-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
848 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= appname %>') | ||
.service('Auth', function ($rootScope, $cookieStore, $q, $http) { | ||
|
||
var _user = {}; | ||
|
||
if($cookieStore.get('token')) { | ||
$http.get('/api/users/me') | ||
.then(function (res) { | ||
_user = res.data; | ||
}) | ||
.catch(function (err) { | ||
console.log(err); | ||
}); | ||
} | ||
|
||
/** | ||
* Signup | ||
* | ||
* @param user | ||
* @returns {promise} | ||
*/ | ||
this.signup = function (user) { | ||
var deferred = $q.defer(); | ||
$http.post('/api/users', user) | ||
.then(function (res) { | ||
_user = res.data.user; | ||
$cookieStore.put('token', res.data.token); | ||
deferred.resolve(); | ||
}) | ||
.catch(function (err) { | ||
deferred.reject(err.data); | ||
}); | ||
return deferred.promise; | ||
}; | ||
|
||
/** | ||
* Login | ||
* | ||
* @param user | ||
* @returns {promise} | ||
*/ | ||
this.login = function (user) { | ||
var deferred = $q.defer(); | ||
$http.post('/auth/local', user) | ||
.then(function (res) { | ||
_user = res.data.user; | ||
$cookieStore.put('token', res.data.token); | ||
deferred.resolve(); | ||
}) | ||
.catch(function (err) { | ||
deferred.reject(err.data); | ||
}); | ||
return deferred.promise; | ||
}; | ||
|
||
/** | ||
* Logout | ||
*/ | ||
this.logout = function () { | ||
$cookieStore.remove('token'); | ||
_user = {}; | ||
}; | ||
|
||
/** | ||
* Check if user is logged | ||
* | ||
* @returns {boolean} | ||
*/ | ||
this.isLogged = function () { | ||
return _user.hasOwnProperty('email'); | ||
}; | ||
|
||
/** | ||
* Returns the user | ||
* | ||
* @returns {object} | ||
*/ | ||
this.getUser = function () { | ||
return _user; | ||
}; | ||
|
||
}); |
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,34 @@ | ||
'use strict'; | ||
|
||
describe('Service: Auth', function () { | ||
|
||
beforeEach(module('<%= appname %>')); | ||
|
||
var Auth, | ||
$httpBackend, | ||
$cookieStore; | ||
|
||
beforeEach(inject(function (_Auth_, _$httpBackend_, _$cookieStore_) { | ||
Auth = _Auth_; | ||
$httpBackend = _$httpBackend_; | ||
$cookieStore = _$cookieStore_; | ||
$cookieStore.remove('token'); | ||
})); | ||
|
||
afterEach(function() { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
it('should log user', function () { | ||
expect(Auth.isLogged()).toBe(false); | ||
Auth.login({ email: 'test@test.com', password: 'test' }); | ||
$httpBackend.expectPOST('/auth/local') | ||
.respond({ token: 'abcde', user: { email: 'test@test.com' } }); | ||
$httpBackend.flush(); | ||
expect($cookieStore.get('token')).toBe('abcde'); | ||
expect(Auth.getUser().email).toBe('test@test.com'); | ||
expect(Auth.isLogged()).toBe(true); | ||
}); | ||
|
||
}); |
17 changes: 17 additions & 0 deletions
17
app/templates/client/services/socket(sockets)/socket.mock.js
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('<%= appname %>') | ||
.factory('Socket', function (socketFactory) { | ||
|
||
return { | ||
socket: { | ||
connect: angular.noop, | ||
on: angular.noop, | ||
emit: angular.noop, | ||
receive: angular.noop | ||
}, | ||
syncModel: angular.noop, | ||
unsyncModel: angular.noop | ||
}; | ||
|
||
}); |
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
32 changes: 32 additions & 0 deletions
32
app/templates/client/views/login(auth)/login.controller.js
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,32 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= appname %>') | ||
.controller('LoginCtrl', function (Auth, $location) { | ||
|
||
var vm = this; | ||
|
||
angular.extend(vm, { | ||
|
||
name: 'LoginCtrl', | ||
|
||
/** | ||
* User credentials | ||
*/ | ||
user: { email: 'test@test.com', password: 'test' }, | ||
|
||
/** | ||
* Login method | ||
*/ | ||
login: function () { | ||
Auth.login(vm.user) | ||
.then(function () { | ||
$location.path('/'); | ||
}) | ||
.catch(function (err) { | ||
vm.error = err; | ||
}); | ||
} | ||
|
||
}); | ||
|
||
}); |
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 @@ | ||
<div> | ||
{{ vm.name }} | ||
</div> | ||
|
||
<form ng-submit="vm.login()"> | ||
<input type="email" | ||
ng-model="vm.user.email" | ||
placeholder="email"> | ||
<input type="password" | ||
ng-model="vm.user.password" | ||
placeholder="password"> | ||
<button type="submit"> | ||
login | ||
</button> | ||
</form> | ||
|
||
<pre ng-if="vm.error">{{ vm.error | json }}</pre> |
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,11 @@ | ||
'use strict'; | ||
|
||
angular.module('<%= appname %>') | ||
.config(function ($routeProvider) { | ||
$routeProvider | ||
.when('/login', { | ||
templateUrl: 'views/login/login.html', | ||
controller: 'LoginCtrl', | ||
controllerAs: 'vm' | ||
}); | ||
}); |
Oops, something went wrong.