Created
July 23, 2019 13:54
-
-
Save taowen/b33184cda6105d8e38b6d131b8028957 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const MAX_RETRY_COUNT = 3; | |
@sources.Mysql() | |
export class Account extends Process { | |
public name: string; | |
// plain text, just a demo | |
public password: string; | |
public retryCount: number; | |
public reset: ProcessEndpoint<string, boolean>; | |
public login: ProcessEndpoint<string, boolean>; | |
public process() { | |
let password: string; | |
while (true) { | |
locked: this.commit(); | |
const resetCall = this.recv('reset'); | |
password = resetCall.request; | |
if (this.isPasswordComplex(password)) { | |
this.respond(resetCall, true); | |
break; | |
} | |
this.respond(resetCall, false); | |
} | |
let retryCount = MAX_RETRY_COUNT; | |
for (; retryCount > 0; retryCount -= 1) { | |
normal: this.commit(); | |
const loginAttempt = this.recv('login'); | |
const success = loginAttempt.request === password; | |
this.respond(loginAttempt, success); | |
if (success) { | |
retryCount = MAX_RETRY_COUNT + 1; | |
continue; | |
} | |
} | |
__GOBACK__('locked'); | |
} | |
private isPasswordComplex(password: string) { | |
return password && password.length > 6; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment