| | |
| | | package com.lf.server.controller.sys; |
| | | |
| | | import com.lf.server.controller.BaseController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.data.UsersEntity; |
| | | import com.lf.server.entity.sys.LoginInfo; |
| | | import com.lf.server.entity.sys.Result; |
| | | import com.lf.server.entity.sys.User; |
| | | import com.lf.server.service.sys.UserService; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.service.data.UsersService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/sign") |
| | | public class SignController { |
| | | public class SignController extends BaseController { |
| | | @Autowired |
| | | UserService userService; |
| | | |
| | | @GetMapping("/getName") |
| | | public User getName(String loginName) { |
| | | return userService.queryUserByName(loginName); |
| | | } |
| | | UsersService userService; |
| | | |
| | | /** |
| | | * 跳到首页 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 跳到未授权页面 |
| | | * return "redirect:/toLogin" |
| | | * |
| | | * @return String |
| | | */ |
| | | @GetMapping("/noauth") |
| | | public ModelAndView toNoAuth(ModelAndView mv) { |
| | | mv.setViewName("noauth"); |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 登录认证 |
| | | * |
| | | * @return String |
| | | */ |
| | | @GetMapping("/login") |
| | | public ModelAndView login(String username, String password, String service, Integer rememberMe) { |
| | | ModelAndView mv = new ModelAndView(); |
| | | @PostMapping(value="/login", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<String> login(@RequestBody UsersEntity user) { |
| | | try { |
| | | mv.setViewName("index"); |
| | | if (service != null && service.length() > 0) { |
| | | mv.addObject("url", service); |
| | | } else { |
| | | mv.addObject("msg", username); |
| | | if (user == null) { |
| | | return fail("请输入用户名和密码!", null); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | if (StringHelper.isEmpty(user.getUid())) { |
| | | return fail("用户名不能为空!", null); |
| | | } |
| | | if (StringHelper.isEmpty(user.getPwd())) { |
| | | return fail("密码不能为空!", null); |
| | | } |
| | | |
| | | return mv; |
| | | UsersEntity ue = userService.selectByUid(user.getUid()); |
| | | if (ue == null) { |
| | | return fail("用户名不存在!", null); |
| | | } |
| | | |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | mv.setViewName("login"); |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * Ajax登录 |
| | | * |
| | | * @param userInfo |
| | | * @return |
| | | */ |
| | | @PostMapping(value = "/ajaxLogin", produces = "application/json; charset=UTF-8") |
| | | public Result ajaxLogin(@RequestBody User userInfo) { |
| | | try { |
| | | LoginInfo loginInfo = userService.getLoginInfo(userInfo.getLoginName()); |
| | | |
| | | return new Result(200, loginInfo != null ? "登录成功" : "登录失败", loginInfo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new Result(500, e.getMessage()); |
| | | } |
| | | } |
| | | } |