All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quhaodian.user.plugs.github.GitHubOauthController Maven / Gradle / Ivy

There is a newer version: 1.8.31
Show newest version
package com.quhaodian.user.plugs.github;


import com.quhaodian.plug.Message;
import com.quhaodian.plug.data.entity.PluginConfig;
import com.quhaodian.plug.data.service.PluginConfigService;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller("gitHubOauthController")
@RequestMapping("/admin/oauth_plugin/github")
public class GitHubOauthController {

  @Resource(name = "gitHubOauthPlugin")
  private GitHubOauthPlugin filePlugin;

  @Resource(name = "pluginConfigServiceImpl")
  private PluginConfigService pluginConfigService;


  /**
   * 安装
   */
  @RequestMapping(value = "/install")
  public String install(RedirectAttributes redirectAttributes) {
    if (!filePlugin.getIsInstalled()) {
      PluginConfig pluginConfig = new PluginConfig();
      pluginConfig.setPluginId(filePlugin.getId());
      pluginConfig.setIsEnabled(false);
      pluginConfigService.save(pluginConfig);
    }
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);

    return "redirect:/admin/oauth_plugin/list.htm";
  }

  /**
   * 卸载
   */
  @RequestMapping(value = "/uninstall")
  public String uninstall(RedirectAttributes redirectAttributes) {
    if (filePlugin.getIsInstalled()) {
      PluginConfig pluginConfig = filePlugin.getPluginConfig();
      pluginConfigService.deleteById(pluginConfig.getId());
    }
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/oauth_plugin/list.htm";
  }


  /**
   * 设置
   */
  @RequestMapping(value = "/setting", method = RequestMethod.GET)
  public String setting(ModelMap model) {
    PluginConfig pluginConfig = filePlugin.getPluginConfig();
    model.addAttribute("pluginConfig", pluginConfig);
    return "/admin/oauth_plugin/setting_file";
  }

  protected void addFlashMessage(RedirectAttributes redirectAttributes, Message message) {
    if (redirectAttributes != null && message != null) {
      redirectAttributes.addFlashAttribute("msg", message);
    }
  }

  protected static final Message SUCCESS_MESSAGE = new Message(Message.Type.success, "成功");

  /**
   * 更新
   */
  @RequestMapping(value = "/update", method = RequestMethod.POST)
  public String update(Integer order, RedirectAttributes redirectAttributes) {
    PluginConfig pluginConfig = filePlugin.getPluginConfig();
    pluginConfig.setIsEnabled(true);
    pluginConfig.setSortNum(order);
    pluginConfigService.update(pluginConfig);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/oauth_plugin/list.htm";
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy