This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login-panel.ejs
183 lines (170 loc) · 6.45 KB
/
login-panel.ejs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<div class = "<% if(errors==''){ %>hidden<% } %> col-xs-12 col-sm-12 col-md-6 panel panel-default">
<div class = "collapse <% if(errors != '' ){ %>in<% } %>" id = "id_login_panelbody_loginpanelbody">
<div class = "panel-body">
<div class = "text-center hidden-md hidden-lg">
<a href="#" class="btn btn-block" onclick="$('#id_navbar_login').click();" aria-label="close">×</a>
</div>
<div class = "col-md-6 class_login_div_halflogin">
<ul class = "nav nav-tabs">
<li class = "active"><a data-toggle = "tab" href = "#" id = "id_login_tab_login">login</a></li>
<li><a data-toggle = "tab" href = "#" id = "id_login_tab_register">register</a></li>
</ul>
<form id = "id_login_form_local" class = "form-horizontal" role = "form" action = "/loggingLocal" method = "post">
<div class = "row">
</div>
<% if(errors!=''){ %>
<div class = "alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<%= errors %>
</div>
<% } %>
<div class = "form-group registerToggle hidden">
<label class = "col-md-4 control-label" for = "fullname">Name</label>
<div class = "col-md-8">
<input type ="text" name = "fullname" id = "fullname" class = "form-control">
</div>
</div>
<div class = "form-group">
<label class = "col-md-4 control-label" for = "username">Email</label>
<div class = "col-md-8">
<input type ="username" name = "username" id = "username" class = "form-control">
</div>
</div>
<div class = "form-group">
<label class = "col-md-4 control-label" for = "password">Password</label>
<div class = "col-md-8">
<input type ="password" name = "password" id = "password" class = "form-control">
</div>
</div>
<div class = "form-group registerToggle hidden">
<label class = "col-md-4 control-label" for = "passwordAgain">Retype</label>
<div class = "col-md-8">
<input type ="password" name = "passwordAgain" id = "passwordAgain" class = "form-control">
</div>
</div>
<div class = "col-md-2 col-md-offset-4">
<div class = "btn btn-primary" id = "id_login_btn_login">Login
</div>
<div class = "btn btn-link hidden" id = "id_login_btn_register">Register
</div>
</div>
</form>
</div>
<div class = "col-md-6 class_login_div_halflogin">
<div class = "text-center">
<div class = "imgcontainer" id = "id_login_img_googlesignin">
<img src = "include/signinwithgoogle.png">
</div>
<br>
<div class = "imgcontainer" id = "id_login_img_facebooksignin">
<img src = "include/signinwithfacebook.png">
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$('#id_login_tab_login').off('click').click(function(){
$('#id_login_form_local').animate({opacity:'0.0'},300,function(){
$('id_login_form_local input').parent().parent().removeClass('has-error');
$('#id_login_form_local label').removeClass('required');
$('#id_login_form_local input').val('');
$('#id_login_btn_login').removeClass('hidden');
$('.registerToggle,#id_login_btn_register').addClass('hidden');
$('#id_login_form_local').animate({opacity:'1.0'});
})
})
$('#id_login_tab_register').off('click').click(function(){
$('#id_login_form_local').animate({opacity:'0.0'},300,function(){
$('id_login_form_local input').parent().parent().removeClass('has-error');
$('#id_login_form_local label').addClass('required');
$('#id_login_form_local input').val('');
$('#id_login_btn_login').addClass('hidden');
$('.registerToggle,#id_login_btn_register').removeClass('hidden');
$('#id_login_form_local').animate({opacity:'1.0'});
})
})
$('#id_login_form_local').submit(function(e){
if($('#id_login_tab_register').parent().hasClass('active')){
$('#id_login_btn_register').click();
e.preventDefault();
return;
}
$('id_login_form_local input').parent().parent().removeClass('has-error');
var noErrorFlag = true;
$('#username,#password').each(function(){
if($(this).val()==''){
noErrorFlag = false;
$(this).parent().parent().addClass('has-error');
}else{
$(this).parent().parent().removeClass('has-error');
}
})
if(noErrorFlag){
$('#password').val($.sha256($('#password').val()));
$('#id_login_btn_login')
.html('logging in...')
.addClass('disabled');
}else{
e.preventDefault();
}
});
$('#id_login_btn_login').off('click').click(function(){
if($(this).hasClass('disabled')){
return false;
}
$(this).addClass('disabled');
$('#id_login_form_local').submit();
})
$('#id_login_btn_register').off('click').click(function(){
if($(this).hasClass('disabled')){
return false;
}
var errorMessage = 'Error:';
var emptyStringFlag = true;
var noErrorFlag = true;
$('#id_login_form_local input').each(function(){
if($(this).val()==''){
noErrorFlag = false;
if(emptyStringFlag){
emptyStringFlag = false;
errorMessage += ' All of the fields are required.'
}
$(this).parent().parent().addClass('has-error');
}else{
$(this).parent().parent().removeClass('has-error');
}
})
if($('#password').val()!=''){
if($('#password').val()!=$('#passwordAgain').val()){
noErrorFlag = false;
$('#password,#passwordAgain').parent().parent().addClass('has-error');
errorMessage += ' Password and Retype do not match!'
}else{
$('#password,#passwordAgain').parent().parent().removeClass('has-error');
}
}
if(noErrorFlag){
$(this).addClass('disabled');
var json = {
fullname : $('#fullname').val(),
username : $('#username').val(),
password : $.sha256($('#password').val()),
}
$.ajax({
type : 'POST',
url : '/localRegister',
data : json,
success : function(o){
if(o.success){
info_modal('Please check your inbox for an e-mail of verification.')
}
}
})
}else{
info_modal(errorMessage);
}
})
</script>