std::string fuh::user_info(const std::string& name) { if(!user_exists(name)) { throw error("No user with the name '" + name + "' exists."); } time_t reg_date = get_registrationdate(name); time_t ll_date = get_lastlogin(name); std::string reg_string = ctime(®_date); std::string ll_string; if(ll_date) { ll_string = ctime(&ll_date); } else { ll_string = "Never\n"; } std::stringstream info; info << "Name: " << name << "\n" << "Registered: " << reg_string << "Last login: "******"This account is currently inactive.\n"; } return info.str(); }
std::string suh::user_info(const std::string& name) { if(!user_exists(name)) throw error("No user with the name '" + name + "' exists."); time_t reg_date = get_registrationdate(name); time_t ll_date = get_lastlogin(name); std::string reg_string = ctime(®_date); std::string ll_string = ctime(&ll_date); std::stringstream info; info << "Name: " << name << "\n" << "Real name: " << get_realname(name) << "\n" << "Registered: " << reg_string << "Last login: " << ll_string; return info.str(); }
void suh::clean_up() { // Remove users that have not logged in for user_expiration_ days: // Check if the last login of this user exceeds the // expiration limit //The expiration time set to 0 means no expiration limit if(!user_expiration_) { return; } time_t now = time(NULL); //A minute has 60 seconds, an hour 60 minutes and //a day 24 hours. time_t limit = user_expiration_ * 60 * 60 * 24; std::vector<std::string> us = users(); for(std::vector<std::string>::const_iterator u = us.begin(); u != us.end(); ++u) { if((now - get_lastlogin(*u)) > limit) { std::cout << "User '" << *u << "' exceeds expiration limit.\n"; remove_user(*u); } } }