package mircoders.module;
-import java.util.HashMap;
-import java.util.Map;
-
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.module.AbstractModule;
import mir.module.ModuleExc;
import mir.module.ModuleFailure;
-import mir.storage.StorageObject;
import mir.util.JDBCStringRoutines;
import mircoders.entity.EntityUsers;
import mircoders.global.MirGlobal;
+import mircoders.storage.DatabaseUsers;
+
+import java.util.HashMap;
+import java.util.Map;
/*
{
static LoggerWrapper logger = new LoggerWrapper("Module.Users");
- public ModuleUsers(StorageObject theStorage)
- {
- if (theStorage == null)
- logger.warn("ModuleUsers(): StorageObject was null!");
-
- this.theStorage = theStorage;
+ public ModuleUsers() {
+ super(DatabaseUsers.getInstance());
}
/**
* @param password The password
* @return The authenticated user, or <code>null</code> if the user
* doesn't exist, or the supplied password is invalid.
- * @throws ModuleException
+ * @throws ModuleExc
*/
public EntityUsers getUserForLogin(String user, String password) throws ModuleExc, ModuleFailure {
EntityList userList = getByWhereClause(whereString, -1);
- if (userList != null && userList.getCount() == 1)
- return (EntityUsers) userList.elementAt(0);
- else
- return null;
+ if (userList != null && userList.getCount() == 1) {
+ EntityUsers result = (EntityUsers) userList.elementAt(0);
+
+ if (result.getFieldValue("is_disabled") == null ||
+ result.getFieldValue("is_disabled").equals("0"))
+ return result;
+ }
+
+ return null;
}
catch (Throwable t) {
throw new ModuleFailure(t);
public boolean checkUserPassword(EntityUsers aUser, String aPassword) throws ModuleExc, ModuleFailure {
try {
- return aUser.getValue("password").equals(MirGlobal.localizer().adminInterface().makePasswordDigest(aPassword));
+ return aUser.getFieldValue("password").equals(MirGlobal.localizer().adminInterface().makePasswordDigest(aPassword));
}
catch (Throwable t) {
throw new ModuleFailure(t);
}
}
- private Map digestPassword(Map aValues) throws ModuleExc, ModuleFailure {
+ private Map digestPassword(Map aValues) throws ModuleFailure {
Map result = aValues;
try {
return result;
}
+ /**
+ *
+ * @param theValues
+ * @return
+ * @throws ModuleExc
+ * @throws ModuleFailure
+ */
+
public String add (Map theValues) throws ModuleExc, ModuleFailure {
try {
return super.add(digestPassword(theValues));
}
/**
- * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
- * @param theValues Hash mit Spalte/Wert-Paaren
- * @return Id des eingef?gten Objekts
- * @exception ModuleException
+ *
+ * @param theValues
+ * @return
+ * @throws ModuleExc
+ * @throws ModuleFailure
*/
public String set (Map theValues) throws ModuleExc, ModuleFailure {
try {
throw new ModuleFailure(t);
}
}
+
+ public void recordLogin(EntityUsers aUser) throws ModuleExc, ModuleFailure {
+ try {
+ String sql = "update webdb_users set lastlogin=now() where id = " + aUser.getId();
+
+ storage.executeUpdate(sql);
+ }
+ catch (Throwable t) {
+// no propagation of this error for now, to allow mir to still function
+// with older db schemas
+// throw new ModuleFailure(t);
+ }
+ }
}
\ No newline at end of file