-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustom.js
More file actions
131 lines (111 loc) · 3.08 KB
/
custom.js
File metadata and controls
131 lines (111 loc) · 3.08 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function getXMLHttp(){
var xmlHttp
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
function getAjaxHttp(e, p){
$.ajax({
type: "POST",
url: "/member/index.html",
data: { 'email': e, 'pwd' : p },
statusCode: {
200: function(jqXHR) {
alert( "Fail" );
jqXHR.prop = "Auth Fail";
},
302: function() {
alert( "Success" );
},
},
})
.done(function( msg, stat, jqXHR ) {
console.log(jqXHR.prop);
getValue = $("#authenticationFailed").html();
alert(getValue);
//alert( "Submitted!" );
//alert(Context.Response.StatusCode);
/*if (Context.Response.StatusCode == 302){
alert('302 Failed');
} else if(Context.Response.StatusCode == 200) {
alert('200 Passed!');
} else {
}*/
});
}
function validateEmail(email) {
if(email == ''){
return false;
}
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function logUser(email, password){
if (validateEmail(email)) {
if(password.length < 5 || password.length > 16){
alert('Passwords must be 5 to 16 characters long and may contain only alphabets (a-z) and numbers (0-9).');
return false;
}
}
getAjaxHttp(email, password);
/*var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4){
handleLogUser(xmlHttp.responseText, email);
}
}
xmlHttp.open("GET", "http://www.yourwebsite.com/log_user.php?e="+email+"&p="+password, true);
xmlHttp.send(null);
} else {
alert('Your email is not valid.');
}*/
}
function handleLogUser(response, email, password){
if(response == 'true'){
console.log('User has successfully login.');
}else{
console.log('Your credentials are incorrect.');
}
}
function LoginBox(){
$('.body').prepend('<div class="login" ><div class="title">User Login</div><input value="" class="username" autocapitalize="off" type="text" placeholder="username"/><input value="" class="password" autocapitalize="off" type="password" placeholder="password"/><button class="go">Login to your account</button></div>');
}
function adjust(){
var marginTop = (($('body').height() - $('.login').height())-100)/2;
var marginLeft = (($('body').width() - $('.login').width())-100)/2;
$('.login').css({'left': marginLeft, 'top': marginTop });
}
$(window).load(function() {
var loginbox1 = new LoginBox;
adjust();
$('button').click(function(){
logUser( $(this).closest('.login').children('.username').val(), $(this).closest('.login').children('.password').val() );
})
});
$( window ).resize(function() {
adjust();
});
function login(){
logUser($('.username').value, $('.password').value);
}