Ejemplo n.º 1
0
 public function process()
 {
     if (array_key_exists('state', $this->request->get) && $this->request->get['state'] == 'nux_authorization') {
         if (array_key_exists('code', $this->request->get)) {
             $details = $this->session->get('nux_add_service_details');
             $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['redirect_uri']);
             $result = $oauth2->request_token($details['token_uri'], $this->request->get['code']);
             if (!empty($result) && array_key_exists('access_token', $result)) {
                 Hm_IMAP_List::add(array('name' => $details['name'], 'server' => $details['server'], 'port' => $details['port'], 'tls' => $details['tls'], 'user' => $details['email'], 'pass' => $result['access_token'], 'expiration' => strtotime(sprintf("+%d seconds", $result['expires_in'])), 'refresh_token' => $result['refresh_token'], 'auth' => 'xoauth2'));
                 if (isset($details['smtp'])) {
                     Hm_SMTP_List::add(array('name' => $details['name'], 'server' => $details['smtp']['server'], 'port' => $details['smtp']['port'], 'tls' => $details['smtp']['tls'], 'auth' => 'xoauth2', 'user' => $details['email'], 'pass' => $result['access_token'], 'expiration' => strtotime(sprintf("+%d seconds", $result['expires_in'])), 'refresh_token' => $result['refresh_token']));
                     $this->session->record_unsaved('SMTP server added');
                     $smtp_servers = Hm_SMTP_List::dump(false, true);
                     $this->user_config->set('smtp_servers', $smtp_servers);
                 }
                 Hm_Msgs::add('E-mail account successfully added');
                 $servers = Hm_IMAP_List::dump(false, true);
                 $this->user_config->set('imap_servers', $servers);
                 Hm_IMAP_List::clean_up();
                 $user_data = $this->user_config->dump();
                 if (!empty($user_data)) {
                     $this->session->set('user_data', $user_data);
                 }
                 $this->session->del('nux_add_service_details');
                 $this->session->record_unsaved('IMAP server added');
                 $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
                 $this->session->close_early();
             } else {
                 Hm_Msgs::add('ERRAn Error Occurred');
             }
         } elseif (array_key_exists('error', $this->request->get)) {
             Hm_Msgs::add('ERR' . ucwords(str_replace('_', ' ', $this->request->get['error'])));
         } else {
             Hm_Msgs::add('ERRAn Error Occurred');
         }
         $msgs = Hm_Msgs::get();
         $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
         Hm_Dispatch::page_redirect('?page=servers');
     }
 }
Ejemplo n.º 2
0
 public function process()
 {
     if (array_key_exists('state', $this->request->get) && $this->request->get['state'] == 'github_authorization') {
         if (array_key_exists('code', $this->request->get)) {
             $details = github_connect_details($this->config);
             $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['redirect_uri']);
             $result = $oauth2->request_token($details['token_url'], $this->request->get['code']);
             if (!empty($result) && array_key_exists('access_token', $result)) {
                 Hm_Msgs::add('Github connection established');
                 $this->user_config->set('github_connect_details', $result);
                 $user_data = $this->user_config->dump();
                 $this->session->set('user_data', $user_data);
                 $this->session->record_unsaved('Github connection');
                 $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
                 $this->session->close_early();
             } else {
                 Hm_Msgs::add('ERRAn Error Occurred');
             }
         } elseif (array_key_exists('error', $this->request->get)) {
             Hm_Msgs::add('ERR' . ucwords(str_replace('_', ' ', $this->request->get['error'])));
         } else {
             Hm_Msgs::add('ERRAn Error Occurred');
         }
         $msgs = Hm_Msgs::get();
         $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
         Hm_Dispatch::page_redirect('?page=servers');
     }
 }