-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.h
54 lines (40 loc) · 1.69 KB
/
Token.h
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
#ifndef _TOKEN_H_
#define _TOKEN_H_
#include "util/tokenExtractor.h"
#include "Credentials.h"
#include <regex>
#include <Wt/Utils>
#include <Wt/Dbo/ptr>
#include <Wt/Dbo/SqlConnectionPool>
// This class takes care of creating an access token or invalidating it
// It also contains the actual username and password
class Token {
public:
Token(std::string base64str);
// creates an access token using the provided base64 string on construction
// and returns true on success
// or returns false on failure
bool createAccessToken(Wt::Dbo::SqlConnectionPool& connPool);
// In order for this funciton to work, It needs to compare the
// accessToken parameter with the one it creates from the base64str
// that is taken in construction and if equal -> does the job and returns true
// else -> return false
bool invalidateAccessToken(std::string accessToken,
Wt::Dbo::SqlConnectionPool& connPool);
// this function uses the username and password extracted by the Ctor and creates a new user in the db
// getters
std::string getUsername();
std::string getPassword();
std::string getAccessToken();
std::string getBase64str();
static std::regex getEmailRegex();
static std::regex getPhoneNumberRegex();
private:
std::string _base64str;
std::string _accessToken; // an empty string initially
std::string _username;
std::string _password;
static std::regex __phoneNumber;
static std::regex __email;
};
#endif