ChangeUser.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var Sequence = require('./Sequence');
  2. var Util = require('util');
  3. var Packets = require('../packets');
  4. var Auth = require('../Auth');
  5. module.exports = ChangeUser;
  6. Util.inherits(ChangeUser, Sequence);
  7. function ChangeUser(options, callback) {
  8. Sequence.call(this, options, callback);
  9. this._user = options.user;
  10. this._password = options.password;
  11. this._database = options.database;
  12. this._charsetNumber = options.charsetNumber;
  13. this._currentConfig = options.currentConfig;
  14. }
  15. ChangeUser.prototype.start = function(handshakeInitializationPacket) {
  16. var scrambleBuff = handshakeInitializationPacket.scrambleBuff();
  17. scrambleBuff = Auth.token(this._password, scrambleBuff);
  18. var packet = new Packets.ComChangeUserPacket({
  19. user : this._user,
  20. scrambleBuff : scrambleBuff,
  21. database : this._database,
  22. charsetNumber : this._charsetNumber,
  23. });
  24. this._currentConfig.user = this._user;
  25. this._currentConfig.password = this._password;
  26. this._currentConfig.database = this._database;
  27. this._currentConfig.charsetNumber = this._charsetNumber;
  28. this.emit('packet', packet);
  29. };
  30. ChangeUser.prototype['ErrorPacket'] = function(packet) {
  31. var err = this._packetToError(packet);
  32. err.fatal = true;
  33. this.end(err);
  34. };