Completed
Pull Request — master (#1559)
by Christoph
08:58
created

DefaultAccountManager::defaultConfigAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * ownCloud - Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Mail\Service\DefaultAccount;
23
24
use OCA\Mail\Service\Logger;
25
use OCP\IConfig;
26
use OCP\ISession;
27
28
class DefaultAccountManager {
29
30
	/** @var IConfig */
31
	private $config;
32
33
	/** @var ISession */
34
	private $session;
35
36
	/** @var Logger */
37
	private $logger;
38
39
	/**
40
	 * @param IConfig $config
41
	 * @param ISession $session
42
	 * @param Logger $logger
43
	 */
44
	public function __construct(IConfig $config, ISession $session, Logger $logger) {
45
		$this->config = $config;
46
		$this->session = $session;
47
		$this->logger = $logger;
48
	}
49
50
	/**
51
	 * Check whether the admin configured default account settings for creating
52
	 * a default account
53
	 *
54
	 * @return boolean
55
	 */
56
	public function defaultConfigAvailable() {
57
		return !is_null($this->getConfig());
58
	}
59
60
	/**
61
	 * @return array
62
	 */
63
	private function getConfig() {
64
		$config = $this->config->getSystemValue('app.mail.accounts.default', null);
65
		if (is_null($config)) {
66
			$this->logger->debug('no default config found');
67
			return null;
68
		} else {
69
			$this->logger->debug('default config to create a default account found');
70
			// TODO: check if config is complete
71
			return $config;
72
		}
73
	}
74
75
	/**
76
	 * Save the login password to the session to create a default account in a
77
	 * sub-sequent request
78
	 *
79
	 * @param string $password
80
	 */
81
	public function saveLoginPassword($password) {
82
		$this->session->set('mail_default_account_password', $password);
83
	}
84
85
}
86