Search in sources :

Example 6 with Action

use of io.github.ihongs.action.anno.Action 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 7 with Action

use of io.github.ihongs.action.anno.Action 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 8 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class DataAction method revert.

// ** 恢复 **/
@Action("revert")
@CommitSuccess
public void revert(ActionHelper helper) throws HongsException {
    Data ett = (Data) getEntity(helper);
    Map req = helper.getRequestData();
    // 默认的终端标识
    String meno = Synt.asString(req.get("meno"));
    if (meno == null || meno.isEmpty()) {
        req.put("meno", "centra");
    } else if (!meno.equals("centra") && !meno.startsWith("centra.")) {
        req.put("meno", "centra." + meno);
    }
    helper.reply("", ett.revert(req));
}
Also used : Data(io.github.ihongs.serv.matrix.Data) Map(java.util.Map) Action(io.github.ihongs.action.anno.Action) SearchAction(io.github.ihongs.dh.search.SearchAction) CommitSuccess(io.github.ihongs.action.anno.CommitSuccess)

Example 9 with Action

use of io.github.ihongs.action.anno.Action in project HongsCORE by ihongs.

the class DataAction method reveal.

@Action("reveal")
public void reveal(ActionHelper helper) throws HongsException {
    ActionRunner runner = (ActionRunner) helper.getAttribute(ActionRunner.class.getName());
    String ent = runner.getEntity();
    String mod = runner.getModule();
    Data ett = (Data) getEntity(helper);
    Map req = helper.getRequestData();
    req.put("form_id", ett.getFormId());
    req.put("user_id", req.get("user"));
    Map rsp = ett.getModel().search(req);
    // 详情数据转换
    if (rsp.containsKey("info")) {
        Map df = (Map) rsp.remove("info");
        Map dt = (Map) Dawn.toObject((String) df.remove("data"));
        rsp.put("snap", df);
        rsp.put("info", dt);
        // 补充枚举和关联
        Set ab = Synt.toTerms(req.get(Cnst.AB_KEY));
        if (null != ab) {
            byte md = 0;
            if (ab.contains(".enfo"))
                md += SelectHelper.ENFO;
            if (ab.contains(".info"))
                md += SelectHelper.INFO;
            if (ab.contains(".fall"))
                md += SelectHelper.FALL;
            if (ab.contains("_text"))
                md += SelectHelper.TEXT;
            if (ab.contains("_time"))
                md += SelectHelper.TIME;
            if (ab.contains("_link"))
                md += SelectHelper.LINK;
            if (ab.contains("_fork"))
                md += SelectHelper.FORK;
            if (md != 0) {
                new SelectHelper().addItemsByForm(mod, ent).select(rsp, md);
            }
            // 新的和旧的
            if (ab.contains("older") || ab.contains("newer")) {
                Object id = df.get(/**/
                "id");
                Object fid = df.get("form_id");
                long ctime = Synt.declare(df.get("ctime"), 0L);
                if (ab.contains("older")) {
                    Map row = ett.getModel().table.fetchCase().filter("`id` = ? AND `form_id` = ? AND `ctime` < ?", id, fid, ctime).assort("`ctime` DESC").select("`ctime`").getOne();
                    df.put("older", !row.isEmpty() ? row.get("ctime") : null);
                }
                if (ab.contains("newer")) {
                    Map row = ett.getModel().table.fetchCase().filter("`id` = ? AND `form_id` = ? AND `ctime` > ?", id, fid, ctime).assort("`ctime`  ASC").select("`ctime`").getOne();
                    df.put("newer", !row.isEmpty() ? row.get("ctime") : null);
                }
            }
        }
    }
    helper.reply(rsp);
}
Also used : ActionRunner(io.github.ihongs.action.ActionRunner) Set(java.util.Set) Data(io.github.ihongs.serv.matrix.Data) Map(java.util.Map) SelectHelper(io.github.ihongs.action.SelectHelper) Action(io.github.ihongs.action.anno.Action) SearchAction(io.github.ihongs.dh.search.SearchAction)

Example 10 with Action

use of io.github.ihongs.action.anno.Action 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)

Aggregations

Action (io.github.ihongs.action.anno.Action)64 Map (java.util.Map)53 HashMap (java.util.HashMap)26 CommitSuccess (io.github.ihongs.action.anno.CommitSuccess)22 Preset (io.github.ihongs.action.anno.Preset)15 HongsException (io.github.ihongs.HongsException)14 CoreLocale (io.github.ihongs.CoreLocale)12 NaviMap (io.github.ihongs.action.NaviMap)12 Verify (io.github.ihongs.action.anno.Verify)10 IAction (io.github.ihongs.dh.IAction)10 CoreConfig (io.github.ihongs.CoreConfig)9 Select (io.github.ihongs.action.anno.Select)8 Set (java.util.Set)8 List (java.util.List)7 File (java.io.File)6 HashSet (java.util.HashSet)6 FetchCase (io.github.ihongs.db.util.FetchCase)5 JAction (io.github.ihongs.dh.JAction)4 UserAction (io.github.ihongs.serv.master.UserAction)3 ArrayList (java.util.ArrayList)3