minif

login1.1

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