forked from codeforgeek/angular-post-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
47 lines (45 loc) · 1.65 KB
/
home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
app.controller('sign_up', function ($scope, $http) {
$scope.check_credentials = function () {
/*
* Validate the Email and Password using Regular Expression.
* Once Validated call the PHP file using HTTP Post Method.
*/
/*
* Validate Email and Password.
* Email shound not be blank, should contain @ and . and not more than 30 characters.
* Password Cannot be blank, not be more than 12 characters, should not contain 1=1.
* Set the Messages to Blank each time the function is called.
*/
$scope.message = "";
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var error = 0;
if ($scope.email == "" || $scope.email == null) {
error = 1;
}
if (!emailReg.test($scope.email)) {
error = 2;
}
/*---- Email is validated ------ */
if ($scope.password == "" || $scope.password == null) {
error = 3;
}
if (error == 0) {
var request = $http({
method: "post",
url: window.location.host + "/login.php",
data: {
email: $scope.email,
pass: $scope.password
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
/* Check whether the HTTP Request is Successfull or not. */
request.success(function (data) {
$scope.message = "From PHP file : "+data;
});
}
else {
$scope.message = "You have Filled Wrong Details! Error: " + error;
}
}
});