Skip to content

Commit

Permalink
feat(bot): ui for generating bot auth code
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Jan 14, 2022
1 parent bfda044 commit 63b9657
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module.exports = function (app, passport) {
_id: newName,
created: Date.now(),
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.ip,
source: 'upload',
encrypted: req.body.encrypted || false,
type: req.files[FILE_UPLOAD_FIELD].type,
createdBy: req.user._id
Expand Down
1 change: 1 addition & 0 deletions public/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<script src="scripts/services/remote.js"></script>
<script src="scripts/services/image.js"></script>
<script src="scripts/services/collection.js"></script>
<script src="scripts/services/telegram.js"></script>
<script src="scripts/services/encryption.js"></script>
<script src="scripts/filters/imageLinkFilters.js"></script>
<script src="scripts/directives/myenter.js"></script>
Expand Down
8 changes: 7 additions & 1 deletion public/app/scripts/controllers/settings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('anchrClientApp')
.controller('SettingsCtrl', ['$scope', '$rootScope', 'Auth', 'Snackbar', function ($scope, $rootScope, Auth, Snackbar) {
.controller('SettingsCtrl', ['$scope', '$rootScope', 'Auth', 'Telegram', 'Snackbar', function ($scope, $rootScope, Auth, Telegram, Snackbar) {
$scope.updatePassword = function () {
Auth.updatePassword(
$scope.data.oldPassword,
Expand All @@ -19,6 +19,12 @@ angular.module('anchrClientApp')
)
};

$scope.getOtp = function () {
Telegram.otp.get(null, function(result) {
alert('Your one-time authentication code is: ' + result.otp);
});
}

$scope.deleteAccount = function () {
Auth.deleteAccount(
function () {
Expand Down
20 changes: 20 additions & 0 deletions public/app/scripts/services/telegram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

angular.module('anchrClientApp')
.factory('Telegram', ['$resource', function ($resource) {
return {
otp: $resource('/api/telegram/otp', null, {
get: {
method: 'GET',
headers: { 'Accept': 'text/plain' },
responseType: 'text',
transformResponse: function (data) {
// for some reason, angular keeps converting the string to a json object
// i.e. converts 123456 to { 1: "1", 2: "2", ... }
// this happens event when setting transformResponse to an empty array as suggested at https://docs.angularjs.org/api/ngResource/service/$resource#!
return { otp: data }
}
}
})
};
}]);
5 changes: 5 additions & 0 deletions public/app/views/settings.inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ <h4 class="text-primary">Change Password</h4>
</div>
</form>
</section>
<section id="telegramBotSection">
<h4 class="text-primary">Telegram Bot Integration</h4>
<p>Anchr integrates with Telegram through the official <a href="https://t.me/AnchrBot" target="_blank">@AnchrBot</a>. It allows you to add and shorten links and upload images right from your favorite messaging app. To get started, create a code below and send a message with <code>/start 123456</code> (for example) to the bot.</p>
<button type="button" class="btn btn-primary" ng-click="getOtp()">Generate Code</button>
</section>
<section id="deleteAccountSection">
<h4 class="text-primary">Delete Account</h4>
<p>You can delete your account and all related data stored in Anchr. But be careful as his action is irreversible. If you hit the big, red button below, there is no turning back.</p>
Expand Down

0 comments on commit 63b9657

Please sign in to comment.