-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store / retrieve temporary passwords from database
This makes them much shorter. Downside: They're no longer stateless :(
- Loading branch information
Leon Klingele
committed
Jul 27, 2017
1 parent
32af810
commit 63decef
Showing
14 changed files
with
258 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<database> | ||
<name>*dbname*</name> | ||
<create>true</create> | ||
<overwrite>false</overwrite> | ||
<charset>utf8</charset> | ||
<table> | ||
<name>*dbprefix*spreedme_tps</name> | ||
<declaration> | ||
<field> | ||
<name>id</name> | ||
<type>integer</type> | ||
<autoincrement>1</autoincrement> | ||
</field> | ||
<field> | ||
<name>tp</name> | ||
<type>text</type> | ||
<notnull>true</notnull> | ||
<length>64</length> | ||
</field> | ||
<field> | ||
<name>userid</name> | ||
<type>text</type> | ||
<notnull>true</notnull> | ||
<length>64</length> | ||
</field> | ||
<field> | ||
<name>expiration</name> | ||
<type>timestamp</type> | ||
<notnull>true</notnull> | ||
</field> | ||
<index> | ||
<name>spreedme_tps_tp</name> | ||
<unique>true</unique> | ||
<field> | ||
<name>tp</name> | ||
</field> | ||
</index> | ||
</declaration> | ||
</table> | ||
</database> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Nextcloud - spreedme | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. See the COPYING file. | ||
* | ||
* @author Leon <[email protected]> | ||
* @copyright struktur AG 2016 | ||
*/ | ||
|
||
namespace OCA\SpreedME\Controller; | ||
|
||
use OCA\SpreedME\Security\TemporaryPasswordManager; | ||
use OCA\SpreedME\User\User; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\IDBConnection; | ||
use OCP\IRequest; | ||
|
||
class TemporaryPasswordController extends Controller { | ||
|
||
private $user; | ||
private $temporaryPasswordManager; | ||
|
||
public function __construct($appName, IRequest $request, IDBConnection $db) { | ||
parent::__construct($appName, $request); | ||
|
||
if (!empty($userId)) { | ||
$this->user = new User($userId); | ||
} else { | ||
$this->user = new User(); | ||
} | ||
|
||
$this->temporaryPasswordManager = new TemporaryPasswordManager($db); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
*/ | ||
public function generateTemporaryPassword($userid, $expiration) { | ||
$_response = array('success' => false); | ||
if ($this->user->isSpreedMeAdmin() && $userid !== null && $expiration !== null) { | ||
try { | ||
$_response['tp'] = $this->temporaryPasswordManager->generateTemporaryPassword($userid, $expiration); | ||
$_response['success'] = true; | ||
} catch (\Exception $e) { | ||
$_response['error'] = $e->getCode(); | ||
} | ||
} | ||
|
||
return new DataResponse($_response); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
* @PublicPage | ||
*/ | ||
public function getTokenWithTemporaryPassword($tp) { | ||
$_response = array('success' => false); | ||
if ($tp) { | ||
try { | ||
$token = $this->temporaryPasswordManager->getSignedComboFromTemporaryPassword($tp); | ||
$_response = array_merge($_response, $token); | ||
$_response['success'] = true; | ||
} catch (\Exception $e) { | ||
$_response['error'] = $e->getCode(); | ||
} | ||
} | ||
|
||
return new DataResponse($_response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.