1/*
2 * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6#include "UserCredentials.h"
7
8
9// These are keys that are used to store this object's data into a BMessage
10// instance.
11
12#define KEY_NICKNAME		"nickname"
13#define KEY_PASSWORD_CLEAR	"passwordClear"
14#define KEY_IS_SUCCESSFUL	"isSuccessful"
15
16
17UserCredentials::UserCredentials(BMessage* from)
18{
19	from->FindString(KEY_NICKNAME, &fNickname);
20	from->FindString(KEY_PASSWORD_CLEAR, &fPasswordClear);
21	from->FindBool(KEY_IS_SUCCESSFUL, &fIsSuccessful);
22}
23
24
25UserCredentials::UserCredentials(const BString& nickname,
26	const BString& passwordClear)
27	:
28	fNickname(nickname),
29	fPasswordClear(passwordClear),
30	fIsSuccessful(false)
31{
32}
33
34
35UserCredentials::UserCredentials()
36	:
37	fNickname(),
38	fPasswordClear(),
39	fIsSuccessful(false)
40{
41}
42
43
44UserCredentials::~UserCredentials()
45{
46}
47
48
49const BString&
50UserCredentials::Nickname() const
51{
52	return fNickname;
53}
54
55
56const BString&
57UserCredentials::PasswordClear() const
58{
59	return fPasswordClear;
60}
61
62
63const bool
64UserCredentials::IsSuccessful() const
65{
66	return fIsSuccessful;
67}
68
69
70const bool
71UserCredentials::IsValid() const
72{
73	return !fNickname.IsEmpty() && !fPasswordClear.IsEmpty();
74}
75
76
77void
78UserCredentials::SetNickname(const BString& value)
79{
80	fNickname = value;
81}
82
83
84void
85UserCredentials::SetPasswordClear(const BString& value)
86{
87	fPasswordClear = value;
88}
89
90
91void
92UserCredentials::SetIsSuccessful(bool value)
93{
94	fIsSuccessful = value;
95}
96
97
98UserCredentials&
99UserCredentials::operator=(const UserCredentials& other)
100{
101	fNickname = other.fNickname;
102	fPasswordClear = other.fPasswordClear;
103	fIsSuccessful = other.fIsSuccessful;
104	return *this;
105}
106
107
108status_t
109UserCredentials::Archive(BMessage* into, bool deep) const
110{
111	status_t result = B_OK;
112	if (result == B_OK)
113		result = into->AddString(KEY_NICKNAME, fNickname);
114	if (result == B_OK)
115		result = into->AddString(KEY_PASSWORD_CLEAR, fPasswordClear);
116	if (result == B_OK)
117		result = into->AddBool(KEY_IS_SUCCESSFUL, fIsSuccessful);
118	return result;
119}