Advertisement
minif

login

Jan 23rd, 2020
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. --Minif OS Login
  2.  
  3. --Functions
  4. osBGImageExists = false
  5. osUserImageExists = false
  6. if fs.exists("/system/images/minif") then
  7. os_BGImage = paintutils.loadImage("/system/images/minif")
  8. osBGImageExists = true
  9. end
  10.  
  11. function osPaintLockScreen()
  12. osFillBG(colors.black)
  13. if osBGImageExists then
  14. paintutils.drawImage(os_BGImage,1,1)
  15. end
  16. paintutils.drawFilledBox(1,1,osScreenSizeX,5,colors.white)
  17. paintutils.drawBox(2,4,osScreenSizeX-2,4,colors.lightGray)
  18.  
  19. term.setBackgroundColor(colors.red)
  20. term.setCursorPos(osScreenSizeX-4,1)
  21. term.setTextColor(colors.black)
  22. term.write("Power")
  23.  
  24. term.setBackgroundColor(colors.white)
  25. term.setTextColor(colors.black)
  26. term.setCursorPos(2,2)
  27. term.write("Username:")
  28. end
  29.  
  30. function osInputUserName()
  31. term.setBackgroundColor(colors.lightGray)
  32. term.setCursorPos(2,4)
  33. osEnteredUser = read()
  34. end
  35.  
  36. function osDrawUserProfile(user)
  37. if fs.exists("/system/user/" .. user .. "/icon") then
  38. os_UserImage = paintutils.loadImage("/system/user/"..user.."/icon")
  39. osUserImageExists = true
  40. paintutils.drawImage(os_UserImage,(osScreenSizeX/2)-3,8)
  41. end
  42. end
  43.  
  44. function osInputUserPassword(user)
  45. term.setBackgroundColor(colors.white)
  46. term.setTextColor(colors.black)
  47. term.setCursorPos((osScreenSizeX/2)-3,15)
  48. osEnteredPassword = read("*")
  49. if fs.exists("/system/user/"..user.."/.pass") then
  50. osPassword = fs.open("/system/user/"..user.."/.pass","r")
  51. if osEnteredPassword == osPassword.readAll() then
  52. if fs.exists("/system/desktop") then
  53. osPassword.close()
  54. shell.run("/system/desktop")
  55. else
  56. osPassword.close()
  57. if fs.exists("/disk/system/desktop") then
  58. osFillBG(colors.cyan)
  59. print("Found desktop file on disk")
  60. print("Copying file from disk...")
  61. fs.copy("disk/system/desktop","system/desktop")
  62. print("Done!")
  63. sleep(3)
  64. shell.run("/system/desktop")
  65. else
  66. osBSOD("Critical file missing.","/system/desktop is missing, and is needed to run.","Please re-install this file")
  67. end
  68. end
  69. else
  70. term.setCursorPos(2,1)
  71. term.setTextColor(colors.red)
  72. term.write("Invalid Password!")
  73. term.setTextColor(colors.black)
  74. sleep(1)
  75. end
  76. else
  77. osBSOD("Critical file missing.", "The user does not have a password file, and is needed to login", "You may need to re-configure the user.")
  78. end
  79. end
  80.  
  81. function osCheckUser()
  82. if fs.isDir("/user/"..osEnteredUser) and not (osEnteredUser == "") then
  83. osDrawUserProfile(osEnteredUser)
  84. osInputUserPassword(osEnteredUser)
  85. osPaintLockScreen()
  86. else
  87. osPaintLockScreen()
  88. term.setCursorPos(2,1)
  89. term.setTextColor(colors.red)
  90. term.write("Invalid User!")
  91. term.setTextColor(colors.black)
  92. end
  93. end
  94.  
  95. --Execution
  96.  
  97. osPaintLockScreen()
  98.  
  99. if fs.exists("/system/setupdata") then else
  100. if fs.exists("/system/tools/setup") then
  101. shell.run("/system/tools/setup")
  102. else
  103. osBSOD("Critical file missing.","/system/tools/setup is missing, and is needed to perform initial setup.","Please re-install this file")
  104. end
  105. osPaintLockScreen()
  106. end
  107.  
  108. if fs.exists("/apps") then else
  109. fs.makeDir("/apps")
  110. end
  111.  
  112. while true do
  113. osPEvent, osPB, osPX, osPY = os.pullEvent()
  114. if osPEvent == "key" then
  115. osInputUserName()
  116. osCheckUser()
  117. else
  118. if osPY == 4 then
  119. osInputUserName()
  120. osCheckUser()
  121. end
  122.  
  123. if osPY == 1 and osPX >= osScreenSizeX-4 then
  124. os.shutdown()
  125. end
  126. end
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement