Package com.github.dactiv.showcase.entity.account

Examples of com.github.dactiv.showcase.entity.account.User


   */
    @OperatingAudit(function="修改密码")
  @RequestMapping("/change-password")
  public String changePassword(String oldPassword,String newPassword) {

    User user = SystemVariableUtils.getSessionVariable().getUser();
   
    oldPassword = new SimpleHash("MD5", oldPassword.toCharArray()).toString();
   
    if (!user.getPassword().equals(oldPassword)) {
      throw new ServiceException("旧密码不正确.");
    }
   
    accountManager.updateUserPassword(user,newPassword);
     
View Full Code Here


   */
  @ResponseBody
  @RequestMapping("/change-portrait")
  public Map<String, Object> changePortrait(HttpServletRequest request) throws IOException {
    //获取当前用户
    User entity = SystemVariableUtils.getSessionVariable().getUser();
   
    Map<String, Object> result = Maps.newHashMap();
   
    //获取传进来的流
    InputStream is = request.getInputStream();
    //读取流内容到ByteArrayOutputStream中
    ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    int ch;
    while ((ch = is.read()) != -1) {
      bytestream.write(ch);
    }
   
    bytestream.close();
   
    File uploadDirectory = new File(fileUploadPath);
   
    //如果没有创建上传文件夹就创建文件夹
    if (!uploadDirectory.exists() || !uploadDirectory.isDirectory()) {
      uploadDirectory.mkdirs();
    }
   
    entity.setPortrait(fileUploadPath + entity.getId());
   
    File portraitFile = new File(fileUploadPath + entity.getId());
    //如果当前用户没有创建头像,就创建头像
    if (!portraitFile.exists()) {
      portraitFile.createNewFile();
    }
    //拷贝到指定路径里
View Full Code Here

    @OperatingAudit(function="改修个人信息")
  @SuppressWarnings("unchecked")
  @RequestMapping("/change-profile")
  public Map<String, Object> changeProfile(String realname,String email,@RequestParam(required = false)String portrait) throws IOException {
    //获取当前用户
    User entity = SystemVariableUtils.getSessionVariable().getUser();
   
    entity.setRealname(realname);
    entity.setEmail(email);
   
    accountManager.updateUser(entity);
    SystemVariableUtils.getSessionVariable().setUser(entity);
   
    return MapUtils.toMap(new BeanResourceBundle(entity,new String[]{"realname"}));
View Full Code Here

   *
   */
  @ModelAttribute("entity")
  public User bindingModel(String id) {

    User user = new User();
   
    if (StringUtils.isNotEmpty(id)) {
      user = accountManager.getUser(id);
    }

View Full Code Here

  private AccountManager accountManager;

  @Test
  @Transactional(readOnly=true)
  public void testGetUser() {
    User user = accountManager.getUser("SJDK3849CKMS3849DJCK2039ZMSK0001");
    assertEquals(user.getUsername(),"maurice");
  }
View Full Code Here

    assertEquals(page.getTotalPages(), 1);
  }

  @Test
  public void testInsertUser() {
    User entity = new User();
   
    entity.setEmail("test@test.com");
    entity.setPassword("123456");
    entity.setRealname("一个测试用户");
    entity.setUsername("test_maurice");
    entity.setState(State.Enable.getValue());
   
    int before = countRowsInTable("tb_user");
    accountManager.insertUser(entity);
    int after = countRowsInTable("tb_user");
   
View Full Code Here

  }

  @Test
  @Transactional
  public void testUpdateUser() {
    User entity = accountManager.getUser("SJDK3849CKMS3849DJCK2039ZMSK0001");
    entity.setUsername("modify");
    entity.setPassword("123456");
    entity.setRealname("maurice");
   
    accountManager.updateUser(entity);
   
    getSessionFactory().getCurrentSession().flush();
    getSessionFactory().getCurrentSession().clear();
   
    entity = accountManager.getUser("SJDK3849CKMS3849DJCK2039ZMSK0001");
   
    assertEquals(entity.getUsername(), "maurice");
    assertEquals(entity.getPassword(), "e10adc3949ba59abbe56e057f20f883e");
    assertEquals(entity.getRealname(), "maurice");
  }
View Full Code Here

    assertEquals(before - 1, after);
  }

  @Test
  public void testGetUserByUsername() {
    User entity = accountManager.getUserByUsername("maurice");
    assertEquals(entity.getUsername(), "maurice");
    assertEquals(entity.getRealname(), "maurice.chen");
  }
View Full Code Here

  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;

        String username = usernamePasswordToken.getUsername();
       
        User user = accountManager.getUserByUsername(username);
       
        if (user == null) {
            throw new IncorrectCredentialsException();
        }
       
        if (user.getState().equals(State.Disable.getValue())) {
           throw new DisabledAccountException("你的账户已被禁用,请联系管理员开通.");
        }
       
        SessionVariable model = new SessionVariable(user);
       
        return new SimpleAuthenticationInfo(model,user.getPassword(),getName());
  }
View Full Code Here

TOP

Related Classes of com.github.dactiv.showcase.entity.account.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.