Skip to content

Commit ea0a9d6

Browse files
committed
Added new module authentication, sign in template, sign in controller with base logic to apply user login. Also added translate file to handle all locale files with a properly behavior like other frameworks. New user model, locales (spanish and english files), less, sass files and other stuff were created to show an example and naming conventions correctly.
1 parent 866ec4d commit ea0a9d6

File tree

18 files changed

+185
-15
lines changed

18 files changed

+185
-15
lines changed

app/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
'use strict';
44

55
//Main module named 'app' with its module dependencies
6-
angular.module('app', ['ui.router', 'restmod', 'satellizer']).config(restmodAdapter).config(satellizerAdapter);
6+
angular.module('app', ['ui.router', 'restmod', 'satellizer', 'pascalprecht.translate', 'ngCookies', 'app.authentication']).config(restmodConfig).config(satellizerConfig);
77

88
//Injecting service dependencies
9-
restmodAdapter.$inject = ['restmodProvider'];
10-
satellizerAdapter.$inject = ['$authProvider'];
9+
restmodConfig.$inject = ['restmodProvider'];
10+
satellizerConfig.$inject = ['$authProvider'];
1111

1212
//Restmod configuration for models representation like ORM
13-
function restmodAdapter (restmodProvider) {
13+
function restmodConfig(restmodProvider) {
1414

1515
restmodProvider.rebase({
1616
$config: {
@@ -28,7 +28,7 @@
2828
}
2929

3030
//Satellizer configuration for user authentication using JWT
31-
function satellizerAdapter ($authProvider) {
31+
function satellizerConfig($authProvider) {
3232

3333
$authProvider.loginUrl = 'http://localhost/api/v1/signin';
3434
$authProvider.signupUrl = 'http://localhost/api/v1/signup';

app/controllers/.gitkeep

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('app.authentication').controller('SigninController', SigninController);
6+
7+
//Injecting Satellizer service to allow login action
8+
SigninController.$inject = ['$auth'];
9+
10+
function SigninController($auth) {
11+
12+
var vm = this;
13+
14+
vm.actions = {
15+
signin: signin
16+
};
17+
18+
function signin(email, password) {
19+
20+
var user = {
21+
email: email,
22+
password: password
23+
};
24+
25+
$auth.login(user).then(function (response) {
26+
//Here all code necessary after successful login
27+
}).catch(function (response) {
28+
//Here all code necessary when error was thrown
29+
});
30+
}
31+
}
32+
33+
})();

app/i18n.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
//Adding translation config
6+
angular.module('app').config(englishTranslations).config(spanishTranslations);
7+
8+
//Injecting locale messages
9+
englishTranslations.$inject = ['$translateProvider', 'EN_MESSAGES', 'EN_ERROR_MESSAGES'];
10+
spanishTranslations.$inject = ['$translateProvider', 'ES_MESSAGES', 'ES_ERROR_MESSAGES'];
11+
12+
function englishTranslations ($translateProvider, EN_MESSAGES, EN_ERROR_MESSAGES) {
13+
14+
//Here put and if you want to set like a namespace to segment all messages
15+
var allMessages = {
16+
message: EN_MESSAGES,
17+
error: EN_ERROR_MESSAGES
18+
};
19+
20+
$translateProvider.translations('en', allMessages);
21+
}
22+
23+
function spanishTranslations($translateProvider, ES_MESSAGES, ES_ERROR_MESSAGES) {
24+
25+
//Here put and if you want to set like a namespace to segment all messages
26+
var allMessages = {
27+
message: ES_MESSAGES,
28+
error: ES_ERROR_MESSAGES
29+
};
30+
31+
$translateProvider.translations('es', allMessages);
32+
$translateProvider.preferredLanguage('es');
33+
$translateProvider.useLocalStorage();
34+
$translateProvider.useSanitizeValueStrategy('escape');
35+
}
36+
37+
})();

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<base href="/">
45
<meta charset="utf-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
67
<title>App</title>

app/locales/en/app.errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('app').constant('EN_ERROR_MESSAGES', {
6+
7+
'Invalid data': 'Invalid data'
8+
});
9+
10+
})();

app/locales/en/app.messages.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('app').constant('EN_MESSAGES', {
6+
7+
'Email': 'Email',
8+
'Password': 'Password',
9+
'Sign in': 'Sign in',
10+
'Back': 'Back'
11+
});
12+
13+
})();

app/locales/es/app.errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('app').constant('ES_ERROR_MESSAGES', {
6+
7+
'Invalid data': 'Datos invalidos'
8+
});
9+
10+
})();

app/locales/es/app.messages.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(function () {
2+
3+
'use strict';
4+
5+
angular.module('app').constant('ES_MESSAGES', {
6+
7+
'Email': 'Correo electrónico',
8+
'Password': 'Contraseña',
9+
'Sign in': 'Iniciar sesión',
10+
'Back': 'Volver'
11+
});
12+
13+
})();

app/models/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)