use of com.alibaba.dubbo.registry.common.domain.User in project dubbo by alibaba.
the class Infos method update.
public boolean update(Map<String, Object> context) {
User user = new User();
user.setId(currentUser.getId());
user.setUsername(currentUser.getUsername());
user.setOperatorAddress(operatorAddress);
user.setName((String) context.get("name"));
user.setDepartment((String) context.get("department"));
user.setEmail((String) context.get("email"));
user.setPhone((String) context.get("phone"));
user.setAlitalk((String) context.get("alitalk"));
user.setLocale((String) context.get("locale"));
userDAO.modifyUser(user);
context.put("redirect", "../" + getClass().getSimpleName().toLowerCase());
return true;
}
use of com.alibaba.dubbo.registry.common.domain.User in project dubbo by alibaba.
the class Passwds method create.
public boolean create(Map<String, Object> context) {
User user = new User();
user.setOperator(operator);
user.setOperatorAddress(operatorAddress);
user.setPassword((String) context.get("newPassword"));
user.setUsername(operator);
boolean sucess = userDAO.updatePassword(user, (String) context.get("oldPassword"));
if (!sucess)
context.put("message", getMessage("passwd.oldwrong"));
return sucess;
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class Restful method execute.
public void execute(Map<String, Object> context) throws Throwable {
if (context.get(WebConstants.CURRENT_USER_KEY) != null) {
User user = (User) context.get(WebConstants.CURRENT_USER_KEY);
currentUser = user;
operator = user.getUsername();
role = user.getRole();
context.put(WebConstants.CURRENT_USER_KEY, user);
}
operatorAddress = (String) context.get("request.remoteHost");
context.put("operator", operator);
context.put("operatorAddress", operatorAddress);
context.put("currentRegistry", currentRegistry);
String httpMethod = (String) context.get("request.method");
String method = (String) context.get("_method");
String contextPath = (String) context.get("request.contextPath");
context.put("rootContextPath", new RootContextPath(contextPath));
// Analyze Method
if (method == null || method.length() == 0) {
String id = (String) context.get("id");
if (id == null || id.length() == 0) {
method = "index";
} else {
method = "show";
}
}
if ("index".equals(method)) {
if ("post".equalsIgnoreCase(httpMethod)) {
method = "create";
}
} else if ("show".equals(method)) {
if ("put".equalsIgnoreCase(httpMethod) || "post".equalsIgnoreCase(httpMethod)) {
// Instead of submitting a PUT request with a form, use POST instead
method = "update";
} else if ("delete".equalsIgnoreCase(httpMethod)) {
// Instead of submitting a PUT request with a form, use POST instead
method = "delete";
}
}
context.put("_method", method);
try {
Method m = null;
try {
m = getClass().getMethod(method, new Class<?>[] { Map.class });
} catch (NoSuchMethodException e) {
for (Method mtd : getClass().getMethods()) {
if (Modifier.isPublic(mtd.getModifiers()) && mtd.getName().equals(method)) {
m = mtd;
break;
}
}
if (m == null) {
throw e;
}
}
if (m.getParameterTypes().length > 2) {
throw new IllegalStateException("Unsupport restful method " + m);
} else if (m.getParameterTypes().length == 2 && (m.getParameterTypes()[0].equals(Map.class) || !m.getParameterTypes()[1].equals(Map.class))) {
throw new IllegalStateException("Unsupport restful method " + m);
}
Object r;
if (m.getParameterTypes().length == 0) {
r = m.invoke(this, new Object[0]);
} else {
Object value;
Class<?> t = m.getParameterTypes()[0];
if (Map.class.equals(t)) {
value = context;
} else if (isPrimitive(t)) {
String id = (String) context.get("id");
value = convertPrimitive(t, id);
} else if (t.isArray() && isPrimitive(t.getComponentType())) {
String id = (String) context.get("id");
String[] ids = id == null ? new String[0] : id.split("[.+]+");
value = Array.newInstance(t.getComponentType(), ids.length);
for (int i = 0; i < ids.length; i++) {
Array.set(value, i, convertPrimitive(t.getComponentType(), ids[i]));
}
} else {
value = t.newInstance();
for (Method mtd : t.getMethods()) {
if (Modifier.isPublic(mtd.getModifiers()) && mtd.getName().startsWith("set") && mtd.getParameterTypes().length == 1) {
String p = mtd.getName().substring(3, 4).toLowerCase() + mtd.getName().substring(4);
Object v = context.get(p);
if (v == null) {
if ("operator".equals(p)) {
v = operator;
} else if ("operatorAddress".equals(p)) {
v = (String) context.get("request.remoteHost");
}
}
if (v != null) {
try {
mtd.invoke(value, new Object[] { CompatibleTypeUtils.compatibleTypeConvert(v, mtd.getParameterTypes()[0]) });
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
}
}
}
if (m.getParameterTypes().length == 1) {
r = m.invoke(this, new Object[] { value });
} else {
r = m.invoke(this, new Object[] { value, context });
}
}
if (m.getReturnType() == boolean.class || m.getReturnType() == Boolean.class) {
context.put("rundata.layout", "redirect");
context.put("rundata.target", "redirect");
context.put("success", r == null || ((Boolean) r).booleanValue());
if (context.get("redirect") == null) {
context.put("redirect", getDefaultRedirect(context, method));
}
} else if (m.getReturnType() == String.class) {
String redirect = (String) r;
if (redirect == null) {
redirect = getDefaultRedirect(context, method);
}
if (context.get("chain") != null) {
context.put("rundata.layout", "home");
context.put("rundata.target", "home");
} else {
context.put("rundata.redirect", redirect);
}
} else {
context.put("rundata.layout", method);
context.put("rundata.target", context.get("rundata.target") + "/" + method);
}
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
throw ((InvocationTargetException) e).getTargetException();
}
// if (e instanceof InvocationTargetException) {
// e = ((InvocationTargetException) e).getTargetException();
// }
// logger.warn(e.getMessage(), e);
// context.put("rundata.layout", "redirect");
// context.put("rundata.target", "redirect");
// context.put("success", false);
// context.put("exception", e);
// context.put("redirect", getDefaultRedirect(context, method));
}
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class Infos method index.
public void index(Map<String, Object> context) {
User user = userDAO.findById(currentUser.getId());
context.put("user", user);
}
use of com.alibaba.dubbo.registry.common.domain.User in project incubator-dubbo-ops by apache.
the class Passwds method create.
public boolean create(Map<String, Object> context) {
User user = new User();
user.setOperator(operator);
user.setOperatorAddress(operatorAddress);
user.setPassword((String) context.get("newPassword"));
user.setUsername(operator);
boolean sucess = userDAO.updatePassword(user, (String) context.get("oldPassword"));
if (!sucess)
context.put("message", getMessage("passwd.oldwrong"));
return sucess;
}
Aggregations