diff --git a/src/routes/dashboard/account-route.js b/src/routes/dashboard/account-route.js
index 831a4ec..d396615 100644
--- a/src/routes/dashboard/account-route.js
+++ b/src/routes/dashboard/account-route.js
@@ -269,39 +269,40 @@ class AccountRoute extends PolymerElement {
@@ -367,22 +368,54 @@ class AccountRoute extends PolymerElement {
}
}
+
+_applyAccount(data){
+ let check = true;
+ this.publicKeyActiveError = "";
+ this.publicKeyOwnerError = "";
+ this.worbliAccountNameError = ""
+ const worbli_account_name = this.worbliAccountName;
+ const public_key_active = this.publicKeyActive;
+ const public_key_owner = this.publicKeyOwner;
+ const nameConfirmed = this._validateAccountName(worbli_account_name);
+ const activeConfirmed = this._validatePublicKey(public_key_active);
+ const ownerConfirmed = this._validatePublicKey(public_key_owner);
+ if(!activeConfirmed){this.publicKeyActiveError = "Wrong public key format. Make sure you are not pasting your private key."; check = false}
+ if(!ownerConfirmed){this.publicKeyOwnerError = "Wrong public key format. Make sure you are not pasting your private key."; check = false}
+ if(!nameConfirmed){this.worbliAccountNameError = "Account name must be between 6 and 12 characters, must start with a letter and can contain only lowercase letters and numbers 1-5."; check = false;}
+ if(check === true){
+ const data = {worbli_account_name, public_key_active, public_key_owner}
+ const token = localStorage.getItem("token");
+ const url = `${this.apiPath}/user/account/`;
+ fetch(url, {
+ method: 'POST',
+ body: JSON.stringify(data),
+ headers:{'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}
+ })
+ .then((response) => {return response.json()})
+ .then((response) => {
+ if(response.data === false){
+ this.worbliAccountNameError = response.error
+ } else {
+ this.complete = true;
+ }
+ })
+ .catch(error => {
+ console.log("response");
+ this.worbliAccountNameError = "Account name is already taken"
+ });
+ }
+}
-_save(data){
- const token = localStorage.getItem("token");
- const url = `${this.apiPath}/user/profile/`;
- fetch(url, {
- method: 'POST',
- body: JSON.stringify(data),
- headers:{'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}
- })
- .then((response) => {return response.json()})
- .then((response) => {
- this.set('route.path', '/dashboard/review/')
- })
- .catch(error => console.log('Error:', error));
+_validateAccountName(name){
+ var re = /^[a-z](?=[a-z1-5]{5,11}$)/;
+ return re.test(name);
}
+_validatePublicKey(key){
+ var re = /^EOS[A-Za-z0-9]{50}$/;
+ return re.test(key);
+}
} window.customElements.define('account-route', AccountRoute);