Link sharing works

This commit is contained in:
brantje 2016-10-04 00:19:46 +02:00
parent 4ded0d8e0b
commit 294b9f7201
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
6 changed files with 21 additions and 81 deletions

View file

@ -419,14 +419,14 @@
<field> <field>
<name>vault_id</name> <name>vault_id</name>
<type>integer</type> <type>integer</type>
<notnull>true</notnull> <notnull>false</notnull>
<unsigned>true</unsigned> <unsigned>true</unsigned>
<length>8</length> <length>8</length>
</field> </field>
<field> <field>
<name>vault_guid</name> <name>vault_guid</name>
<type>text</type> <type>text</type>
<notnull>true</notnull> <notnull>false</notnull>
<length>64</length> <length>64</length>
</field> </field>
<field> <field>
@ -470,7 +470,7 @@
<field> <field>
<name>shared_key</name> <name>shared_key</name>
<type>clob</type> <type>clob</type>
<notnull>true</notnull> <notnull>false</notnull>
</field> </field>
</declaration> </declaration>
</table> </table>

View file

@ -5,7 +5,7 @@
<description>A password manager for Nextcloud</description> <description>A password manager for Nextcloud</description>
<licence>AGPL</licence> <licence>AGPL</licence>
<author>Sander Brand</author> <author>Sander Brand</author>
<version>1.0.2.21</version> <version>1.0.2.24</version>
<namespace>Passman</namespace> <namespace>Passman</namespace>
<category>other</category> <category>other</category>
<website>https://github.com/nextcloud/passman/</website> <website>https://github.com/nextcloud/passman/</website>

View file

@ -297,6 +297,8 @@ class ShareController extends ApiController {
* @PublicPage * @PublicPage
*/ */
public function getPublicCredentialData($credential_guid) { public function getPublicCredentialData($credential_guid) {
//@TODO if ExpireViews --, if 0 delete
//@TODO Check expire date
try { try {
$credential = $this->shareService->getSharedItem(null, $credential_guid); $credential = $this->shareService->getSharedItem(null, $credential_guid);
return new JSONResponse($credential); return new JSONResponse($credential);

View file

@ -10,83 +10,20 @@ angular.module('passmanApp')
$scope.test = 'hello world'; $scope.test = 'hello world';
$scope.loading = false; $scope.loading = false;
var example_shared_credential = {
"credential_id": 292,
"guid": "3D18EAD3-CF40-4B2B-B568-82CD7CB3D47F",
"user_id": "sander",
"vault_id": 2,
"label": "donnelly.com",
"description": null,
"created": 1475479693,
"changed": 1475479693,
"tags": [{"text": "Games"}],
"email": null,
"username": "ebrekke",
"password": "hd%/U_%vzvh%",
"url": "http://api.namefake.com/english-united-states/male/2854dda4938c9c5f60a288fa6fbe5095",
"favicon": null,
"renew_interval": null,
"expire_time": 0,
"delete_time": 0,
"files": [{
"file_id": 1,
"filename": "20160925-Clipperz_Export.html",
"guid": "6DA2CE41-A26B-4F97-A334-2CC74F7E9890",
"size": 13863,
"created": 1475485368,
"mimetype": "text/html",
"$$hashKey": "object:1261"
}, {
"file_id": 2,
"filename": "20160925_Clipperz_Offline.html",
"guid": "9337D189-B79E-4750-BEF9-3C912A9EA59D",
"size": 3088428,
"created": 1475485376,
"mimetype": "text/html",
"$$hashKey": "object:1268"
}],
"custom_fields": [{
"label": "Test field",
"value": "blah blah",
"secret": false,
"$$hashKey": "object:1205"
}, {
"label": "another field =)",
"value": "vlaue",
"secret": true,
"$$hashKey": "object:1220"
}],
"otp": {
"type": "totp",
"label": "Google:fake@gmail.com",
"qr_uri": {
"qrData": "otpauth://totp/Google%3Afake%40gmail.com?secret=oyonyttithtryvpnqqrxluytgwon2mhw&issuer=Google",
"image": ""
},
"secret": "oyonyttithtryvpnqqrxluytgwon2mhw",
"issuer": "Google"
},
"hidden": 0,
"shared_key": null,
"tags_raw": [{"text": "Games"}]
};
$scope.loadSharedCredential = function () { $scope.loadSharedCredential = function () {
$scope.loading = true; $scope.loading = true;
var guid = $window.location.hash.replace('#',''); var data = window.atob($window.location.hash.replace('#','')).split('<::>');
var guid = data[0];
var _key = data[1];
ShareService.getPublicSharedCredential(guid).then(function (sharedCredential) { ShareService.getPublicSharedCredential(guid).then(function (sharedCredential) {
$scope.loading = false; $scope.loading = false;
console.log(sharedCredential)
if(sharedCredential.status === 200){ if(sharedCredential.status === 200){
$scope.shared_credential = example_shared_credential; var _credential = ShareService.decryptSharedCredential(sharedCredential.data.credential_data, _key);
$scope.shared_credential = _credential;
} else { } else {
$scope.expired = true; $scope.expired = true;
} }
}, function(error){
return false;
}) })
} }

View file

@ -61,7 +61,6 @@ angular.module('passmanApp')
$location.path('/vault/' + $scope.storedCredential.vault_id); $location.path('/vault/' + $scope.storedCredential.vault_id);
}; };
$scope.share_link = $location.$$protocol + '://' + $location.$$host + OC.generateUrl('apps/passman/share/public#') + $scope.storedCredential.guid;
$scope.default_permissions = new SharingACL(0); $scope.default_permissions = new SharingACL(0);
$scope.default_permissions.addPermission( $scope.default_permissions.addPermission(
@ -138,12 +137,11 @@ angular.module('passmanApp')
}; };
$scope.unshareCredential = function (credential) { $scope.unshareCredential = function (credential) {
ShareService.unshareCredential(credential).then(function () { ShareService.unshareCredential(credential);
var _credential = angular.copy(credential); var _credential = angular.copy(credential);
_credential.shared_key = null; _credential.shared_key = null;
CredentialService.updateCredential(_credential).then(function () { CredentialService.updateCredential(_credential).then(function () {
NotificationService.showNotification('Credential unshared', 4000) NotificationService.showNotification('Credential unshared', 4000)
})
}) })
}; };
@ -196,12 +194,15 @@ angular.module('passmanApp')
if($scope.share_settings.linkSharing.enabled){ if($scope.share_settings.linkSharing.enabled){
var shareObj = { var shareObj = {
item_id: '', item_id: $scope.storedCredential.credential_id,
item_guid: $scope.storedCredential.guid,
permissions: $scope.share_settings.linkSharing.settings.acl.getAccessLevel(), permissions: $scope.share_settings.linkSharing.settings.acl.getAccessLevel(),
expire_timestamp: $scope.share_settings.linkSharing.settings.expire_time, expire_timestamp: $scope.share_settings.linkSharing.settings.expire_time,
expire_views: $scope.share_settings.linkSharing.settings.expire_views expire_views: $scope.share_settings.linkSharing.settings.expire_views
}; };
ShareService.createPublicSharedCredential(shareObj).then(function(){ ShareService.createPublicSharedCredential(shareObj).then(function(){
var hash = window.btoa($scope.storedCredential.guid + '<::>'+ key)
$scope.share_link = $location.$$protocol + '://' + $location.$$host + OC.generateUrl('apps/passman/share/public#') + hash;
}); });
} }

View file

@ -65,7 +65,7 @@ style('passman', 'public-page');
<div class="col-xs-8 col-xs-push-2 col-xs-pull-2 credential_container"> <div class="col-xs-8 col-xs-push-2 col-xs-pull-2 credential_container">
<h2>Passman</h2> <h2>Passman</h2>
<div ng-if="!shared_credential && !expired"> <div ng-if="!shared_credential && !expired">
<span class="text">{name} has shared a credential with you.</span> <span class="text">Someone has shared a credential with you.</span>
<button class="button-geen" ng-if="!loading" <button class="button-geen" ng-if="!loading"
ng-click="loadSharedCredential()">Click here to request ng-click="loadSharedCredential()">Click here to request
it it