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 UserCredentials& 59 UserCredentials::operator=(const UserCredentials& other) 60 { 61 fNickname = other.fNickname; 62 fPasswordClear = other.fPasswordClear; 63 fIsSuccessful = other.fIsSuccessful; 64 return *this; 65 } 66 67 68 bool 69 UserCredentials::operator==(const UserCredentials& other) const 70 { 71 return fNickname == other.fNickname && fPasswordClear == other.fPasswordClear 72 && fIsSuccessful == other.fIsSuccessful; 73 } 74 75 76 bool 77 UserCredentials::operator!=(const UserCredentials& other) const 78 { 79 return !(*this == other); 80 } 81 82 83 const BString& 84 UserCredentials::Nickname() const 85 { 86 return fNickname; 87 } 88 89 90 const BString& 91 UserCredentials::PasswordClear() const 92 { 93 return fPasswordClear; 94 } 95 96 97 const bool 98 UserCredentials::IsSuccessful() const 99 { 100 return fIsSuccessful; 101 } 102 103 104 const bool 105 UserCredentials::IsValid() const 106 { 107 return !fNickname.IsEmpty() && !fPasswordClear.IsEmpty(); 108 } 109 110 111 void 112 UserCredentials::SetNickname(const BString& value) 113 { 114 fNickname = value; 115 } 116 117 118 void 119 UserCredentials::SetPasswordClear(const BString& value) 120 { 121 fPasswordClear = value; 122 } 123 124 125 void 126 UserCredentials::SetIsSuccessful(bool value) 127 { 128 fIsSuccessful = value; 129 } 130 131 132 status_t 133 UserCredentials::Archive(BMessage* into, bool deep) const 134 { 135 status_t result = B_OK; 136 if (result == B_OK) 137 result = into->AddString(KEY_NICKNAME, fNickname); 138 if (result == B_OK) 139 result = into->AddString(KEY_PASSWORD_CLEAR, fPasswordClear); 140 if (result == B_OK) 141 result = into->AddBool(KEY_IS_SUCCESSFUL, fIsSuccessful); 142 return result; 143 }