Skip to content
Snippets Groups Projects
Commit 7bed9f3a authored by Jared Hancock's avatar Jared Hancock
Browse files

Provide failsafe for a client's name

It is possible that a recipient received and processed by the system may not
have a name set. In that case, the email mailbox should be used. As a
failsafe, avoid crashing if the User::save() should fail.
parent 5d020999
No related branches found
No related tags found
No related merge requests found
...@@ -103,12 +103,13 @@ class UserModel extends VerySimpleModel { ...@@ -103,12 +103,13 @@ class UserModel extends VerySimpleModel {
return $this->org; return $this->org;
} }
function setOrganization($org) { function setOrganization($org, $save=true) {
if (!$org instanceof Organization) if (!$org instanceof Organization)
return false; return false;
$this->set('org', $org); $this->set('org', $org);
$this->save(); if ($save)
$this->save();
return true; return true;
} }
...@@ -146,8 +147,12 @@ class User extends UserModel { ...@@ -146,8 +147,12 @@ class User extends UserModel {
// Try and lookup by email address // Try and lookup by email address
$user = static::lookupByEmail($vars['email']); $user = static::lookupByEmail($vars['email']);
if (!$user) { if (!$user) {
$name = $vars['name'];
if (!$name)
list($name) = explode('@', $vars['email'], 2);
$user = User::create(array( $user = User::create(array(
'name'=>$vars['name'], 'name'=>$name,
'created'=>new SqlFunction('NOW'), 'created'=>new SqlFunction('NOW'),
'updated'=>new SqlFunction('NOW'), 'updated'=>new SqlFunction('NOW'),
//XXX: Do plain create once the cause //XXX: Do plain create once the cause
...@@ -156,13 +161,20 @@ class User extends UserModel { ...@@ -156,13 +161,20 @@ class User extends UserModel {
)); ));
// Is there an organization registered for this domain // Is there an organization registered for this domain
list($mailbox, $domain) = explode('@', $vars['email'], 2); list($mailbox, $domain) = explode('@', $vars['email'], 2);
if ($org = Organization::forDomain($domain)) if (isset($vars['org_id']))
$user->setOrganization($org); $user->set('org_id', $vars['org_id']);
elseif ($org = Organization::forDomain($domain))
$user->save(true); $user->setOrganization($org, false);
$user->emails->add($user->default_email);
// Attach initial custom fields try {
$user->addDynamicData($vars); $user->save(true);
$user->emails->add($user->default_email);
// Attach initial custom fields
$user->addDynamicData($vars);
}
catch (OrmException $e) {
return null;
}
} }
return $user; return $user;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment