Example #1
0
 public static function beforeLogin($params, &$response)
 {
     $oldIgnoreAcl = \GO::setIgnoreAclPermissions(true);
     $ia = new Authenticator();
     if ($ia->setCredentials($params['username'], $params['password'])) {
         if ($ia->imapAuthenticate()) {
             if (!$ia->user) {
                 \GO::debug("IMAPAUTH: Group-Office user doesn't exist.");
                 if (!isset($params['first_name'])) {
                     $response['needCompleteProfile'] = true;
                     $response['success'] = false;
                     $response['feedback'] = \GO::t('pleaseCompleteProfile', 'imapauth');
                     return false;
                 } else {
                     //user doesn't exist. create it now
                     $user = new \GO\Base\Model\User();
                     $user->email = $ia->email;
                     $user->username = $ia->goUsername;
                     $user->password = $ia->imapPassword;
                     $user->first_name = $params['first_name'];
                     $user->middle_name = $params['middle_name'];
                     $user->last_name = $params['last_name'];
                     try {
                         if (!$user->save()) {
                             throw new \Exception("Could not save user: "******"\n", $user->getValidationErrors()));
                         }
                         if (!empty($ia->config['groups'])) {
                             $user->addToGroups($ia->config['groups']);
                         }
                         $ia->user = $user;
                         $user->checkDefaultModels();
                         //todo testen of deze regel nodig is om e-mail account aan te maken voor nieuwe gebruiker
                         $ia->createEmailAccount($user, $ia->config, $ia->imapUsername, $ia->imapPassword);
                     } catch (\Exception $e) {
                         \GO::debug('IMAPAUTH: Failed creating user ' . $ia->goUsername . ' and e-mail ' . $ia->email . 'Exception: ' . $e->getMessage(), E_USER_WARNING);
                     }
                 }
             }
         } else {
             $response['feedback'] = GO::t('badLogin') . ' (IMAP)';
             return false;
         }
     }
     \GO::setIgnoreAclPermissions($oldIgnoreAcl);
 }
Example #2
0
 private function _checkEmailAccounts(\GO\Base\Model\User $user, $password)
 {
     if (\GO::modules()->isInstalled('email')) {
         $arr = explode('@', $user->email);
         $mailbox = trim($arr[0]);
         $domain = isset($arr[1]) ? trim($arr[1]) : '';
         $imapauth = new \GO\Imapauth\Authenticator();
         $config = $imapauth->config = $imapauth->getDomainConfig($domain);
         if (!$config) {
             \GO::debug('LDAPAUTH: No E-mail configuration found for domain: ' . $domain);
             return false;
         }
         if (empty($config['create_email_account'])) {
             \GO::debug('LDAPAUTH: E-mail account creation disabled for domain: ' . $domain);
             return false;
         }
         \GO::debug('LDAPAUTH: E-mail configuration found. Creating e-mail account');
         $imapUsername = empty($config['ldap_use_email_as_imap_username']) ? $user->username : $user->email;
         if (!$imapauth->checkEmailAccounts($user, $config['host'], $imapUsername, $password)) {
             $imapauth->createEmailAccount($user, $config, $imapUsername, $password);
         }
     }
 }