restructuring, working on password reset email
next steps: - create reset url and add it to the translation fill map - implement message translation - implement otp validation and login
This commit is contained in:
@@ -36,6 +36,7 @@ public class Constants {
|
||||
public static final String MIME = "mime";
|
||||
public static final String NUMBER = "number";
|
||||
public static final String OPTIONAL = "optional";
|
||||
public static final String PASS = "pass";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String POST = "POST";
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.allSet;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
public class EmailAddress {
|
||||
private final String email;
|
||||
|
||||
public EmailAddress(String addr){
|
||||
var parts = addr.split("@");
|
||||
if (parts.length != 2 || !allSet(parts[0],parts[1])) throw new IllegalArgumentException(format("{0} is not a valid email address!",addr));
|
||||
email = addr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.UmbrellaException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* © SRSoftware 2025 */
|
||||
public class UmbrellaUser implements Mappable {
|
||||
|
||||
private final long id;
|
||||
private final String theme, name, lang;
|
||||
private final EmailAddress email;
|
||||
|
||||
public UmbrellaUser(long id, String name, EmailAddress email, String theme, String languageCode) {
|
||||
this.email = email;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.theme = theme;
|
||||
this.lang = languageCode;
|
||||
}
|
||||
|
||||
|
||||
public EmailAddress email(){
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof UmbrellaUser user)) return false;
|
||||
return Objects.equals(email, user.email)
|
||||
&& Objects.equals(name, user.name)
|
||||
&& Objects.equals(id, user.id)
|
||||
&& Objects.equals(lang, user.lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(email, id, lang, name);
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public String language(){
|
||||
return lang;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return name;
|
||||
}
|
||||
|
||||
public static UmbrellaUser of(JSONObject json) throws UmbrellaException {
|
||||
if (json.has(USER)) json = json.getJSONObject(USER);
|
||||
if (!json.has(ID)) throw new UmbrellaException(HTTP_BAD_REQUEST,ERROR_MISSING_FIELD,ID);
|
||||
var id = json.getLong(ID);
|
||||
var name = json.has(NAME) ? json.getString(NAME) : null;
|
||||
var email = json.has(EMAIL) ? new EmailAddress(json.getString(EMAIL)) : null;
|
||||
var theme = json.has(THEME) ? json.getString(THEME) : null;
|
||||
var lang = json.has(LANGUAGE) ? json.getString(LANGUAGE) : null;
|
||||
return new UmbrellaUser(id, name, email, theme, lang);
|
||||
}
|
||||
|
||||
public String theme(){
|
||||
return theme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> toMap() {
|
||||
var map = new HashMap<String,Object>();
|
||||
map.put(ID,id);
|
||||
map.put(LOGIN, name()); // this is still used by old umbrella modules
|
||||
map.put(NAME, name());
|
||||
map.put(EMAIL,email().toString());
|
||||
map.put(THEME,theme);
|
||||
map.put(LANGUAGE,lang);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user