Skip to content

Commit 326c9dd

Browse files
committed
adding new doubted files
1 parent 57c4269 commit 326c9dd

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

app/models/model.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ Schema = mongoose.Schema;
1010
// name : {
1111
// type: String
1212
// },
13-
//});
13+
//});+
1414

1515
// Model Schema
1616
var ModelSchema = new Schema ({
17+
firstname : {
18+
type: String
19+
},
20+
lastname : {
21+
type: String
22+
},
1723
email : {
1824
type: String
1925
},

app/routes/api.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,52 @@ module.exports = function(app) {
4444
});
4545
});
4646
// Example POST route
47+
app.get('/login', function (req, res) {
48+
var isExists = con.find({
49+
email : req.body.email // Bound using Angular
50+
});
51+
console.log(isExists);
52+
53+
if (isExists) {
54+
res.send("logged in!");
55+
} else {
56+
res.send("Please register");
57+
}
58+
});
59+
// Example POST route
60+
app.post('/signup', function (req, res) {
61+
Model.create({
62+
firstname: req.body.firstname,
63+
lastname: req.body.lastname,
64+
email : req.body.email, // Bound using Angular
65+
password : req.body.password,
66+
67+
}, function(err, model) {
68+
if(err) {
69+
res.send("Please try again!");
70+
}
71+
72+
Model.find(function(err, users) {
73+
res.send("You are Registered!");
74+
});
75+
});
76+
});
77+
// Example POST route
4778
app.post('/users', function (req, res) {
4879
Model.create({
4980
email : req.body.email, // Bound using Angular
5081
password : req.body.password
5182
}, function(err, model) {
5283
if(err) {
53-
res.send(err);
84+
res.send("Please try again!");
5485
}
5586

5687
Model.find(function(err, users) {
57-
res.send(users);
88+
res.send("You are Registered!");
5889
});
5990
});
6091
});
61-
app.get('/users', function(req, res) {
92+
app.get('/users', function(req, res) {
6293

6394
// Checks the model collection and returns all of them`
6495
Model.find(function(err, users) {

app/routes/routes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ module.exports = function(app) {
2121
res.sendfile('public/views/login.html');
2222
});
2323

24+
app.get('/signup', function(req, res) {
25+
// Displaying an already made view
26+
res.sendfile('public/views/signup.html');
27+
});
28+
2429
// Wildcard route serving static html page
2530
app.get('*', function(req, res) {
2631
// Displaying an already made view

public/controllers/login.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@
22
var login = angular.module('login', []);
33

44
// Defining wrapper Routes for our API
5-
login.controller('loginCtrl', function loginCtrl($scope, $http) {
5+
login.controller('loginCtrl', function loginCtrl($scope, $http, $timeout) {
66
$scope.formData = {};
77
$scope.createUser = function() {
8+
$scope.isCheck = false;
89
$http.post('/users', $scope.formData)
910
.success(function(data) {
1011
$scope.formData = {};
11-
$scope.users = data;
12-
console.log(data);
12+
$scope.message = data;
1313
})
1414
.error(function(data) {
15-
console.log("Error: " + data);
15+
$scope.message = data;
1616
});
17+
$timeout(function() { $scope.isCheck = true; }, 10);
1718
};
19+
})
1820

19-
})
21+
// Defining wrapper Routes for our API
22+
login.controller('signupCtrl', function signupCtrl($scope, $http, $timeout) {
23+
$scope.formData = {};
24+
$scope.signUp = function() {
25+
$scope.isCheck = false;
26+
$http.post('/signup', $scope.formData)
27+
.success(function(data) {
28+
$scope.formData = {};
29+
$scope.message = data;
30+
})
31+
.error(function(data) {
32+
$scope.message = data;
33+
});
34+
$timeout(function() { $scope.isCheck = true; }, 10);
35+
};
36+
})

public/views/login.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,20 @@
1717
<!-- FORM TO CREATE USERS -->
1818
<div id="model-form" class="form-horizontal">
1919
<div class="col-sm-8 col-sm-offset-2 text-center" id="name-field">
20-
20+
<p ng-show="isCheck" style="background:red;padding:5px;">{{ message }}</p>
2121
<!-- Only posts to Angular's createModel if form is valid and was submitted -->
2222
<form name="modelCreate" ng-submit="modelCreate.$valid && submitted && createUser()" novalidate>
2323
<div class="form-group">
24-
2524
<!-- BIND THIS VALUE TO formData.name -->
2625
<div class="col-sm-12">
2726
<input type="email" name="email" class="form-control input-lg text-center" placeholder="Email" ng-model="formData.email" required />
28-
2927
<input type="password" name="password" class="form-control input-lg text-center" placeholder="Password" ng-model="formData.password" required />
30-
3128
</div>
3229
</div>
33-
30+
3431
<!-- 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">
32+
<button type="submit" class="btn btn-primary btn-lg" ng-click="submitted=true" ng-disabled="modelCreate.password && modelCreate.password.$dirty && modelCreate.password.$invalid ||
33+
modelCreate.email.$dirty && modelCreate.email.$invalid && modelCreate.email">
3734
Register
3835
</button>
3936
</form>

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var morgan = require('morgan');
88
var db = require('./config/db');
99

1010
// Connect to the DB
11-
mongoose.connect(db.url);
11+
var con = mongoose.connect(db.url);
1212

1313
// Initialize the Express App
1414
var app = express();

0 commit comments

Comments
 (0)