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

orgs: Auto import based on email domain

parent a45bb90b
Branches
Tags
No related merge requests found
......@@ -129,6 +129,15 @@ class Organization extends OrganizationModel {
return $base;
}
function isMappedToDomain($domain) {
foreach (explode(',', $this->domain) as $d) {
if (strcasecmp($domain, trim($d)) === 0) {
return true;
}
}
return false;
}
function to_json() {
$info = array(
......@@ -164,8 +173,8 @@ class Organization extends OrganizationModel {
if ($vars['domain']) {
foreach (explode(',', $vars['domain']) as $d) {
if (!Validator::is_email('test' . trim($d))) {
$errors['domain'] = 'Enter a valid email domain, like @domain.com';
if (!Validator::is_email('t@' . trim($d))) {
$errors['domain'] = 'Enter a valid email domain, like domain.com';
}
}
}
......
......@@ -154,6 +154,16 @@ class User extends UserModel {
// of the detached emails is fixed.
'default_email' => UserEmail::ensure($vars['email'])
));
// Is there an organization registered for this domain
list($mailbox, $domain) = explode('@', $vars['email'], 2);
foreach (Organization::objects()
->filter(array('domain__contains'=>$domain)) as $org) {
if ($org->isMappedToDomain($domain)) {
$user->setOrganization($org);
break;
}
}
$user->save(true);
$user->emails->add($user->default_email);
// Attach initial custom fields
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment