aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2020-03-02 03:26:01 +0300
committerRblSb <msrblsb@gmail.com>2020-03-02 03:37:30 +0300
commitfe6875904f0c8f4ed8359efe961570307d9cbae6 (patch)
treec19c6274609c88b519ab5676ace5d7665512e153 /src/client
parent2ade04273717807096a07b6eb132b7677917392d (diff)
addAdmin server command
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Buttons.hx13
-rw-r--r--src/client/Main.hx46
2 files changed, 46 insertions, 13 deletions
diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx
index 51ba75d..e567331 100644
--- a/src/client/Buttons.hx
+++ b/src/client/Buttons.hx
@@ -209,13 +209,12 @@ class Buttons {
static function initChatInput(main:Main):Void {
final guestName:InputElement = cast ge("#guestname");
guestName.onkeydown = e -> {
- if (guestName.value.length == 0) return;
- if (e.keyCode == 13) main.send({
- type: Login,
- login: {
- clientName: guestName.value
- }
- });
+ if (e.keyCode == 13) main.guestLogin(guestName.value);
+ }
+
+ final guestPass:InputElement = cast ge("#guestpass");
+ guestPass.onkeydown = e -> {
+ if (e.keyCode == 13) main.userLogin(guestName.value, guestPass.value);
}
final chatLine:InputElement = cast ge("#chatline");
diff --git a/src/client/Main.hx b/src/client/Main.hx
index c74a600..9d383bc 100644
--- a/src/client/Main.hx
+++ b/src/client/Main.hx
@@ -1,5 +1,6 @@
package client;
+import haxe.crypto.Sha256;
import haxe.Timer;
import js.html.MouseEvent;
import js.html.KeyboardEvent;
@@ -217,10 +218,14 @@ class Main {
case Login:
onLogin(data.login.clients, data.login.clientName);
+ case PasswordRequest:
+ showGuestPasswordPanel();
+
case LoginError:
final text = Lang.get("usernameError")
.replace("$MAX", '${config.maxLoginLength}');
serverMessage(4, text);
+ showGuestLoginPanel();
case Logout:
updateClients(data.logout.clients);
@@ -324,12 +329,12 @@ class Main {
onLogin(connected.clients, connected.clientName);
}
final guestName:InputElement = cast ge("#guestname");
- if (guestName.value.length > 0) send({
- type: Login,
- login: {
- clientName: guestName.value
- }
- });
+ final guestPass:InputElement = cast ge("#guestpass");
+ if (config.salt != null && guestPass.value.length > 0) {
+ userLogin(guestName.value, guestPass.value);
+ } else {
+ guestLogin(guestName.value);
+ }
clearChat();
serverMessage(1);
for (message in connected.history) {
@@ -338,6 +343,27 @@ class Main {
player.setItems(connected.videoList, connected.itemPos);
}
+ public function guestLogin(name:String):Void {
+ if (name.length == 0) return;
+ send({
+ type: Login, login: {
+ clientName: name
+ }
+ });
+ }
+
+ public function userLogin(name:String, password:String):Void {
+ if (config.salt == null) return;
+ if (password.length == 0) return;
+ if (name.length == 0) return;
+ send({
+ type: Login, login: {
+ clientName: name,
+ passHash: Sha256.encode(password + config.salt)
+ }
+ });
+ }
+
function setConfig(config:Config):Void {
this.config = config;
pageTitle = config.channelName;
@@ -386,6 +412,7 @@ class Main {
function showGuestLoginPanel():Void {
ge("#guestlogin").style.display = "block";
+ ge("#guestpassword").style.display = "none";
ge("#chatline").style.display = "none";
ge("#exitBtn").textContent = Lang.get("login");
Browser.window.dispatchEvent(new Event("resize"));
@@ -393,12 +420,19 @@ class Main {
function hideGuestLoginPanel():Void {
ge("#guestlogin").style.display = "none";
+ ge("#guestpassword").style.display = "none";
ge("#chatline").style.display = "block";
ge("#exitBtn").textContent = Lang.get("exit");
if (isAdmin()) ge("#clearchatbtn").style.display = "inline-block";
Browser.window.dispatchEvent(new Event("resize"));
}
+ function showGuestPasswordPanel():Void {
+ ge("#guestlogin").style.display = "none";
+ ge("#chatline").style.display = "none";
+ ge("#guestpassword").style.display = "block";
+ }
+
function updateClients(newClients:Array<ClientData>):Void {
clients.resize(0);
for (client in newClients) {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage