Commit cb33404f authored by 郭晓俊's avatar 郭晓俊

Merge branch 'GJYZJ_V1.0' of

http://gitlab.archser.com/common/aserver.git into GJYZJ_V1.0 Conflicts: src/main/resources/DBUpdate/DM_UpdateSQL.xml
parents 216d4228 3d672676
This diff is collapsed.
package com.archser.aserver.controller; package com.archser.aserver.controller;
import java.util.ArrayList; import java.sql.SQLException;
import java.util.List; import java.util.ArrayList;
import javax.inject.Inject; import java.util.HashMap;
import com.archser.aserver.model.User; import java.util.Iterator;
import com.archser.aserver.service.UserService; import java.util.List;
import com.jfinal.core.Controller; import java.util.Map;
import com.jfinal.kit.HashKit; import java.util.Map.Entry;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret; import javax.inject.Inject;
import com.jfinal.plugin.activerecord.Db; import com.archser.aserver.model.User;
import com.jfinal.plugin.activerecord.Record; import com.archser.aserver.service.UserService;
import com.jfinal.core.Controller;
/** import com.jfinal.kit.HashKit;
* 用户相关操作 import com.jfinal.kit.Kv;
* import com.jfinal.kit.Ret;
* @author dgq import com.jfinal.plugin.activerecord.Db;
* import com.jfinal.plugin.activerecord.Record;
*/ import com.jfinal.plugin.redis.Redis;
public class UserController extends Controller {
/**
@Inject * 用户相关操作
UserService userService; *
/** * @author dgq
* 获取用户信息 *
*/ */
public void info() { public class UserController extends Controller {
String username = this.getAttr("username");
User user = User.dao.template("getUser", username).findFirst(); @Inject
user.remove("password"); UserService userService;
this.renderJson(Ret.ok("userInfo", user)); private static final String _INFO = "_INFO";
}
/** /**
* 修改用户密码 * 获取用户信息
*/ */
@SuppressWarnings("unused") public void info() {
public void updatePwd() { String username = this.getAttr("username");
String username = this.getAttr("username"); User user = User.dao.template("getUser", username).findFirst();
String password = this.getPara("newPwd"); user.remove("password");
password = HashKit.sha256(password); this.renderJson(Ret.ok("userInfo", user));
int flag = Db.update(Db.getSql("updatePassword"), password, username); }
if (flag == 0) {
this.renderJson(Ret.fail("msg","修改失败")); /**
} * 修改用户密码
this.renderJson(Ret.ok("msg","修改成功")); * @throws SQLException
} */
public void updatePwd() {
/** String username = this.getAttr("username");
* 修改用户 String password = this.getPara("newPwd");
*/ password = HashKit.sha256(password);
public void updateUser() { int flag = Db.update(Db.getSql("updatePassword"), password, username);
User user = this.getModel(User.class, "user", true); if (flag == 0) {
if (user == null) { this.renderJson(Ret.fail("msg","修改失败"));
renderJson("msg", "数据参数错误,请重新修改"); return ;
return; }
} try {
boolean flag = user.update(); Redis.use().hset(username+ _INFO, "password", password);
if (flag) { }catch (Exception e) {
renderJson(Ret.ok("msg", "数据修改成功!")); e.printStackTrace();
return; }
} else { this.renderJson(Ret.ok("msg","修改成功"));
renderJson(Ret.fail("msg", "Error ! 请联系管理员解决。")); }
}
} /**
* 修改用户
/** */
* 查询角色 public void updateUser() {
*/ User user = this.getModel(User.class, "user", true);
@SuppressWarnings("unused") if (user == null) {
public void getRoleData() { renderJson("msg", "数据参数错误,请重新修改");
String username = this.getAttr("username"); return;
User user = User.dao.template("getUser", username).findFirst(); }
int userId = user.getId(); boolean flag = user.update();
List<Record> records = Db.find(Db.getSql("getRolesByUserId"), userId); if (flag) {
List<Integer> ids = new ArrayList<Integer>(); updateUserForRedis(user);
for (Record record : records) { renderJson(Ret.ok("msg", "数据修改成功!"));
ids.add(record.getInt("ROLE_ID")); return;
} } else {
List<Record> dataList = Db.find(Db.getSqlPara("getRole",Kv.by("ids", ids))); renderJson(Ret.fail("msg", "Error ! 请联系管理员解决。"));
if (dataList != null) { }
this.renderJson(Ret.ok("list", dataList)); }
} else {
this.renderJson(Ret.fail("msg", "未找到数据")); /**
} * 修改Redis中的用户信息
} *@Time:2020年7月10日 - 上午8:48:48
* @author:李德才
/** * @param: @param user
* 验证原密码输入的是否正确 * @return: void
*/ * @throws
public void validateOldPassword() { */
String username = this.getAttr("username"); public void updateUserForRedis(User user) {
User user = User.dao.template("getUser", username).findFirst(); try {
String oldPwd = getPara("oldPwd"); Iterator<Entry<String, Object>> userIterator = user._getAttrsEntrySet().iterator();
String encryptionString = HashKit.sha256(oldPwd); Map<Object, Object> userMap = new HashMap<>();
if (encryptionString.equals(user.getPassword())) { Entry<String, Object> userAttr = null;
renderJson(Ret.ok()); while (userIterator.hasNext()) {
} else { userAttr = userIterator.next();
renderJson(Ret.fail()); userMap.put(userAttr.getKey().toString().trim().toLowerCase(), userAttr.getValue());
} }
} Redis.use().hmset(user.getUsername() + _INFO, userMap);
} catch (Exception e) {
} e.printStackTrace();
}
}
/**
* 查询角色
*/
public void getRoleData() {
String username = this.getAttr("username");
User user = User.dao.template("getUser", username).findFirst();
int userId = user.getId();
List<Record> records = Db.find(Db.getSql("getRolesByUserId"), userId);
List<Integer> ids = new ArrayList<Integer>();
for (Record record : records) {
ids.add(record.getInt("ROLE_ID"));
}
List<Record> dataList = Db.find(Db.getSqlPara("getRole",Kv.by("ids", ids)));
if (dataList != null) {
this.renderJson(Ret.ok("list", dataList));
} else {
this.renderJson(Ret.fail("msg", "未找到数据"));
}
}
/**
* 验证原密码输入的是否正确
*/
public void validateOldPassword() {
String username = this.getAttr("username");
User user = User.dao.template("getUser", username).findFirst();
String oldPwd = getPara("oldPwd");
String encryptionString = HashKit.sha256(oldPwd);
if (encryptionString.equals(user.getPassword())) {
renderJson(Ret.ok());
} else {
renderJson(Ret.fail());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment