| 59 | } |
| 60 | |
| 61 | int main(int argc, char** argv){ |
| 62 | Lemon::JSONParser cfgParser = Lemon::JSONParser("/system/lemon/users.json"); |
| 63 | |
| 64 | auto json = cfgParser.Parse(); |
| 65 | if(json.IsObject()){ |
| 66 | std::map<Lemon::JSONKey, Lemon::JSONValue>& root = *json.object; |
| 67 | |
| 68 | if(auto it = root.find("users"); it != root.end() && it->second.IsArray()){ |
| 69 | for(Lemon::JSONValue& v : *it->second.array){ |
| 70 | if(v.IsObject()){ |
| 71 | User u; |
| 72 | std::map<Lemon::JSONKey, Lemon::JSONValue>& values = *v.object; |
| 73 | |
| 74 | if(auto it = values.find("name"); it != values.end() && it->second.IsString()){ |
| 75 | u.username = it->second.AsString(); |
| 76 | } else { |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | if(auto it = values.find("hash"); it != values.end() && it->second.IsString()){ |
| 81 | u.hash = it->second.AsString(); |
| 82 | } else { |
| 83 | continue; |
| 84 | } |
| 85 | |
| 86 | if(auto it = values.find("uid"); it != values.end() && it->second.IsNumber()){ |
| 87 | u.uid = it->second.AsSignedNumber(); |
| 88 | } else { |
| 89 | continue; |
| 90 | } |
| 91 | |
| 92 | if(auto it = values.find("gid"); it != values.end() && it->second.IsNumber()){ |
| 93 | u.gid = it->second.AsSignedNumber(); |
| 94 | } else { |
| 95 | continue; |
| 96 | } |
| 97 | |
| 98 | users[u.username] = u; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } else { |
| 103 | printf("Failied to parse users.json!\n"); |
| 104 | } |
| 105 | |
| 106 | if(!users.size()){ // TODO: Don't just boot to shell |
| 107 | char* const args[] = {const_cast<char*>("/system/bin/shell.lef")}; // There are no users just load the shell |
| 108 | lemon_spawn(*args, 1, args, 0); |
| 109 | |
| 110 | exit(0); |
| 111 | } |
| 112 | |
| 113 | usernameLabel = new Lemon::GUI::Label("Username:", {10, 20, 100, 16}); |
| 114 | usernameBox = new Lemon::GUI::TextBox({Lemon::Graphics::GetTextLength("Username:") + 20, 16, 10, 24}, false); |
| 115 | usernameBox->SetLayout(Lemon::GUI::Stretch, Lemon::GUI::Fixed); |
| 116 | usernameBox->LoadText("root"); |
| 117 | |
| 118 | passwordLabel = new Lemon::GUI::Label("Password:", {10, 48, 100, 16}); |
nothing calls this directly
no test coverage detected