Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- @author natedrake1234567
- @version 0.1a
- @note simple mail server
- --]]
- os.loadAPI("/conf");
- os.loadAPI("/src/core/timeMgmt");
- os.loadAPI("/src/core/netMgmt");
- os.loadAPI("/src/core/printMgmt");
- --[[
- @note version info
- --]]
- local appName="autho";
- local version="0.1a";
- --[[ GloBal Variables/Config ]]--
- local tArgs={...};
- local termWidth, termHeight=term.getSize();
- local selectedIndex=1;
- local inMenu=true;
- local menuOptions = {
- [1] = {
- text="Login",
- handler=function()
- local loggedIn = false;
- while loggedIn == false do
- username, password = printLoginScreen();
- if login(username, password) then
- loggedIn = true;
- shell.run("/testMailClient0.1", tostring(username));
- else
- loggedIn = false;
- end
- end
- end
- },
- [2] = {
- text="Create",
- handler=function()
- local accountCreated = false;
- while accountCreated == false do
- printMgmt.printCentered("Name:", 9);
- name=read();
- printMgmt.printCentered("Username:", 10);
- username=read();
- printMgmt.printCentered("Password:", 11);
- password=read();
- printMgmt.printCentered("Confirm:", 11);
- confPassword=read();
- if password == confPassword then
- createUser(name, username, password);
- else
- printMgmt.clearScreen();
- printMgmt.printCentered("Passwords do not match", 7);
- end
- end
- end
- }
- }
- function printHeader()
- printMgmt.printCentered("Minceraft PC", 2);
- term.setTextColor(colors.blue);
- printMgmt.printLeft("Powered by "..appName.." "..version, termHeight);
- term.setTextColor(colors.white);
- end
- function printMenu(menu)
- --printMgmt.clearScreen();
- printHeader();
- term.setCursorPos(16, termHeight/2);
- for i=1, #menu do
- if i==selectedIndex then
- term.setTextColor(colors.green);
- term.write("["..menu[i].text.."]".."\t\t\t");
- else
- term.setTextColor(colors.white);
- term.write(" "..menu[i].text.." \t\t\t");
- end
- end
- term.setTextColor(colors.white);
- end
- function printLoginScreen()
- printMgmt.clearScreen();
- printHeader();
- printMgmt.printPos("Username:", 17, 10);
- username = read();
- printMgmt.printPos("Password:", 17, 11);
- password = read();
- return username, password;
- end
- function onKeyPressed(key, menu)
- if key == keys.enter then
- onItemSelected(menu)
- elseif key == keys.left then
- if selectedIndex > 1 then
- selectedIndex = selectedIndex-1;
- end
- elseif key == keys.right then
- if selectedIndex < #menu then
- selectedIndex=selectedIndex+1;
- end
- end
- end
- function onItemSelected(menu)
- menu[selectedIndex].handler();
- end
- -- @note init function
- function init()
- if not netMgmt.isOpen() then
- netMgmt.open();
- end
- end
- function createUser(name, username, password)
- local messageObject = {
- type="auth0Create",
- userAgent=conf.name..";"..conf.version,
- timestamp=timeMgmt.getCurrentRealTime(),
- data={
- name=name,
- username=username,
- password=password
- }
- }
- rednet.send(conf.serverID, messageObject);
- senderID, message, distance, protocol = rednet.receive();
- if message.type == "auth0CreateSuccess" then
- shell.run("/testMailClient0.1", tostring(username));
- else
- printMgmt.printCentered(message.message, 7);
- end
- end
- function login(username, password)
- local messageObject = {
- type="auth0Login",
- userAgent=conf.name..";"..conf.version,
- timestamp=timeMgmt.getCurrentRealTime(),
- data={
- username=username,
- password=password
- }
- }
- rednet.send(conf.serverID, messageObject);
- senderID, message, distance, protocol = rednet.receive();
- if message.type == "auth0UserFound" then
- return true;
- else
- printMgmt.clearScreen()
- term.setTextColor(colors.red);
- printMgmt.printCentered("Incorrect Login Please Try Again!", 5);
- term.setTextColor(colors.white);
- return false;
- end
- end
- function main()
- init();
- while inMenu do
- printMenu(menuOptions);
- event, key=os.pullEvent("key");
- onKeyPressed(key, menuOptions);
- end
- end
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement