Author: ygrego Date: 2015-05-18 10:12:08 +0000 (Mon, 18 May 2015) New Revision: 1356 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1356 Log: Initialization of technicals properties and addition of constants in constructor. Implementation of method "setParentalControlPIN" and addition of method "_setIsPINEntryLocked". Modified: oipf/js/impl/ParentalControlManagerObject.js Modified: oipf/js/impl/ParentalControlManagerObject.js =================================================================== --- oipf/js/impl/ParentalControlManagerObject.js 2015-05-18 10:06:39 UTC (rev 1355) +++ oipf/js/impl/ParentalControlManagerObject.js 2015-05-18 10:12:08 UTC (rev 1356) @@ -23,7 +23,7 @@ _currentPIN: null, //Indicate the number of invalid PIN attemps. - _invalidPINAttempts: null, + _invalidPINAttemptsMax: null, //Contain the number of invalid entry PIN attempts. _currentInvalidPINAttempts: null, @@ -36,12 +36,73 @@ * -Yannis 18/05/2015 The properties "_currentPIN" and "_invalidPINAttemps" * don't have to be innitialized here. */ - init : function(){ + init: function() { + this._timerManager = new TimerManager(); + this._timeout = this._timerManager.createTimer.bind(this._timerManager, 0); + this.isPINEntryLocked = false; this._currentPIN = "0000"; - this._invalidPINAttempts = 4; - this._currentPINAttempts = 0; - } + this._invalidPINAttemptsMax = 4; + this._currentInvalidPINAttempts = 0; + this._PINLockedTime = 2000; + + this._PIN_CORRECT = parentalControlManagerConstants.pin.CORRECT; + this._PIN_INCORRECT = parentalControlManagerConstants.pin.INCORRECT; + this._PIN_LOCKED = parentalControlManagerConstants.pin.LOCKED; + }, + + /* + * Description: + * Set the parental control PIN. This operation SHALL be protected by the + * parental control PIN (if PIN entry is enabled). The return value + * indicates the success of the operation, and SHALL take one of the + * following values: + * ------------------------------------------------------------------------ + * Value | Description + * ------ ----------------------------------------------------------------- + * 0 | The PIN is correct. + * ------ ----------------------------------------------------------------- + * 1 | The PIN is incorrect. + * ------ ----------------------------------------------------------------- + * 2 | PIN entry is locked because an invalid PIN has been entered too + * | many times. The number of invalid PIN attempts before PIN entry + * | is locked is outside the scope of this specification. + * ------ ----------------------------------------------------------------- + * + * Arguments: + * - oldPcPIN: The current parental control PIN. + * - newPcPIN: The new value for the parental control PIN. + * + * Return: Integer + */ + setParentalControlPIN: function(oldPcPIN, newPcPIN) { + if (this._currentInvalidPINAttempts < this._invalidPINAttemptsMax) { + + if (this._currentPIN == oldPcPIN) { + + this._currentPIN = newPcPIN; + return this._PIN_CORRECT; + + } else { + + this._currentInvalidPINAttempts++; + return this._PIN_INCORRECT; + } + } + + this.isPINEntryLocked = true; + + //After a periode of time, the PIN entry will be unlocked. + this._timeout(this._PINLockedTime) + .then(this._setIsPINEntryLocked.bind(this, false)); + + return this._PIN_LOCKED; + }, + + _setIsPINEntryLocked: function(enable) { + this.isPINEntryLocked = enable; + this._currentInvalidPINAttempts = 0; + } }); \ No newline at end of file
participants (1)
-
ygregoï¼ users.nuiton.org