xref: /haiku/src/apps/haikudepot/model/UserCredentials.cpp (revision 0f9ffb37c166a9d9257044c8937f6450f4257b75)
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 
17 UserCredentials::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 
25 UserCredentials::UserCredentials(const BString& nickname,
26 	const BString& passwordClear)
27 	:
28 	fNickname(nickname),
29 	fPasswordClear(passwordClear),
30 	fIsSuccessful(false)
31 {
32 }
33 
34 
35 UserCredentials::UserCredentials(const UserCredentials& other)
36 	:
37 	fNickname(other.Nickname()),
38 	fPasswordClear(other.PasswordClear()),
39 	fIsSuccessful(false)
40 {
41 }
42 
43 
44 UserCredentials::UserCredentials()
45 	:
46 	fNickname(),
47 	fPasswordClear(),
48 	fIsSuccessful(false)
49 {
50 }
51 
52 
53 UserCredentials::~UserCredentials()
54 {
55 }
56 
57 
58 const BString&
59 UserCredentials::Nickname() const
60 {
61 	return fNickname;
62 }
63 
64 
65 const BString&
66 UserCredentials::PasswordClear() const
67 {
68 	return fPasswordClear;
69 }
70 
71 
72 const bool
73 UserCredentials::IsSuccessful() const
74 {
75 	return fIsSuccessful;
76 }
77 
78 
79 const bool
80 UserCredentials::IsValid() const
81 {
82 	return !fNickname.IsEmpty() && !fPasswordClear.IsEmpty();
83 }
84 
85 
86 void
87 UserCredentials::SetNickname(const BString& value)
88 {
89 	fNickname = value;
90 }
91 
92 
93 void
94 UserCredentials::SetPasswordClear(const BString& value)
95 {
96 	fPasswordClear = value;
97 }
98 
99 
100 void
101 UserCredentials::SetIsSuccessful(bool value)
102 {
103 	fIsSuccessful = value;
104 }
105 
106 
107 UserCredentials&
108 UserCredentials::operator=(const UserCredentials& other)
109 {
110 	fNickname = other.fNickname;
111 	fPasswordClear = other.fPasswordClear;
112 	fIsSuccessful = other.fIsSuccessful;
113 	return *this;
114 }
115 
116 
117 status_t
118 UserCredentials::Archive(BMessage* into, bool deep) const
119 {
120 	status_t result = B_OK;
121 	if (result == B_OK)
122 		result = into->AddString(KEY_NICKNAME, fNickname);
123 	if (result == B_OK)
124 		result = into->AddString(KEY_PASSWORD_CLEAR, fPasswordClear);
125 	if (result == B_OK)
126 		result = into->AddBool(KEY_IS_SUCCESSFUL, fIsSuccessful);
127 	return result;
128 }