<commit_before>#!/usr/bin/env node

(function(){

var cmd     = require('commander');
var request = require('request');
var fs      = require('fs');

// this is a hack ... find better way
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

cmd
  .option('--register <email>', 'Register an account')
  .option('--verify <token>', 'Verify an account')
  .option('--forgot <email>', 'Reset the pwd of an account')
  .option('--login <email> ', 'login to an account')
  .option('--logout <token>', 'logout of an account')
  .option('--update <email>', 'Change the pwd of an account')
  .option('--password <password>', 'password for account')
  .option('--newPassword <newPassword>', 'password for account')
  .option('--token <token>', 'x-access-token')
  .parse(process.argv);

function query(name, headers, body, callback) {
  request({
    uri: 'https://1172.16.58.3:8081/api/subscriber/' + name,
    method: 'POST',
    headers: headers,
    rejectUnauthorized : false,
    json: body
  }, callback);
}

function register(email, password) {
  query('register', {}, {
    email: email,
    password: password
  }, function(err, res, body) {
    if(err) {
      console.log('client cant connect to back');
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function verify(token) {
  query('verify', {}, {
    token: token
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function forgot(email) {
  query('forgot', {}, {
    email: email
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function login(email, password) {
  query('login', {}, {
    email: email,
    password: password
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function logout(token) {
  query('logout', {
    'x-access-token': token
  }, {}, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function update(email, token, password, newPassword) {
  query('update', {
      'x-access-token': token
  }, {
    email: email,
    oldPassword: password,
    newPassword: <PASSWORD>Password
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

if(cmd.register && cmd.password) {
  register(cmd.register, cmd.password);
} else if(cmd.verify) {
  verify(cmd.verify);
} else if(cmd.forgot) {
  forgot(cmd.forgot);
} else if(cmd.login && cmd.password) {
  login(cmd.login, cmd.password);
} else if(cmd.logout) {
  logout(cmd.logout);
} else if(cmd.update && cmd.token && cmd.password && cmd.newPassword) {
  update(cmd.update, cmd.token, cmd.password, cmd.newPassword);<commit_msg>add reset to client<commit_after>#!/usr/bin/env node

(function(){

var cmd     = require('commander');
var request = require('request');
var fs      = require('fs');

// this is a hack ... find better way
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

cmd
  .option('--register <email>', 'Register an account')
  .option('--verify <token>', 'Verify an account')
  .option('--forgot <email>', 'Reset the pwd of an account')
  .option('--reset <token>', 'Update forgotten password')
  .option('--login <email> ', 'login to an account')
  .option('--logout <token>', 'logout of an account')
  .option('--update <email>', 'Change the pwd of an account')
  .option('--password <password>', '<PASSWORD>')
  .option('--newPassword <newPassword>', '<PASSWORD> account')
  .option('--token <token>', 'x-access-token')
  .parse(process.argv);

function query(name, headers, body, callback) {
  request({
    uri: 'https://127.0.0.1:8081/api/subscriber/' + name,
    method: 'POST',
    headers: headers,
    rejectUnauthorized : false,
    json: body
  }, callback);
}

function register(email, password) {
  query('register', {}, {
    email: email,
    password: password
  }, function(err, res, body) {
    if(err) {
      console.log('client cant connect to back');
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function verify(token) {
  query('verify', {}, {
    token: token
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function forgot(email) {
  query('forgot', {}, {
    email: email
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function reset(token, password) {
  query('reset', {}, {
    token: token,
    password: password
  }, function(err, res, body){
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function login(email, password) {
  query('login', {}, {
    email: email,
    password: password
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function logout(token) {
  query('logout', {
    'x-access-token': token
  }, {}, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

function update(email, token, password, newPassword) {
  query('update', {
      'x-access-token': token
  }, {
    email: email,
    oldPassword: password,
    newPassword: <PASSWORD>
  }, function(err, res, body) {
    if(err) {
      console.log(err);
    } else {
      console.log(body);
    }
  });
}

if(cmd.register && cmd.password) {
  register(cmd.register, cmd.password);
} else if(cmd.verify) {
  verify(cmd.verify);
} else if(cmd.forgot) {
  forgot(cmd.forgot);
} else if(cmd.reset && cmd.password) {
  reset(cmd.reset, cmd.password);
} else if(cmd.login && cmd.password) {
  login(cmd.login, cmd.password);
} else if(cmd.logout) {
  logout(cmd.logout);
} else if(cmd.update && cmd.token && cmd.password && cmd.newPassword) {
  update(cmd.update, cmd.token, cmd.password, cmd.newPassword);
{'fraction_non_alphanumeric': 0.18637274549098196, 'fraction_numerical': 0.004175016700066801, 'mean_word_length': 2.9953302201467644, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '744967', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2074, 'n_words': 446}