|
@@ -21,47 +21,99 @@
|
|
|
*/
|
|
|
|
|
|
|
|
|
-import {IHelpDeskService, IRandomPasswordResponse} from '../services/helpdesk.service';
|
|
|
+import {IHelpDeskService, IRandomPasswordResponse, ISuccessResponse} from '../services/helpdesk.service';
|
|
|
import {IPromise, IQService} from 'angular';
|
|
|
+import {IHelpDeskConfigService, PASSWORD_UI_MODES} from '../services/helpdesk-config.service';
|
|
|
+import DialogService from '../ux/ias-dialog.service';
|
|
|
|
|
|
-let RANDOM_MAPPING_LENGTH = 20;
|
|
|
+const RANDOM_MAPPING_SIZE = 20;
|
|
|
+const STATUS_AUTOGEN = 'autogen';
|
|
|
+const STATUS_CONFIRM_RANDOM = 'confirm-random';
|
|
|
+const STATUS_FINISHED = 'finished';
|
|
|
+const STATUS_TYPE = 'type';
|
|
|
|
|
|
require('helpdesk/password-suggestions-dialog.scss');
|
|
|
|
|
|
export default class PasswordSuggestionsDialogController {
|
|
|
+ chosenPassword: string;
|
|
|
+ clearResponsesSetting: string;
|
|
|
fetchingRandoms: boolean;
|
|
|
+ maskPasswords: boolean;
|
|
|
+ passwordMasked: boolean;
|
|
|
passwordSuggestions: string[];
|
|
|
+ passwordUiMode: string;
|
|
|
+ status: string;
|
|
|
+ successMessage: string;
|
|
|
+ // this.HelpDeskService.showStrengthMeter;
|
|
|
|
|
|
- static $inject = [ '$q', 'HelpDeskService', 'personUserKey' ];
|
|
|
- constructor(private $q: IQService, private HelpDeskService: IHelpDeskService, private personUserKey: string) {
|
|
|
+ static $inject = [
|
|
|
+ '$q',
|
|
|
+ 'ConfigService',
|
|
|
+ 'HelpDeskService',
|
|
|
+ 'IasDialogService',
|
|
|
+ 'personUsername',
|
|
|
+ 'personUserKey',
|
|
|
+ 'translateFilter'
|
|
|
+ ];
|
|
|
+ constructor(private $q: IQService,
|
|
|
+ private configService: IHelpDeskConfigService,
|
|
|
+ private HelpDeskService: IHelpDeskService,
|
|
|
+ private IasDialogService: DialogService,
|
|
|
+ private personUsername: string,
|
|
|
+ private personUserKey: string,
|
|
|
+ private translateFilter: (id: string) => string) {
|
|
|
this.passwordSuggestions = Array(20).fill('');
|
|
|
- this.fetchRandoms();
|
|
|
+
|
|
|
+ let promise = this.$q.all([
|
|
|
+ this.configService.getClearResponsesSetting(),
|
|
|
+ this.configService.getPasswordUiMode(),
|
|
|
+ this.configService.maskPasswordsEnabled()
|
|
|
+ ]);
|
|
|
+ promise.then((result) => {
|
|
|
+ this.clearResponsesSetting = result[0];
|
|
|
+ this.passwordUiMode = result[1];
|
|
|
+ this.maskPasswords = result[2];
|
|
|
+ this.passwordMasked = this.maskPasswords; // Set now instead of when we set status to STATUS_FINISHED
|
|
|
+ if (this.passwordUiMode === PASSWORD_UI_MODES.AUTOGEN) {
|
|
|
+ this.status = STATUS_AUTOGEN;
|
|
|
+ this.populatePasswordSuggestions();
|
|
|
+ }
|
|
|
+ else if (this.passwordUiMode === PASSWORD_UI_MODES.RANDOM) {
|
|
|
+ this.status = STATUS_CONFIRM_RANDOM;
|
|
|
+ }
|
|
|
+ else if (this.passwordUiMode === PASSWORD_UI_MODES.BOTH || this.passwordUiMode === PASSWORD_UI_MODES.TYPE) {
|
|
|
+ this.status = STATUS_TYPE;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new Error('Password type unsupported!'); // TODO: best way to do this?
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- onChoosePassword(index: number) {
|
|
|
- let password = this.passwordSuggestions[index];
|
|
|
- // change password
|
|
|
+ chooseTypedPassword() { // todo: should this be merged with onChoosePasswordSuggestion?
|
|
|
+ this.HelpDeskService.setPassword(this.personUserKey, false, this.chosenPassword)
|
|
|
+ .then((result: ISuccessResponse) => {
|
|
|
+ this.status = STATUS_FINISHED;
|
|
|
+ this.successMessage = result.successMessage;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- onMoreRandomsButtonClick() {
|
|
|
- this.fetchRandoms();
|
|
|
+ clearAnswers() {
|
|
|
+ this.IasDialogService.close();
|
|
|
}
|
|
|
|
|
|
- fetchRandoms() {
|
|
|
- this.fetchingRandoms = true;
|
|
|
- let ordering = this.generateRandomMapping();
|
|
|
- let promiseChain: IPromise<any> = this.$q.when();
|
|
|
- ordering.forEach((index: number) => {
|
|
|
- promiseChain = promiseChain.then(this.passwordSuggestionFactory(index));
|
|
|
- });
|
|
|
- promiseChain.then(() => {
|
|
|
- this.fetchingRandoms = false;
|
|
|
- });
|
|
|
+ confirmSetRandomPassword() {
|
|
|
+ this.HelpDeskService.setPassword(this.personUserKey, true)
|
|
|
+ .then((result: ISuccessResponse) => {
|
|
|
+ this.chosenPassword = '[' + this.translateFilter('Display_Random') + ']';
|
|
|
+ this.status = STATUS_FINISHED;
|
|
|
+ this.successMessage = result.successMessage;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
generateRandomMapping(): number[] {
|
|
|
let map: number[] = [];
|
|
|
- for (let i = 0; i < RANDOM_MAPPING_LENGTH; i++) {
|
|
|
+ for (let i = 0; i < RANDOM_MAPPING_SIZE; i++) {
|
|
|
map.push(i);
|
|
|
}
|
|
|
let randomComparatorFunction = () => 0.5 - Math.random();
|
|
@@ -70,6 +122,15 @@ export default class PasswordSuggestionsDialogController {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ onChoosePasswordSuggestion(index: number) {
|
|
|
+ this.chosenPassword = this.passwordSuggestions[index];
|
|
|
+ this.HelpDeskService.setPassword(this.personUserKey, false, this.chosenPassword)
|
|
|
+ .then((result: ISuccessResponse) => {
|
|
|
+ this.status = STATUS_FINISHED;
|
|
|
+ this.successMessage = result.successMessage;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
passwordSuggestionFactory(index: number): any {
|
|
|
return () => {
|
|
|
return this.HelpDeskService.getRandomPassword(this.personUserKey).then(
|
|
@@ -79,4 +140,20 @@ export default class PasswordSuggestionsDialogController {
|
|
|
);
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ populatePasswordSuggestions() {
|
|
|
+ this.fetchingRandoms = true;
|
|
|
+ let ordering = this.generateRandomMapping();
|
|
|
+ let promiseChain: IPromise<any> = this.$q.when();
|
|
|
+ ordering.forEach((index: number) => {
|
|
|
+ promiseChain = promiseChain.then(this.passwordSuggestionFactory(index));
|
|
|
+ });
|
|
|
+ promiseChain.then(() => {
|
|
|
+ this.fetchingRandoms = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ togglePasswordMasked() {
|
|
|
+ this.passwordMasked = !this.passwordMasked;
|
|
|
+ }
|
|
|
}
|