This repository has been archived by the owner on Sep 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
132 lines (128 loc) · 5.47 KB
/
client.html
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
<style>
.display_none{
display: none;
}
</style>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
$( document ).ready(function() {
// Login button action
$('.btn-login').bind("click", function(){
var username = $('.username input').val();
var password = $('.password input').val();
if (username == '' || password == ''){
alert('Please fill either username or password on the page.');
}
else{
socket.emit('onUserList', username, password);
displayUsersOnline();
}
return false;
});
// Register button action
$('.btn-register').bind("click", function(event){
$('#create_new').removeClass("display_none");
$('#login').addClass("display_none");
event.preventDefault();
});
// Back button action
$('.btn-back').bind("click", function(event){
$('#create_new').addClass("display_none");
$('#login').removeClass("display_none");
event.preventDefault();
});
// Submit button action
$('.btn-submit').bind("click", function(event){
// Check password
var new_username = $('.new_username input').val();
var new_password = $('.new_password input').val();
var re_new_password = $('.re_new_password input').val();
if (new_username == '') {
alert('Make sure you input the username for register.');
}
if (re_new_password == new_password){
if (re_new_password != '' && new_password != '' ){
socket.emit('onStoreNewUser', new_username, new_password);
displayUsersOnline();
}
else{
alert('Make sure you input the valid password for register.');
}
}
else{
alert('Make sure you input the same password for register.');
}
event.preventDefault();
return false;
});
});
function displayUsersOnline(){
$('#auth').addClass('display_none');
event.preventDefault();
console.log(userOnline);
for (let i in userOnline) {
$("#user_list").append('<div class="list" onclick="onChat(this)" id="'+ userOnline[i] +'">'+ userOnline[i] +'</div>');
}
}
function onChat(elt){
$("#chat-wrap").removeClass('display_none');
}
</script>
<section class="login-block">
<div class="container">
<div class="row">
<div class="col-md-4 login-sec">
<h2 class="text-center">Message App</h2>
<div id="auth">
<form id="login">
<div class="form-group username">
<label class="text-uppercase">Username</label>
<input type="text" class="form-control" placeholder="">
</div>
<div class="form-group password">
<label class="text-uppercase">Password</label>
<input type="password" class="form-control" placeholder="">
</div>
<div class="form-check">
<button type="submit" class="btn btn-register float-right">Register</button>
</div>
<div class="form-check">
<button type="submit" class="btn btn-login float-right">Submit</button>
</div>
</form>
<form id="create_new" class="display_none">
<div class="form-group new_username">
<label class="text-uppercase">New Username</label>
<input type="text" class="form-control" placeholder="">
</div>
<div class="form-group new_password">
<label class="text-uppercase">New Password</label>
<input type="password" class="form-control" placeholder="">
</div>
<div class="form-group re_new_password">
<label class="text-uppercase">Retype New Password</label>
<input type="password" class="form-control" placeholder="">
</div>
<div class="form-check">
<button type="submit" class="btn btn-back float-right">Back</button>
</div>
<div class="form-check">
<button type="submit" class="btn btn-submit float-right">Submit</button>
</div>
</form>
</div>
<div id="user_list"></div>
<div id="chat-wrap" class="display_none">
<div id="chat-area"></div>
<form id="send-message-area">
<p>Your message: </p>
<textarea id="sendie" maxlength = '100'></textarea>
<button>Send</button>
</form>
</div>
</div>
</div>
</div>
</section>