register.js (1243B)
1 2 window.FakeTerminal.command.register = function (instance) { 3 // Extending the base command 4 window.FakeTerminal.command.apply(this, arguments); 5 6 const base = this; 7 8 base.info = () => { 9 return { 10 description: "Register an account" 11 }; 12 }; 13 14 base.execute = () => { 15 let username; 16 let password; 17 18 instance.output.write("Username: ") 19 instance.input.request("text").done((value) => { 20 username = value; 21 22 instance.input.request("password").done( async (value) => { 23 password = value; 24 25 // TODO: Implement authentication with backend 26 if (await register(username, password)) { 27 instance.output.write(`<comment>User ${username} registered successfully!</comment>`); 28 } else { 29 instance.output.write("<comment>Could not register, something went wrong</comment>"); 30 } 31 32 base.deferred.resolve(); 33 }); 34 }).fail(() => { 35 instance.output.write("<error>Something went wrong.</error>") 36 base.deferred.resolve(); 37 }); 38 39 return base.deferred.promise(); 40 } 41 42 return base; 43 }