Skip to content

Commit

Permalink
logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bkawk committed Nov 24, 2018
1 parent 2c16ad4 commit 1cf6e51
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
19 changes: 11 additions & 8 deletions src/components/side-bar/worbli-dashnav.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import '@polymer/app-route/app-location.js';
import '../../components/worbli-logger.js';
import '../../css/shared-styles.js';
import '../../worbli-env.js';

Expand Down Expand Up @@ -54,6 +55,7 @@ class WorbliDashnav extends PolymerElement {
<app-location route="{{route}}" url-space-regex="^[[rootPath]]"></app-location>
<worbli-env api-path="{{apiPath}}""></worbli-env>
<worbli-logger id="logger"></worbli-logger>
<div class="container">
<template is="dom-if" if="{{default}}">
Expand Down Expand Up @@ -162,15 +164,16 @@ class WorbliDashnav extends PolymerElement {
}

_routeChanged(){
const location = this.route.path.split("/")[1];
this.page = this.route.path.split("/")[2];
if(this.page === 'password' && this.route && this.route.__queryParams && this.route.__queryParams.token){
const token = this.route.__queryParams.token;
localStorage.setItem("token", token);
}
if(location === 'dashboard'){
this.path = this.route.path.split("/")[1];
this.page = this.route.path.split("/")[2];
if(this.page === 'password' && this.route && this.route.__queryParams && this.route.__queryParams.token){
const token = this.route.__queryParams.token;
localStorage.setItem("token", token)
this.$.logger.log('email clicked');
this._auth();
} else if (this.path == 'dashboard'){
this._auth();
}
}
}

_auth(){
Expand Down
6 changes: 5 additions & 1 deletion src/components/worbli-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { updateStyles } from '@polymer/polymer/lib/mixins/element-mixin.js';
import '@polymer/app-route/app-location.js';
import '../css/shared-styles.js';
import '../worbli-env.js';
import './worbli-logger.js';
class WorbliJoin extends PolymerElement {
static get template() {
return html`
Expand Down Expand Up @@ -132,6 +133,7 @@ class WorbliJoin extends PolymerElement {
</style>
<app-location route="{{route}}" url-space-regex="^[[rootPath]]"></app-location>
<worbli-env api-path="{{apiPath}}""></worbli-env>
<worbli-logger id="logger"></worbli-logger>
<template is="dom-if" if="{{!complete}}">
<h2>Join WORBLI</h2>
<p>WORBLI is the place to access smarter financial services</p>
Expand Down Expand Up @@ -192,14 +194,15 @@ _reset(){
setTimeout(() => {
this.complete = false;
this.resetJoin = false;
}, 2000);
}, 500);
}
}

_confirmEmail(){
this.confirmedEmail = this._validateEmail(this.email);
this._buttonActive()
}

_termsCheckbox(){
if(this.termsCheckbox === undefined && this.termsCheckboxValue === undefined){
this.termsCheckboxValue = true
Expand Down Expand Up @@ -230,6 +233,7 @@ _marketingCheckbox(){
_sendEmail(){
if (this.email && this._validateEmail(this.email)){
const email = this.email;
this.$.logger.log('request email', {email});
let agreed_terms = this.termsCheckboxValue;
let agreed_marketing = this.marketingCheckboxValue;
if(agreed_terms === undefined){agreed_terms = false};
Expand Down
57 changes: 57 additions & 0 deletions src/components/worbli-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import '../worbli-env.js';

class WorbliLogger extends PolymerElement {
static get template() {
return html`
<worbli-env api-path="{{apiPath}}""></worbli-env>`;
}
static get properties() {
return {
apiPath: {
type: Text,
},
};
}

log(_action, _data){
if (_action) {
const action = _action;
const data = _data || {};
const created_at = (new Date).getTime();
const browser = this._browser();
const token = localStorage.getItem("token") || '';
this._send({action, data, created_at, browser, token});
}
}

_send(_data){
const data = _data;
const url = `${this.apiPath}/logger/log/`;
fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers:{'Content-Type': 'application/json'}
})
}

_browser(){
var userAgent= navigator.userAgent, tem,
M= userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+)/g.exec(userAgent) || [];
return 'IE '+(tem[1] || '');
}
if(M[1]=== 'Chrome'){
tem= userAgent.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= userAgent.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]);
return M.join(' ');
}




} window.customElements.define('worbli-logger', WorbliLogger);
34 changes: 18 additions & 16 deletions src/routes/dashboard/password-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../../components/side-bar/worbli-snapshot.js';
import '../../components/side-bar/worbli-dashnav.js';
import '@polymer/app-route/app-location.js';
import '../../worbli-env.js';
import '../../components/worbli-logger.js';

class PasswordRoute extends PolymerElement {
static get template() {
Expand Down Expand Up @@ -226,6 +227,7 @@ class PasswordRoute extends PolymerElement {
<app-location route="{{route}}" url-space-regex="^[[rootPath]]"></app-location>
<worbli-env api-path="{{apiPath}}""></worbli-env>
<worbli-logger id="logger"></worbli-logger>
<div class="split">
<div class="side">
<worbli-dashnav></worbli-dashnav>
Expand Down Expand Up @@ -272,24 +274,24 @@ class PasswordRoute extends PolymerElement {



_savePassword(){
this.passwordError = ""
this.passwordTwoError = ""
const password = this.password;
const passwordTwo = this.passwordTwo;
if (password != passwordTwo){
this.passwordTwoError = "Passwords are not the same"
} else if (this._validatePassword()){
this._save({password});
} else {
this.passwordTwoError = "Password must be at least 8 characters long and must include uppercase and lowercase letters and a digit or a special character"
}
_savePassword(){
this.passwordError = ""
this.passwordTwoError = ""
const password = this.password;
const passwordTwo = this.passwordTwo;
if (password != passwordTwo){
this.passwordTwoError = "Passwords are not the same"
} else if (this._validatePassword()){
this._save({password});
} else {
this.passwordTwoError = "Password must be at least 8 characters long and must include uppercase and lowercase letters and a digit or a special character"
}
}

_validatePassword(){
const password = this.password;
var re = /^(?=.*[a-z])(?=.*\d|.*[!@#\$%\^&\*])(?=.*[A-Z])(?:.{8,})$/;
return re.test(password);
_validatePassword(){
const password = this.password;
var re = /^(?=.*[a-z])(?=.*\d|.*[!@#\$%\^&\*])(?=.*[A-Z])(?:.{8,})$/;
return re.test(password);
}

_save(data){
Expand Down

0 comments on commit 1cf6e51

Please sign in to comment.