summaryrefslogtreecommitdiff
path: root/src/user.hpp
blob: 7d732951bb24b909a1762263f98a9a48688cfaea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef USER_HPP
#define USER_HPP

#include "master.hpp"

#include "user_content.hpp"

#include <cppcms/json.h>

struct User;

namespace apps {

class user : public master {
	public:
		user( aCms &cms );
		bool check_login( const std::string user, const std::string password );
		bool user_exists( const std::string user );
		void delete_user( const std::string user );
		std::string registration_start( const std::string user, const std::string password, const std::string printName, const std::string email );
		bool verify_registration_code( const std::string code );
		User getUserData( const std::string username );

	public:
		std::string last_captcha;
		std::string new_captcha;
	
	private:
		void login( );
		void logout( );	
		void register_user( );
		void confirm_register( );
		void ini( content::user &c );
		void api_users( );
		void api_user( std::string username );
};

} // namespace user

struct User {
	std::string name;
	std::string printName;
	std::string email;
};

namespace cppcms {
	namespace json {
		
template<>
struct traits<User> {

	static User get( value const &v )
	{
		User u;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		u.name = v.get<std::string>( "name" );
		u.printName = v.get<std::string>( "printName" );
		u.email = v.get<std::string>( "email" );
		return u;
	}
	
	static void set( value &v, User const &u )
	{
		v.set( "name", u.name );
		v.set( "printName", u.printName );
		v.set( "email", u.email );
	}
		
};

} } // namespace cppcms::json

#endif