Browse Source

checking for username being at least 5 characters

PYADPT-55
Volker Birk 8 years ago
parent
commit
e1b7830ab4
  1. 16
      src/identity.cc
  2. 2
      src/identity.hh

16
src/identity.cc

@ -13,11 +13,15 @@ namespace pEp {
Identity::Identity(string address, string username, string user_id,
string fpr, int comm_type, string lang, identity_flags_t flags)
: _ident(new_identity(address.c_str(), fpr.c_str(),
user_id.c_str(), username.c_str()), &::free_identity)
: _ident(new_identity(address.c_str(), fpr.c_str(), username.c_str(),
user_id.c_str()), &::free_identity)
{
if (!_ident)
throw bad_alloc();
if (username.length() && username.length() < 5) {
_ident = nullptr;
throw length_error("username must be at least 5 characters");
}
_ident->comm_type = (PEP_comm_type) comm_type;
_ident->flags = (identity_flags_t) flags;
this->lang(lang);
@ -85,6 +89,14 @@ namespace pEp {
return string(_ident->username) + " <" + _ident->address + ">";
}
void Identity::username(string value)
{
if (value.length() && value.length() < 5)
throw length_error("username must be at least 5 characters");
str_attr(_ident->username, value);
}
void Identity::lang(string value)
{
if (value == "")

2
src/identity.hh

@ -41,7 +41,7 @@ namespace pEp {
void user_id(string value) { str_attr(_ident->user_id, value); }
string username() { return str_attr(_ident->username); }
void username(string value) { str_attr(_ident->username, value); }
void username(string value);
PEP_comm_type comm_type() { return _ident->comm_type; }
void comm_type(PEP_comm_type value) { _ident->comm_type = value; };

Loading…
Cancel
Save