Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions brick/account.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Account::SetPassword(std::string password) {

void
Account::SetDomain(std::string domain) {
Account::trim(domain);
domain_ = domain;
label_ = GenLabel();
base_url_ = GenBaseUrl();
Expand All @@ -140,6 +141,29 @@ Account::SetUseAppPassword(bool use) {
use_app_password_ = use;
}

bool
Account::needTrim(int ch) {
return !std::isspace(ch) && !std::ispunct(ch);
}

void
Account::lTrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), Account::needTrim));
}

// trim from end (in place)
void
Account::rTrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),Account::needTrim).base(), s.end());
}

// trim from both ends (in place)
void
Account::trim(std::string &s) {
Account::lTrim(s);
Account::rTrim(s);
}

void
Account::Set(
bool secure,
Expand All @@ -149,6 +173,7 @@ Account::Set(
bool use_app_password) {

secure_ = secure;
Account::trim(domain);
domain_ = domain;
login_ = login;
password_ = password;
Expand All @@ -163,6 +188,7 @@ Account::GenBaseUrl() {
return (GetOrigin() + kDefaultAppUrl);
}


void
Account::Auth(bool renew_password, const AuthCallback& callback, const std::string& otp) {
CEF_REQUIRE_UI_THREAD();
Expand Down
5 changes: 5 additions & 0 deletions brick/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Account : public CefBase {
void SetUseAppPassword(bool use);
void SetId(int id);

static void trim(std::string &s);
static void rTrim(std::string &s);
static void lTrim(std::string &s);
static bool needTrim(int ch);

std::string GenLabel();
std::string GenBaseUrl();

Expand Down