User.h 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This may look like C code, but it's really -*- C++ -*-
  2. /*
  3. * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
  4. *
  5. * See the LICENSE file for terms of use.
  6. */
  7. #ifndef USER_H_
  8. #define USER_H_
  9. #include <Wt/WDateTime>
  10. #include <Wt/Dbo/Types>
  11. #include <Wt/Dbo/WtSqlTraits>
  12. #include <Wt/Auth/Dbo/AuthInfo>
  13. #include <string>
  14. class User;
  15. typedef Wt::Auth::Dbo::AuthInfo<User> AuthInfo;
  16. typedef Wt::Dbo::collection< Wt::Dbo::ptr<User> > Users;
  17. class User
  18. {
  19. public:
  20. User();
  21. std::string name; /* a copy of auth info's user name */
  22. int gamesPlayed;
  23. long long score;
  24. Wt::WDateTime lastGame;
  25. Wt::Dbo::collection< Wt::Dbo::ptr<AuthInfo> > authInfos;
  26. template<class Action>
  27. void persist(Action& a)
  28. {
  29. Wt::Dbo::field(a, gamesPlayed, "gamesPlayed");
  30. Wt::Dbo::field(a, score, "score");
  31. Wt::Dbo::field(a, lastGame, "lastGame");
  32. Wt::Dbo::hasMany(a, authInfos, Wt::Dbo::ManyToOne, "user");
  33. }
  34. };
  35. DBO_EXTERN_TEMPLATES(User);
  36. #endif // USER_H_