summaryrefslogtreecommitdiff
path: root/member.cxx
blob: c38dc32f03adb29e31b89965015219fcfcbdf5e2 (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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <interchange.h>
#include <interchange/member.h>
#include "interchange/member.hxx"

namespace QInterchange {

	static char *unCopy, *pwCopy, *vCopy, *fpCopy;

	void Member::newAccount(QString const& username,
			QString const& password, QString const& verify,
			QString const& failPage)
	{
		auto unData = username.toLatin1().constData();
		unCopy = (char*)malloc(strlen(unData) + 1);
		strcpy(unCopy, unData);
		auto pwData = password.toLatin1().constData();
		pwCopy = (char*)malloc(strlen(pwData) + 1);
		strcpy(pwCopy, pwData);
		auto vData = verify.toLatin1().constData();
		vCopy = (char*)malloc(strlen(vData) + 1);
		strcpy(vCopy, vData);
		auto fpData = failPage.toLatin1().constData();
		fpCopy = (char*)malloc(strlen(fpData) + 1);
		strcpy(fpCopy, fpData);
		interchange_member_newaccount(unCopy, pwCopy, vCopy, fpCopy,
			[](interchange_response* response) {
				free(unCopy);
				free(pwCopy);
				free(vCopy);
				free(fpCopy);
				interchange_free_response(response);
			}, nullptr);
	}

	void Member::logIn(QString const& username, QString const& password,
			QString const& failPage)
	{
		auto unData = username.toLatin1().constData();
		unCopy = (char*)malloc(strlen(unData) + 1);
		strcpy(unCopy, unData);
		auto pwData = password.toLatin1().constData();
		pwCopy = (char*)malloc(strlen(pwData) + 1);
		strcpy(pwCopy, pwData);
		auto fpData = failPage.toLatin1().constData();
		fpCopy = (char*)malloc(strlen(fpData) + 1);
		strcpy(fpCopy, fpData);
		interchange_member_login(unCopy, pwCopy, fpCopy,
			[](interchange_response* response) {
				free(unCopy);
				free(pwCopy);
				free(fpCopy);
				interchange_free_response(response);
			}, nullptr);
	}

	void Member::setUserName(QString const& userName)
	{
		if (m_userName != userName) {
			m_userName = userName;
			emit userNameChanged();
		}
	}

	void Member::setUserNick(QString const& userNick)
	{
		if (m_userNick != userNick) {
			m_userNick = userNick;
			emit userNickChanged();
		}
	}

	void Member::setPassword(QString const& password)
	{
		if (m_password != password) {
			m_password = password;
			emit passwordChanged();
		}
	}

	void Member::setExpiration(QString const& expiration)
	{
		if (m_expiration != expiration) {
			m_expiration = expiration;
			emit expirationChanged();
		}
	}

	void Member::setAcl(QString const& acl)
	{
		if (m_acl != acl) {
			m_acl = acl;
			emit aclChanged();
		}
	}

	void Member::setModTime(QString const& modTime)
	{
		if (m_modTime != modTime) {
			m_modTime = modTime;
			emit modTimeChanged();
		}
	}

	void Member::setSNickName(QString const& sNickName)
	{
		if (m_sNickName != sNickName) {
			m_sNickName = sNickName;
			emit sNickNameChanged();
		}
	}

	void Member::setCompany(QString const& company)
	{
		if (m_company != company) {
			m_company = company;
			emit companyChanged();
		}
	}

	void Member::setFName(QString const& fName)
	{
		if (m_fName != fName) {
			m_fName = fName;
			emit fNameChanged();
		}
	}

	void Member::setLName(QString const& lName)
	{
		if (m_lName != lName) {
			m_lName = lName;
			emit lNameChanged();
		}
	}

	void Member::setAddress1(QString const& address1)
	{
		if (m_address1 != address1) {
			m_address1 = address1;
			emit address1Changed();
		}
	}

	void Member::setAddress2(QString const& address2)
	{
		if (m_address2 != address2) {
			m_address2 = address2;
			emit address2Changed();
		}
	}

	void Member::setAddress3(QString const& address3)
	{
		if (m_address3 != address3) {
			m_address3 = address3;
			emit address3Changed();
		}
	}

	void Member::setCity(QString const& city)
	{
		if (m_city != city) {
			m_city = city;
			emit cityChanged();
		}
	}

	void Member::setState(QString const& state)
	{
		if (m_state != state) {
			m_state = state;
			emit stateChanged();
		}
	}

	void Member::setZip(QString const& zip)
	{
		if (m_zip != zip) {
			m_zip = zip;
			emit zipChanged();
		}
	}

	void Member::setCountry(QString const& country)
	{
		if (m_country != country) {
			m_country = country;
			emit countryChanged();
		}
	}

	void Member::setPhoneDay(QString const& phoneDay)
	{
		if (m_phoneDay != phoneDay) {
			m_phoneDay = phoneDay;
			emit phoneDayChanged();
		}
	}

	void Member::setEmail(QString const& email)
	{
		if (m_email != email) {
			m_email = email;
			emit emailChanged();
		}
	}

	void Member::setData(interchange_member* data)
	{
		if (data && data->username && m_userName != data->username) {
			m_userName = QString{data->username};
			emit userNameChanged();
		} else setUserName("");

		if (data && data->usernick && m_userNick != data->usernick) {
			m_userNick = QString{data->usernick};
			emit userNickChanged();
		} else setUserNick("");

		if (data && data->password && m_password != data->password) {
			m_password = QString{data->password};
			emit passwordChanged();
		} else setPassword("");

		if (data && data->expiration && m_expiration != data->expiration) {
			m_expiration = QString{data->expiration};
			emit expirationChanged();
		} else setExpiration("");

		if (data && data->acl && m_acl != data->acl) {
			m_acl = QString{data->acl};
			emit aclChanged();
		} else setAcl("");

		if (data && data->mod_time && m_modTime != data->mod_time) {
			m_modTime = QString{data->mod_time};
			emit modTimeChanged();
		} else setModTime("");

		if (data && data->s_nickname && m_sNickName != data->s_nickname) {
			m_sNickName = QString{data->s_nickname};
			emit sNickNameChanged();
		} else setSNickName("");

		if (data && data->company && m_company != data->company) {
			m_company = QString{data->company};
			emit companyChanged();
		} else setCompany("");

		if (data && data->fname && m_fName != data->fname) {
			m_fName = QString{data->fname};
			emit fNameChanged();
		} else setFName("");

		if (data && data->lname && m_lName != data->lname) {
			m_lName = QString{data->lname};
			emit lNameChanged();
		} else setLName("");

		if (data && data->address1 && m_address1 != data->address1) {
			m_address1 = QString{data->address1};
			emit address1Changed();
		} else setAddress1("");

		if (data && data->address2 && m_address2 != data->address2) {
			m_address2 = QString{data->address2};
			emit address2Changed();
		} else setAddress2("");

		if (data && data->address3 && m_address3 != data->address3) {
			m_address3 = QString{data->address3};
			emit address3Changed();
		} else setAddress3("");

		if (data && data->city && m_city != data->city) {
			m_city = QString{data->city};
			emit cityChanged();
		} else setCity("");

		if (data && data->state && m_state != data->state) {
			m_state = QString{data->state};
			emit stateChanged();
		} else setState("");

		if (data && data->zip && m_zip != data->zip) {
			m_zip = QString{data->zip};
			emit zipChanged();
		} else setZip("");

		if (data && data->country && m_country != data->country) {
			m_country = QString{data->country};
			emit countryChanged();
		} else setCountry("");

		if (data && data->phone_day && m_phoneDay != data->phone_day) {
			m_phoneDay = QString{data->phone_day};
			emit phoneDayChanged();
		} else setPhoneDay("");

		if (data && data->email && m_email != data->email) {
			m_email = QString{data->email};
			emit emailChanged();
		} else setEmail("");

		if (m_data != data) m_data = data;
	}

	void Member::account(QString const& firstName, QString const& lastName,
			QString const& address1, QString const& address2,
			QString const& city, QString const& state, QString const& zip,
			QString const& email, QString const& phoneDay)
	{
		interchange_member_account(firstName.toLatin1().constData(),
				lastName.toLatin1().constData(),
				address1.toLatin1().constData(),
				address2.toLatin1().constData(),
				city.toLatin1().constData(), state.toLatin1().constData(),
				zip.toLatin1().constData(), email.toLatin1().constData(),
				phoneDay.toLatin1().constData());
	}

	void Member::changePassword(QString const& passwordOld, QString const& password,
			QString const& verify)
	{
		interchange_member_changepassword(passwordOld.toLatin1().constData(),
				password.toLatin1().constData(),
				verify.toLatin1().constData());
	}

	void Member::logOut()
	{
		interchange_member_logout(m_data);
		setData(nullptr);
	}

}