Search in sources :

Example 6 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class AuthKit method getCrypt.

/**
 * 获取特征加密字符串
 * @param p
 * @return
 * @throws HongsException
 */
public static String getCrypt(String p) throws HongsException {
    try {
        MessageDigest m = MessageDigest.getInstance("MD5");
        byte[] a = m.digest(p.getBytes());
        byte[] b = new byte[a.length * 2];
        for (int i = 0, j = 0; i < a.length; i++) {
            byte c = a[i];
            b[j++] = PAZZ[c >>> 4 & 15];
            b[j++] = PAZZ[c & 15];
        }
        return new String(b);
    } catch (NoSuchAlgorithmException ex) {
        throw new HongsException(ex);
    }
}
Also used : HongsException(io.github.ihongs.HongsException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 7 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class QQAction method inWeb.

/**
 * QQ Web 登录回调
 * @param helper
 * @throws HongsException
 */
@Action("web/create")
@CommitSuccess
public void inWeb(ActionHelper helper) throws HongsException {
    CoreConfig cc = CoreConfig.getInstance("oauth2");
    String appId = cc.getProperty("oauth2.qq.web.app.id");
    String appSk = cc.getProperty("oauth2.qq.web.app.key");
    String rurl = cc.getProperty("oauth2.qq.wap.bak.url");
    String code = helper.getParameter("code");
    if (appId == null || appSk == null) {
        helper.error(400, "Not support this mode");
    }
    try {
        Map info = getUserInfo(code, appId, appSk, rurl, false);
        String opnId = (String) info.get("opnid");
        String opuId = (String) info.get("opuid");
        String name = (String) info.get("name");
        String head = (String) info.get("head");
        Map back = AuthKit.openSign(helper, "qq", Synt.defoult(opuId, opnId), name, head);
        // 登记 openId
        if (opnId != null && opuId != null) {
            String usrId = (String) back.get(Cnst.UID_SES);
            setUserSign("qq.web", opnId, usrId);
        }
        AuthKit.redirect(helper, back);
    } catch (HongsException ex) {
        AuthKit.redirect(helper, ex);
    }
}
Also used : CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess)

Example 8 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class QQAction method inWap.

/**
 * QQ WAP 登录回调
 * @param helper
 * @throws HongsException
 */
@Action("wap/create")
@CommitSuccess
public void inWap(ActionHelper helper) throws HongsException {
    CoreConfig cc = CoreConfig.getInstance("oauth2");
    String appId = cc.getProperty("oauth2.qq.wap.app.id");
    String appSk = cc.getProperty("oauth2.qq.wap.app.key");
    String rurl = cc.getProperty("oauth2.qq.wap.bak.url");
    String code = helper.getParameter("code");
    if (appId == null || appSk == null) {
        helper.error(400, "Not support this mode");
    }
    try {
        Map info = getUserInfo(code, appId, appSk, rurl, true);
        String opnId = (String) info.get("opnid");
        String opuId = (String) info.get("opuid");
        String name = (String) info.get("name");
        String head = (String) info.get("head");
        Map back = AuthKit.openSign(helper, "qq", Synt.defoult(opuId, opnId), name, head);
        // 登记 openId
        if (opnId != null && opuId != null) {
            String usrId = (String) back.get(Cnst.UID_SES);
            setUserSign("qq.wap", opnId, usrId);
        }
        AuthKit.redirect(helper, back);
    } catch (HongsException ex) {
        AuthKit.redirect(helper, ex);
    }
}
Also used : CoreConfig(io.github.ihongs.CoreConfig) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess)

Example 9 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class MineAction method mineSave.

@Action("save")
@Preset(conf = "master", form = "mine")
@Verify(conf = "master", form = "mine", type = 1, trim = 1)
@CommitSuccess
public void mineSave(ActionHelper ah) throws HongsException {
    Object id = ah.getSessibute(Cnst.UID_SES);
    if (id == null || "".equals(id)) {
        throw new HongsException(401, "");
    }
    Map rd = ah.getRequestData();
    rd.put("id", id);
    // 禁止危险修改, 其实校验已经做过限制了. 这是以防万一
    rd.remove("depts");
    rd.remove("roles");
    rd.remove("state");
    // 验证原始密码
    Table ut = DB.getInstance("master").getTable("user");
    String pw = (String) rd.get("password");
    String po = (String) rd.get("passolde");
    if (pw != null && !"".equals(pw)) {
        Map xd = new HashMap();
        Map ed = new HashMap();
        xd.put("ok", false);
        xd.put("errs", ed);
        xd.put("msg", CoreLocale.getInstance().translate("fore.form.invalid"));
        if (po != null && !"".equals(po)) {
            Map row = ut.fetchCase().filter("id = ?", id).select("password , passcode").getOne();
            String ps = (String) row.get("password");
            String pc = (String) row.get("passcode");
            if (pc != null)
                po += pc;
            po = AuthKit.getCrypt(po);
            if (!po.equals(ps)) {
                ed.put("passolde", "旧密码不正确");
                ah.reply(xd);
                return;
            }
        } else {
            ed.put("passolde", "请填写旧密码");
            ah.reply(xd);
            return;
        }
    }
    // 附加验证标识, 当要验证的字段值改变时, 重设为未验证
    Map<String, Object> fs = ut.getFields();
    Map<String, Object> fz = new HashMap();
    for (String fn : fs.keySet()) {
        String fx;
        if (fn.endsWith("_checked")) {
            fx = fn.substring(0, fn.length() - 8);
            if (fs.containsKey(fx) && rd.containsKey(fx)) {
                fz.put(fx, rd.get(fx));
            }
        }
    }
    if (!fz.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (String fn : fz.keySet()) {
            sb.append(",`").append(fn).append("`");
        }
        Map ud = ut.fetchCase().filter("`id` = ?", id).select(sb.substring(1)).getOne();
        for (Map.Entry<String, Object> et : fz.entrySet()) {
            String fn = et.getKey();
            Object fv = et.getValue();
            Object fo = ud.get(fn);
            if (fv == null || fv.equals("") || !fv.equals(fo)) {
                rd.put(et.getKey() + "_checked", "0");
            }
        }
    }
    UserAction ua = new UserAction();
    ua.doSave(ah);
}
Also used : UserAction(io.github.ihongs.serv.master.UserAction) Table(io.github.ihongs.db.Table) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) UserAction(io.github.ihongs.serv.master.UserAction) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess) Preset(io.github.ihongs.action.anno.Preset) Verify(io.github.ihongs.action.anno.Verify)

Example 10 with HongsException

use of io.github.ihongs.HongsException in project HongsCORE by ihongs.

the class MineAction method mineInfo.

@Action("info")
@Preset(conf = "master", form = "mine")
public void mineInfo(ActionHelper ah) throws HongsException {
    Object id = ah.getSessibute(Cnst.UID_SES);
    if (id == null || "".equals(id)) {
        throw new HongsException(401, "");
    }
    UserAction ua = new UserAction();
    Map rd = ah.getRequestData();
    rd.put("id", id);
    ua.getInfo(ah);
}
Also used : UserAction(io.github.ihongs.serv.master.UserAction) HongsException(io.github.ihongs.HongsException) HashMap(java.util.HashMap) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) UserAction(io.github.ihongs.serv.master.UserAction) Preset(io.github.ihongs.action.anno.Preset)

Aggregations

HongsException (io.github.ihongs.HongsException)138 Map (java.util.Map)77 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)31 IOException (java.io.IOException)29 Set (java.util.Set)26 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)24 List (java.util.List)20 HongsExemption (io.github.ihongs.HongsExemption)14 Action (io.github.ihongs.action.anno.Action)14 LinkedHashSet (java.util.LinkedHashSet)14 SQLException (java.sql.SQLException)13 FormSet (io.github.ihongs.action.FormSet)12 Table (io.github.ihongs.db.Table)12 FileNotFoundException (java.io.FileNotFoundException)11 CoreConfig (io.github.ihongs.CoreConfig)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 Iterator (java.util.Iterator)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9