7684972a | /* Copyright (C) CJ Affiliate * * You may use, distribute and modify this code under the * terms of the GNU General Public License version 2 or * later. * * You should have received a copy of the license with this * file. If not, you will find a copy in the "LICENSE" file * at https://github.com/cjdev/dual-control. */ |
f757e35b | #include <string> |
28855478 | #include <vector> |
f757e35b | #include "validator.h" |
ee12703f | namespace { |
28855478 | class impl : public validator_ifc { private: directory directory_; |
3a7bcdbe | user_token_supplier user_token_supplier_; |
28855478 | public: impl (const directory &directory, |
3a7bcdbe | const user_token_supplier user_token_supplier) : |
28855478 | directory_ (directory), user_token_supplier_ (user_token_supplier) {} bool validate (const std::string &user_name, const std::string &token) { std::vector<user> found_user = directory_.find_user (user_name); if (found_user.empty()) { return false; |
ee12703f | } |
3a7bcdbe | std::string user_token = user_token_supplier_.token (found_user[0]); |
28855478 | return user_token == token; } }; |
ee12703f | } |
28855478 | validator create_validator (const directory &directory, |
3a7bcdbe | const user_token_supplier &user_token_supplier) |
cdf7fd74 | { |
28855478 | std::shared_ptr<validator_ifc> delegate (new impl (directory, user_token_supplier)); return validator (delegate); |
f757e35b | } |