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. */ |
7699d7ec | #ifndef _TOKEN_H #define _TOKEN_H |
b5e563ba | |
f757e35b | #include <string> #include <memory> |
af3a4cd4 | #include <functional> |
b5e563ba | |
f757e35b | #include "user.h" |
215ea751 | #include "sys_fstream.h" |
f757e35b | |
e064ffa9 | class tokens_ifc |
cdf7fd74 | { public: |
af3a4cd4 | using token_generator = std::function<std::string()>; |
e064ffa9 | virtual ~tokens_ifc() {} |
af3a4cd4 | virtual std::string token (const user &user) const |
b65518d3 | { |
b5e563ba | return ""; |
3a7bcdbe | } |
decf9568 | virtual void save (const user &user, const std::string &token) const {} |
9af49688 | }; |
3a7bcdbe | |
e064ffa9 | class tokens |
b65518d3 | { |
0e218820 | public: |
e064ffa9 | typedef std::shared_ptr<tokens_ifc> delegate; |
0e218820 | private: delegate delegate_; public: |
e064ffa9 | tokens (delegate delegate) : |
b65518d3 | delegate_ (delegate) {} |
e064ffa9 | tokens() : tokens ( delegate (new tokens_ifc)) {} |
af3a4cd4 | std::string token (const user &user) const |
0e218820 | { return delegate_->token (user); } |
decf9568 | void save (const user &user, const std::string &token) const |
d10906ee | { |
decf9568 | return delegate_->save (user, token); |
af3a4cd4 | } |
6603197e | static tokens create (const fstreams &fstreams); |
3a7bcdbe | }; |
7699d7ec | #endif |
92957308 |