change_user.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var util = require('util');
  2. var Command = require('./command.js');
  3. var Packets = require('../packets/index.js');
  4. var ClientConstants = require('../constants/client.js');
  5. function ChangeUser(options, callback)
  6. {
  7. this.onResult = callback;
  8. this._user = options.user;
  9. this._password = options.password;
  10. this._database = options.database;
  11. this._passwordSha1 = options.passwordSha1;
  12. this._charsetNumber = options.charsetNumber;
  13. this._currentConfig = options.currentConfig;
  14. Command.call(this);
  15. }
  16. util.inherits(ChangeUser, Command);
  17. ChangeUser.prototype.start = function(packet, connection) {
  18. var packet = new Packets.ChangeUser({
  19. user : this._user,
  20. database : this._database,
  21. charsetNumber : this._charsetNumber,
  22. password : this._password,
  23. passwordSha1 : this._passwordSha1,
  24. authPluginData1 : connection._handshakePacket.authPluginData1,
  25. authPluginData2 : connection._handshakePacket.authPluginData2
  26. });
  27. this._currentConfig.user = this._user;
  28. this._currentConfig.password = this._password;
  29. this._currentConfig.database = this._database;
  30. this._currentConfig.charsetNumber = this._charsetNumber;
  31. // reset prepared statements cache as all statements become invalid after changeUser
  32. connection._statements = {};
  33. connection.writePacket(packet.toPacket());
  34. return ChangeUser.prototype.changeOk;
  35. };
  36. ChangeUser.prototype.changeOk = function(okPacket, connection) {
  37. if (this.onResult)
  38. this.onResult(null);
  39. return null;
  40. };
  41. module.exports = ChangeUser;