File tree Expand file tree Collapse file tree 6 files changed +106
-4
lines changed Expand file tree Collapse file tree 6 files changed +106
-4
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,21 @@ Schema = mongoose.Schema;
5
5
// and should be defined before the schema for readability
6
6
7
7
8
+ // Model Schema
9
+ //var ModelSchema = new Schema ({
10
+ // name : {
11
+ // type: String
12
+ // },
13
+ //});
14
+
8
15
// Model Schema
9
16
var ModelSchema = new Schema ( {
10
- name : {
17
+ email : {
11
18
type : String
12
19
} ,
20
+ password : {
21
+ type : String
22
+ }
13
23
} ) ;
14
-
15
- module . exports = mongoose . model ( 'Model' , ModelSchema ) ;
24
+ module . exports = mongoose . model ( 'Model' , ModelSchema ) ;
25
+ // module.exports = mongoose.model('Model', ModelSchema);
Original file line number Diff line number Diff line change @@ -43,4 +43,28 @@ module.exports = function(app) {
43
43
} ) ;
44
44
} ) ;
45
45
} ) ;
46
+ // Example POST route
47
+ app . post ( '/users' , function ( req , res ) {
48
+ Model . create ( {
49
+ email : req . body . email , // Bound using Angular
50
+ password : req . body . password
51
+ } , function ( err , model ) {
52
+ if ( err ) {
53
+ res . send ( err ) ;
54
+ }
55
+
56
+ Model . find ( function ( err , users ) {
57
+ res . send ( users ) ;
58
+ } ) ;
59
+ } ) ;
60
+ } ) ;
61
+ app . get ( '/users' , function ( req , res ) {
62
+
63
+ // Checks the model collection and returns all of them`
64
+ Model . find ( function ( err , users ) {
65
+
66
+ // returns all people in JSON format
67
+ res . send ( users ) ;
68
+ } ) ;
69
+ } ) ;
46
70
}
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ module.exports = function(app) {
15
15
// Must always end the Writeable stream
16
16
res . end ( ) ;
17
17
} ) ;
18
+
19
+ app . get ( '/login' , function ( req , res ) {
20
+ // Displaying an already made view
21
+ res . sendfile ( 'public/views/login.html' ) ;
22
+ } ) ;
18
23
19
24
// Wildcard route serving static html page
20
25
app . get ( '*' , function ( req , res ) {
Original file line number Diff line number Diff line change 1
1
module . exports = {
2
- url : 'mongodb://localhost:27017/test '
2
+ url : 'mongodb://localhost:27017/users '
3
3
}
Original file line number Diff line number Diff line change
1
+ // Export the controller
2
+ var login = angular . module ( 'login' , [ ] ) ;
3
+
4
+ // Defining wrapper Routes for our API
5
+ login . controller ( 'loginCtrl' , function loginCtrl ( $scope , $http ) {
6
+ $scope . formData = { } ;
7
+ $scope . createUser = function ( ) {
8
+ $http . post ( '/users' , $scope . formData )
9
+ . success ( function ( data ) {
10
+ $scope . formData = { } ;
11
+ $scope . users = data ;
12
+ console . log ( data ) ;
13
+ } )
14
+ . error ( function ( data ) {
15
+ console . log ( "Error: " + data ) ;
16
+ } ) ;
17
+ } ;
18
+
19
+ } )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html ng-app ="login ">
3
+ < head >
4
+ < title > Login Page</ title >
5
+
6
+ < link rel ="stylesheet " href ="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css ">
7
+ < link rel ="stylesheet " type ="text/css " href ="../assets/css/styles.css ">
8
+
9
+ <!-- Angular from Google CDN -->
10
+ < script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js "> </ script >
11
+ <!-- Load AppController -->
12
+ < script type ="text/javascript " src ="../controllers/login.js "> </ script >
13
+ </ head >
14
+ < body ng-controller ="loginCtrl ">
15
+ < div class ="container ">
16
+
17
+ <!-- FORM TO CREATE USERS -->
18
+ < div id ="model-form " class ="form-horizontal ">
19
+ < div class ="col-sm-8 col-sm-offset-2 text-center " id ="name-field ">
20
+
21
+ <!-- Only posts to Angular's createModel if form is valid and was submitted -->
22
+ < form name ="modelCreate " ng-submit ="modelCreate.$valid && submitted && createUser() " novalidate >
23
+ < div class ="form-group ">
24
+
25
+ <!-- BIND THIS VALUE TO formData.name -->
26
+ < div class ="col-sm-12 ">
27
+ < input type ="email " name ="email " class ="form-control input-lg text-center " placeholder ="Email " ng-model ="formData.email " required />
28
+
29
+ < input type ="password " name ="password " class ="form-control input-lg text-center " placeholder ="Password " ng-model ="formData.password " required />
30
+
31
+ </ div >
32
+ </ div >
33
+
34
+ <!-- Sets the value submitted to true to help with form validation -->
35
+ < button type ="submit " class ="btn btn-primary btn-lg " ng-click ="submitted=true " ng-disabled ="modelCreate.password.$dirty && modelCreate.password.$invalid ||
36
+ modelCreate.email.$dirty && modelCreate.email.$invalid ">
37
+ Register
38
+ </ button >
39
+ </ form >
40
+ </ div >
41
+ </ div >
42
+ </ div >
43
+ </ body >
44
+ </ html >
You can’t perform that action at this time.
0 commit comments