Skip to content

Commit 753b595

Browse files
committed
chapter one complete
1 parent 3ba6220 commit 753b595

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

src/js/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import './home';
1414
import './profile';
1515
import './article';
1616
import './services';
17+
import './auth';
1718

1819

1920
// Create and bootstrap application
@@ -25,7 +26,8 @@ const requires = [
2526
'app.home',
2627
'app.profile',
2728
'app.article',
28-
'app.services'
29+
'app.services',
30+
'app.auth'
2931
];
3032

3133
// Mount on window for testing

src/js/auth/auth.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function AuthConfig($stateProvider, $httpProvider) {
2+
'ngInject';
3+
4+
$stateProvider
5+
6+
.state('app.login', {
7+
url: '/login',
8+
controller: 'AuthCtrl as $ctrl',
9+
templateUrl: 'auth/auth.html',
10+
title: 'Sign in'
11+
})
12+
13+
.state('app.register', {
14+
url: '/register',
15+
controller: 'AuthCtrl as $ctrl',
16+
templateUrl: 'auth/auth.html',
17+
title: 'Sign up'
18+
});
19+
20+
};
21+
22+
export default AuthConfig;

src/js/auth/auth.controller.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class AuthCtrl {
2+
constructor($state) {
3+
'ngInject';
4+
5+
this.title = $state.current.title;
6+
this.authType = $state.current.name.replace('app.', '');
7+
8+
}
9+
10+
submitForm() {
11+
this.isSubmitting = true;
12+
13+
console.log(this.formData);
14+
}
15+
}
16+
17+
export default AuthCtrl;

src/js/auth/auth.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<div class="auth-page">
2+
<div class="container page">
3+
<div class="row">
4+
5+
<div class="col-md-6 offset-md-3 col-xs-12">
6+
<h1 class="text-xs-center" ng-bind="::$ctrl.title"></h1>
7+
<p class="text-xs-center">
8+
<a ui-sref="app.login"
9+
ng-show="$ctrl.authType === 'register'">
10+
Have an account?
11+
</a>
12+
<a ui-sref="app.register"
13+
ng-show="$ctrl.authType === 'login'">
14+
Need an account?
15+
</a>
16+
</p>
17+
18+
<form ng-submit="$ctrl.submitForm()">
19+
<fieldset ng-disabled="$ctrl.isSubmitting">
20+
21+
<fieldset class="form-group" ng-show="$ctrl.authType === 'register'">
22+
<input class="form-control form-control-lg"
23+
type="text"
24+
placeholder="Username"
25+
ng-model="$ctrl.formData.username" />
26+
</fieldset>
27+
28+
<fieldset class="form-group">
29+
<input class="form-control form-control-lg"
30+
type="email"
31+
placeholder="Email"
32+
ng-model="$ctrl.formData.email" />
33+
</fieldset>
34+
35+
<fieldset class="form-group">
36+
<input class="form-control form-control-lg"
37+
type="password"
38+
placeholder="Password"
39+
ng-model="$ctrl.formData.password" />
40+
</fieldset>
41+
42+
<button class="btn btn-lg btn-primary pull-xs-right"
43+
type="submit"
44+
ng-bind="::$ctrl.title">
45+
</button>
46+
47+
</fieldset>
48+
</form>
49+
</div>
50+
51+
</div>
52+
</div>
53+
</div>

src/js/auth/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import angular from 'angular';
2+
3+
// Create the module where our functionality can attach to
4+
let authModule = angular.module('app.auth', []);
5+
6+
// Include our UI-Router config settings
7+
import AuthConfig from './auth.config';
8+
authModule.config(AuthConfig);
9+
10+
11+
// Include controllers
12+
import AuthCtrl from './auth.controller';
13+
authModule.controller('AuthCtrl', AuthCtrl);
14+
15+
16+
export default authModule;

src/js/home/home.controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class HomeCtrl {
44

55
this.appName = AppConstants.appName;
66

7+
78
}
89

910

0 commit comments

Comments
 (0)