| 1 package com.quikj.application.web.talk.plugin; 2 3 import com.quikj.server.framework.*; 4 import com.quikj.server.web.*; 5 import com.quikj.application.web.talk.messaging.*; 6 7 import java.sql.*; 8 9 public class DbChangeUserPassword implements DbOperationInterface 10 { 11 public DbChangeUserPassword(String username, String old_password, 12 String new_password, EndPointInterface endpoint, 13 ServiceController parent, AceSQL database, 14 int request_id, Object user_parm) 15 { 16 userName = username; 17 oldPassword = old_password; 18 newPassword = new_password; 19 this.endpoint = endpoint; 20 this.parent = parent; 21 this.database = database; 22 requestId = request_id; 23 userParm = user_parm; 24 } 25 26 public boolean initiate() 27 { 28 try 29 { 30 Statement statement = UserTable.getChangePasswordStatement(database.getConnection(), 31 userName, oldPassword, newPassword); 32 33 operationId = database.executeSQL(statement, 34 (String []) null, 35 this); 36 37 if (operationId == -1) 38 { 39 lastError = parent.getErrorMessage(); 40 return false; 41 } 42 43 return true; 44 } 45 catch (SQLException ex) 46 { 47 lastError = "Error creating SQL statement : " + ex.getMessage(); 48 return false; 49 } 50 } 51 52 public boolean processResponse(AceSQLMessage message) { 54 if (message.getStatus() == AceSQLMessage.SQL_ERROR) 55 { 56 AceLogger.Instance().log(AceLogger.ERROR, 57 AceLogger.SYSTEM_LOG, 58 parent.getName() 59 + "- DbChangeUserPassword.processResponse() -- Database error result."); 60 61 if (sendResponse(AceHTTPMessage.INTERNAL_ERROR, 62 java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.plugin.language", ServiceController.getLocale(endpoint.getParam("language"))).getString("Database_error"), 63 new ChangePasswordResponseMessage()) == false) 64 { 65 AceLogger.Instance().log(AceLogger.ERROR, 67 AceLogger.SYSTEM_LOG, 68 parent.getName() 69 + "- DbChangeUserPassword.processResponse() -- Could not send response message to the endpoint " 70 + endpoint); 71 } 72 73 return true; 74 } 75 76 if (message.getAffectedRows() != 1) 77 { 78 if (sendResponse(AceHTTPMessage.NOT_MODIFIED, 79 java.util.ResourceBundle.getBundle("com.quikj.application.web.talk.plugin.language", ServiceController.getLocale(endpoint.getParam("language"))).getString("Password_not_modified"), new ChangePasswordResponseMessage()) == false) 80 { 81 AceLogger.Instance().log(AceLogger.ERROR, 83 AceLogger.SYSTEM_LOG, 84 parent.getName() 85 + "- DbChangeUserPassword.processResponse() -- Could not send response message to the endpoint " 86 + endpoint); 87 } 88 89 return true; 90 } 91 92 AceLogger.Instance().log(AceLogger.INFORMATIONAL, 93 AceLogger.USER_LOG, 94 parent.getName() 95 + "- Password changed for user " 96 + userName); 97 98 if (sendResponse(AceHTTPMessage.OK, "OK", 99 new ChangePasswordResponseMessage()) == false) 100 { 101 AceLogger.Instance().log(AceLogger.ERROR, 103 AceLogger.SYSTEM_LOG, 104 parent.getName() 105 + "- DbChangeUserPassword.processResponse() -- Could not send response message to the endpoint " 106 + endpoint); 107 } 108 109 return true; 110 } 111 112 public boolean sendResponse(int response_status, String reason, 113 TalkMessageInterface message) 114 { 115 if (endpoint.sendEvent(new MessageEvent(MessageEvent.CLIENT_RESPONSE_MESSAGE, 116 null, 117 response_status, 118 reason, 119 message, 120 userParm, 121 requestId)) == false) 122 { 123 return false; 124 } 125 126 return true; 127 } 128 129 public void cancel() 130 { 131 database.cancelSQL(operationId, parent); 132 } 133 134 public String getLastError() 135 { 136 return lastError; 137 } 138 139 public EndPointInterface getEndPoint() 140 { 141 return endpoint; 142 } 143 144 private String userName; 145 private String oldPassword; 146 private String newPassword; 147 148 private EndPointInterface endpoint; 149 private ServiceController parent; 150 private AceSQL database; 151 private int requestId; 152 private Object userParm; 153 154 private int operationId; 155 156 private String lastError = ""; 157 158 } 159 160 | Popular Tags |