forked from e-mission/e-mission-phone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a secret check before proceeding
This is a hack to support the specific requirements of the NREL publication process, which is currently intended to be a closed system. - Users need to scan a specified QR code that represents a secret - They are allowed to proceed only if the secret matches the app secret In the long term, we want to use channels directly instead of this "secret" code. However, we didn't want to deal with externally hosted software for approval at this time. This is the commit fixes the first three tasks in e-mission/e-mission-docs#628 in particular, e-mission/e-mission-docs#628 (comment) and e-mission/e-mission-docs#628 (comment) Changes: - new "secretcheck" service - on receiving a custom URL, pass the parameter to secretcheck - secretcheck validates the secret and stores it - change startprefs so that if we have a valid stored secret, we can move on to checking the other onboarding states - copy over the templates and the javascript code for the first screen from the em-base repository
- Loading branch information
Showing
7 changed files
with
211 additions
and
9 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
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,54 @@ | ||
angular.module('emission.splash.secretcheck', ['emission.plugin.logger', | ||
'emission.plugin.kvstore']) | ||
.factory('SecretCheck', function($window, $state, $ionicPlatform, $ionicPopup, KVStore, Logger) { | ||
|
||
var sc = {}; | ||
sc.SECRET_STORE_KEY = "secret_key"; | ||
// hardcoded to highlight that this is a hack | ||
// eventually, we want to remove this and use channels like we do for emTripLog | ||
sc.SECRET = "REPLACEME" | ||
|
||
sc.handleValidateSecretURL = function(urlComponents) { | ||
Logger.log("handleValidateSecretURL = "+JSON.stringify(urlComponents)); | ||
const inputSecret = urlComponents['secret']; | ||
Logger.log("input secret is = "+inputSecret); | ||
|
||
const next_state = urlComponents['next_state'] || "root.intro"; | ||
|
||
if (sc.checkSecret(inputSecret)) { | ||
sc.storeInputSecret(inputSecret).then(() => { | ||
$state.go(next_state); | ||
}).catch((e) => | ||
Logger.displayError("Could not store valid secret "+inputSecret, e) | ||
); | ||
} else { | ||
Logger.displayError("Invalid input secret", | ||
{message: "Input secret "+inputSecret+" does not match expected "+sc.SECRET, | ||
stack: "In splash/secret.js"}); | ||
} | ||
} | ||
|
||
sc.checkSecret = function(secret) { | ||
const retVal = secret != null && secret.length > 0 && secret === sc.SECRET; | ||
if (!retVal) { | ||
Logger.log("Secret "+secret+" does not match expected value"); | ||
}; | ||
return retVal; | ||
} | ||
|
||
sc.storeInputSecret = function(secret) { | ||
return KVStore.set(sc.SECRET_STORE_KEY, secret); | ||
} | ||
|
||
sc.getInputSecret = function() { | ||
return KVStore.get(sc.SECRET_STORE_KEY).then(function(read_secret) { | ||
return read_secret; | ||
}); | ||
} | ||
|
||
sc.hasValidSecret = function() { | ||
return sc.getInputSecret().then(sc.checkSecret); | ||
} | ||
|
||
return sc; | ||
}); |
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,41 @@ | ||
<ion-popover-view> | ||
<ion-content class="has-footer"> | ||
<div class="intro-text"> | ||
This app builds an automatic diary of all your trips, across all | ||
transportation modes. It reads multiple sensors, including | ||
location, in the background, and turns GPS tracking on and off | ||
automatically for minimal power consumption. Information about your travel | ||
patterns will be displayed to you according to the design of the study you | ||
join. | ||
</div> | ||
|
||
<div class="intro-text"> | ||
<b>Tip(s) for correct operation:</b> | ||
<div ng-show="isIOS"> | ||
<ion-list> | ||
<ion-item class="item-text-wrap"> | ||
<i class="icon ion-checkmark-circled"></i> | ||
"Always allow" access to location | ||
</ion-item> | ||
<ion-item class="item-text-wrap"> | ||
<i class="icon ion-checkmark-circled"></i> | ||
Do not force kill the app | ||
</ion-item> | ||
</ion-list> | ||
</div> | ||
<div ng-show="isAndroid"> | ||
<ion-list> | ||
<ion-item class="item-text-wrap"> <div> | ||
<i class="icon ion-checkmark-circled"></i> | ||
Keep location services turned on</div> | ||
</ion-item> | ||
</ion-list> | ||
</div> | ||
</div> | ||
</ion-content> | ||
<ion-footer-bar class="bar-positive"> | ||
<button class="button button-block button-clear" ng-click="hideDetails($event)"> | ||
Close | ||
</button> | ||
</ion-footer-bar> | ||
</ion-popover-view> |
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,45 @@ | ||
<ion-view> | ||
<ion-content class="has-footer"> | ||
<!-- <div class="intro-space"></div> --> | ||
<div class="intro-title"> | ||
<center><img alt="e-mission icon" src="img/icon.png"/ style="width: 25%; height: auto;"></center> | ||
</div> | ||
<div class="intro-text"> | ||
<div> | ||
<center><button class="button button-clear button-dark" ng-click="showDetails($event)"><b>Welcome to emTripLog ℹ️ </b></button></center> | ||
</div> | ||
<!-- --> | ||
|
||
To proceed further, you need a link 🔗 or QR code to join a study. | ||
This should have been provided by the researcher who asked you to install this | ||
app. | ||
|
||
<div class="intro-space"></div> | ||
|
||
<ion-list> | ||
<ion-item class="item-text-wrap"> | ||
<div> | ||
<i class="icon ion-iphone"></i> | ||
On your phone 📱, switch back to the browser 🌐, scroll down and | ||
click the link in step 2. | ||
</div> | ||
</ion-item> | ||
<ion-item class="item-text-wrap"> | ||
<center> <b> - OR - </b> </center> | ||
</ion-item> | ||
<ion-item class="item-text-wrap"> | ||
<div> | ||
<i class="icon ion-laptop"></i> | ||
On your computer 💻, scroll down to step 2 and scan ⬇️ the QR code. | ||
</div> | ||
</ion-item> | ||
</ion-list> | ||
<div class="intro-space"></div> | ||
</div> | ||
</ion-content> | ||
<ion-footer-bar class="bar-positive"> | ||
<button ng-enabled="scanEnabled" class="button button-block button-clear" ng-click="scanCode()"> | ||
Scan now | ||
</button> | ||
</ion-footer-bar> | ||
</ion-view> |