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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* authentication_model.cpp
* SecondLife
*
* Created by RMS on 7/17/08.
*
*/
#include "llviewerprecompiledheaders.h"
#include "lldir.h"
#include "llfile.h"
#include "llsdserialize.h"
#include "authentication_model.h"
AuthenticationModel::AuthenticationModel()
{
loadPersistentData();
}
AuthenticationModel::~AuthenticationModel()
{
savePersistentData();
}
void AuthenticationModel::loadPersistentData()
{
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
"cross_grid_authentication.xml");
LLSD auth_llsd;
llifstream file;
file.open(filename);
if(file.is_open())
LLSDSerialize::fromXML(mAuthLLSD, file);
}
void AuthenticationModel::savePersistentData()
{
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
"cross_grid_authentication.xml");
llofstream ofile;
ofile.open(filename);
LLSDSerialize::toPrettyXML(mAuthLLSD, ofile);
}
void AuthenticationModel::revert()
{
loadPersistentData();
}
AuthenticationModel::connection_t AuthenticationModel::subscribeToModelUpdates
(event_t::slot_function_type subscriber)
{
return mEventUpdate.connect(subscriber);
}
void AuthenticationModel::unsubscribe(connection_t subscriber)
{
subscriber.disconnect();
}
/* setters */
void AuthenticationModel::addAccount(const std::string &grid, const std::string &accountName,
const std::string &accountPassword)
{
mAuthLLSD[grid][accountName] = LLSD::LLSD(accountPassword);
mEventUpdate();
}
void AuthenticationModel::removeAccount(const std::string &grid, const std::string &accountName)
{
mAuthLLSD[grid].erase(accountName);
mEventUpdate();
}
void AuthenticationModel::changePassword(const std::string &grid, const std::string &accountName,
const std::string &newPassword)
{
mAuthLLSD[grid][accountName] = newPassword;
// no event necessary: passwords aren't displayed in any view
}
/* getters */
void AuthenticationModel::getAllAccountNames(std::list<std::string> &names)
{
// TODO: implement this for account management
}
void AuthenticationModel::getAccountNames(const std::string &grid, std::set<std::string> &names)
{
if(!mAuthLLSD.has(grid))
return;
for(LLSD::map_const_iterator it = mAuthLLSD[grid].beginMap();
it != mAuthLLSD[grid].endMap(); ++it)
{
names.insert(it->first);
}
}
void AuthenticationModel::getPassword(const std::string &grid, const std::string &accountName,
std::string &password)
{
password = mAuthLLSD[grid][accountName].asString();
}
void AuthenticationModel::requestUpdate()
{
mEventUpdate();
}
|