2 changed files with 135 additions and 0 deletions
@ -0,0 +1,84 @@ |
|||||
|
package a8k.db; |
||||
|
import com.iflytop.uf.UfActiveRecord; |
||||
|
import com.iflytop.uf.UfActiveRecordField; |
||||
|
import java.util.Map; |
||||
|
public class MdbOption extends UfActiveRecord { |
||||
|
@UfActiveRecordField |
||||
|
public String key; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String value; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String comment; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String editable; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String dataType; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String unit; |
||||
|
|
||||
|
// get table name |
||||
|
public static String getTableName() { |
||||
|
return "app_options"; |
||||
|
} |
||||
|
|
||||
|
// get option |
||||
|
public static String getString(String key, String defaultValue ) { |
||||
|
var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); |
||||
|
if ( null == option ) { |
||||
|
return defaultValue; |
||||
|
} |
||||
|
return option.value; |
||||
|
} |
||||
|
|
||||
|
// get option string |
||||
|
public static String getString( String key ) { |
||||
|
var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); |
||||
|
if ( null == option ) { |
||||
|
throw new RuntimeException("Option not found : " + key); |
||||
|
} |
||||
|
return option.value; |
||||
|
} |
||||
|
|
||||
|
// get option |
||||
|
public static Integer getInteger(String key, Integer defaultValue ) { |
||||
|
var option = MdbOption.getString(key, defaultValue.toString()); |
||||
|
return Integer.parseInt(option); |
||||
|
} |
||||
|
|
||||
|
// get option |
||||
|
public static Integer getInteger( String key ) { |
||||
|
var option = MdbOption.getString(key); |
||||
|
return Integer.parseInt(option); |
||||
|
} |
||||
|
|
||||
|
// get option |
||||
|
public static Double getDouble(String key, Double defaultValue ) { |
||||
|
var option = MdbOption.getString(key, defaultValue.toString()); |
||||
|
return Double.parseDouble(option); |
||||
|
} |
||||
|
|
||||
|
// get option value as double |
||||
|
public static Double getDouble( String key ) { |
||||
|
var option = MdbOption.getString(key); |
||||
|
return Double.parseDouble(option); |
||||
|
} |
||||
|
|
||||
|
// get as boolean |
||||
|
public static Boolean getBoolean( String key, Boolean defaultValue ) { |
||||
|
var option = MdbOption.getString(key, defaultValue ? "1" : "0"); |
||||
|
option = option.toLowerCase(); |
||||
|
return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); |
||||
|
} |
||||
|
|
||||
|
// get option value as boolean |
||||
|
public static Boolean getBoolean( String key ) { |
||||
|
var option = MdbOption.getString(key); |
||||
|
option = option.toLowerCase(); |
||||
|
return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); |
||||
|
} |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
package a8k.db; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.iflytop.uf.UfActiveRecord; |
||||
|
import com.iflytop.uf.UfActiveRecordField; |
||||
|
import org.springframework.util.DigestUtils; |
||||
|
public class MdbUser extends UfActiveRecord { |
||||
|
@UfActiveRecordField |
||||
|
public String account; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
@UfActiveRecordField |
||||
|
public String password; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
@UfActiveRecordField |
||||
|
public String salt; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public Integer isAdmin; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public Integer createdAt; |
||||
|
|
||||
|
@UfActiveRecordField |
||||
|
public String createdBy; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
@UfActiveRecordField |
||||
|
public String accessToken; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
@UfActiveRecordField |
||||
|
public Integer accessTokenExpiredAt; |
||||
|
|
||||
|
// get table name |
||||
|
public static String getTableName() { |
||||
|
return "app_users"; |
||||
|
} |
||||
|
|
||||
|
// check if password matches |
||||
|
public Boolean matchPassword(String password) { |
||||
|
String hash = this.hashPassword(password); |
||||
|
return this.password.equals(hash); |
||||
|
} |
||||
|
|
||||
|
// hash password |
||||
|
public String hashPassword(String password) { |
||||
|
String salt = this.salt; |
||||
|
return DigestUtils.md5DigestAsHex((salt + password + salt).getBytes()); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue