Package com.foxconn.gds.security.model

Examples of com.foxconn.gds.security.model.UserAccount


    }
  }

  @Override
  public boolean deleteMark(String account, boolean deletedthrows Exception {
    UserAccount user = this.findUserAccountByID(account);
    if(user!=null) {
      EntityManager em = null;
      EntityTransaction tx = null;
      try {
        em = entityManagerFactory.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        user.setDeleteMark(deleted);
        em.merge(user);
        tx.commit();
      } catch (Exception err) {
        if(tx!=null) tx.rollback();
        log.severe( err.getMessage() );
View Full Code Here


    return false;
  }

  @Override
  public boolean resetPassword(String account, String defaultPasswordthrows Exception {
    UserAccount user = this.findUserAccountByID(account);
    if(user!=null) {
      EntityManager em = null;
      EntityTransaction tx = null;     
      try {
        em = entityManagerFactory.createEntityManager();
        tx = em.getTransaction();
     
        tx.begin();
       
        UserAccount tmp
          = new UserAccount(account, defaultPassword, user.getToken(), user.getProfile());
        tmp.setInGroups( user.getInGroups() );
        tmp.setId( user.getId() );
       
        em.merge(tmp);
        tx.commit();
      } catch (Exception err) {
        if(tx!=null) tx.rollback();
View Full Code Here

  }

  @Override
  public boolean setNewPassword(String account, String oldPasswod,
      String newPassword) throws Exception {
    UserAccount user = this.findUserAccount(account, oldPasswod);   
    if(user!=null) {
      EntityManager em = null;
      EntityTransaction tx = null;
      try {
        em = entityManagerFactory.createEntityManager();
        tx = em.getTransaction();
     
        tx.begin();
       
        UserAccount tmp
          = new UserAccount(account, newPassword, user.getToken(), user.getProfile());
        tmp.setInGroups( user.getInGroups() );
        tmp.setId( user.getId() );
       
        em.merge(tmp);
        tx.commit();
      } catch (Exception err) {
        if(tx!=null) tx.rollback();
View Full Code Here

  public boolean saveOrUpdateUserAccount(UserAccount user, boolean updated)
  throws Exception {
    if(user==null || user.getAccount()==null || user.getProfile()==null) {
      throw new Exception("User Account Or Profile Is Null ...");
    }
    UserAccount tmpUser = this.findUserAccountByID(user.getAccount());
    if(tmpUser!=null ) {//
      if(!updated) {
        throw new Exception("[NOT SAVE] User Account exist already ...");
      } else {
        user.setId( tmpUser.getId() );
      }   
    }
   
    UserProfile profile = user.getProfile();
    UserProfile tmpProfile = this.findUserProfile(profile.getEmployeeId());
View Full Code Here

    }
    //-------------------------------------------------------
    Collection<UserGroup> ownUsers = null;
    if(accountAy!=null) {
      for(String account : accountAy){
        UserAccount userAccount = this.findUserAccountByID(account);
        UserGroup userGroup = new UserGroup(userAccount, pGrp);
        if(ownUsers==null) {
          ownUsers = new ArrayList<UserGroup>();
        }
        ownUsers.add(userGroup);
View Full Code Here

      jnObj.put("total", sspInfo.getTotal());
      jnObj.put("records", sspInfo.getRecords());
     
      JSONArray jnAry = new JSONArray();
      JSONObject perJN;
      UserAccount acc = null;
      for(int i=0, size=accounts.size(); i<size; i++) {
        acc = accounts.get(i);
        perJN = new JSONObject();
        perJN.put("id", acc.getId());
        perJN.put("account", acc.getAccount());
        perJN.put("profile.name", acc.getProfile().getName());
        perJN.put("profile.employeeId", acc.getProfile().getEmployeeId());
        perJN.put("profile.email", acc.getProfile().getEmail());
        perJN.put("profile.mobile", acc.getProfile().getMobile());
       
        perJN.put("myGroups", acc.getMyGroups())
        perJN.put("delMark", acc.isDeleteMark());
        jnAry.add(perJN);
      }
     
      jnObj.put("rows", jnAry);
     
//      System.out.println( "JSON.toString = \n"+ jnObj.toString() );
      res.setContentType("text/json;charset=utf-8");
      res.getWriter().write( jnObj.toString() );
// EDIT     
    } else if (req.getRequestURI().endsWith("edit.do")) {
//      System.out.println("req.URI="+req.getRequestURI());
      UserAccount user = this.compose(req);
      JSONObject jnObj = new JSONObject();
      try {
        if( !UserAccountServices.getInstance().saveOrUpdateUserAccount(user, true) ) {       
          jnObj.put("msg", "Edit User Info Failure~!");
          res.getWriter().write(jnObj.toString());
        } else {
          jnObj.put("msg","Edit User Info Success !");         
          res.getWriter().write(jnObj.toString());         
        }
      } catch (Exception ex) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        jnObj.put("msg",ex.getMessage());         
        res.getWriter().write(jnObj.toString());         
      }
     
// ADD     
    } else if (req.getRequestURI().endsWith("add.do")) {
//      System.out.println("req.URI="+req.getRequestURI());
      UserAccount user = compose(req);
      try {
        if(!UserAccountServices.getInstance().saveOrUpdateUserAccount(user, false)) {
          res.getWriter().write("Add User Account/Profile/Group Failure~!");
        } else {
          res.getWriter().write("Add User Account/Profile/Group Success !");
        }
      } catch (Exception ex) {
        //ex.printStackTrace();
        //res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        res.getWriter().write(ex.getMessage());
      }     
// DEL     
    } else if (req.getRequestURI().endsWith("del.do")) {
//      System.out.println("req.URI="+req.getRequestURI());
      String account = req.getParameter("account");
      try {
        if(! UserAccountServices.getInstance().deleteMark(account, true) ) {
          res.getWriter().write("Mark Delete failure!");
        } else {
          res.getWriter().write("Mark Delete Success!");
        }
      } catch(Exception ex) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        res.getWriter().write(ex.getMessage());
      }
// RESET     
    } else if (req.getRequestURI().endsWith("reset.do")) {
//      System.out.println("req.URI="+req.getRequestURI());
      String account = req.getParameter("account");
      String type = req.getParameter("type");
      JSONObject jnObj = new JSONObject();
      try {
        if("R".equals(type)) {
          if(! UserAccountServices.getInstance().resetPassword(account, account) ) {
            res.getWriter().write("Reset Password Failure!");
          } else {
            res.getWriter().write("Reset Password Success!<br> Your New Password is Your Account! ");
          }
        } else if("C".equals(type)) {
          if(! UserAccountServices.getInstance().deleteMark(account, false) ) {
            res.getWriter().write("Cancel Delete Mark Failure!");
          } else {
            res.getWriter().write("Cancel Delete Mark Success!");
          }
        } else if("N".equals(type)) {
          String oldPwd = req.getParameter("oldPwd");
          String newPwd = req.getParameter("newPwd");
         
          if(! UserAccountServices.getInstance().setNewPassword(account, oldPwd, newPwd) ) {
            jnObj.put("msg", "Set New Password Failure!");
            res.getWriter().write(jnObj.toString());
          } else {
            jnObj.put("msg", "Set New Password Success!");
            res.getWriter().write(jnObj.toString());
          }
        }
      } catch(Exception ex) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        jnObj.put("msg", ex.getMessage());
        res.getWriter().write( jnObj.toString() );
      }
// List GROUPS     
    } else if(req.getRequestURI().endsWith("groups.do")) {
        Integer page, limit;
        String sidx, sord;
        // $1 ----------------------
        // get the requested page
        page = Integer.valueOf(req.getParameter("page"));
        // get how many rows we want to have into the grid
        // rowNum parameter in the grid
        limit = Integer.valueOf(req.getParameter("rows"));
        // get index row - i.e. user click to sort
        // at first time sortname parameter - after that the index from colModel
        sidx = req.getParameter("sidx");
        // sorting order - at first time sortorder
        sord = req.getParameter("sord");
       
        SSPageInfo sspInfo = new SSPageInfo(page, limit, sidx, sord);
        sspInfo.set_search( req.getParameter("_search") );
        if(sspInfo.is_search() && req.getParameter("filters")!=null ) {
          JSONParser jnParser = new JSONParser();
          JSONObject jo = (JSONObject)jnParser.parse( req.getParameter("filters") );
          sspInfo.setCondition(jo);
        }   
     
        // $2 -----------------------         
        List<Group> allGroups = UserAccountServices.getInstance().sspGroups(sspInfo);
       
        // $3 -----------------------
        // constructing a JSON
        JSONObject jnObj = new JSONObject();
        jnObj.put("page", sspInfo.getPage());
        jnObj.put("total", sspInfo.getTotal());
        jnObj.put("records", sspInfo.getRecords());
       
        JSONArray jnAry = new JSONArray();
        Group grp = null;
        JSONObject perJN=null;
        StringBuilder sb = new StringBuilder();
        for(int i=0, size=allGroups.size(); i<size; i++) {
          grp = allGroups.get(i);
          perJN = new JSONObject();
          perJN.put("id", grp.getId());
         
          perJN.put("groupName", grp.getGroupName());
          sb = new StringBuilder();
          for(UserGroup ug : grp.getOwnUsers()) {
            if(ug.getUserAccount()!=null) {
              sb.append( ug.getUserAccount().getAccount() ).append(",");
            }
          }
          perJN.put("ownUsers", sb.toString());
         
          jnAry.add(perJN);
        }
       
        jnObj.put("rows", jnAry);
       
        System.out.println( "JSON.toString = \n"+ jnObj.toString() );
        res.setContentType("text/json;charset=utf-8");
        res.getWriter().write( jnObj.toString() );
// FETCH ALL USERS       
    } else if(req.getRequestURI().endsWith("allUsers.do")) {
      List<UserAccount> allUsers = UserAccountServices.getInstance().listAllUserAccount();
      JSONArray jnAry = new JSONArray();
      UserAccount account = null;
      JSONObject perJN=null;
      for(int i=0, size=allUsers.size(); i<size; i++) {
        account = allUsers.get(i);
        perJN = new JSONObject();
        perJN.put("id", account.getId());
        perJN.put("account", account.getAccount());
        jnAry.add(perJN);
      }
     
      System.out.println( "JSON.toString = \n"+ jnAry.toString() );
      res.setContentType("text/json;charset=utf-8");
View Full Code Here

    }
  }
 
  private UserAccount compose(HttpServletRequest req) {
    String account = req.getParameter("account");
    UserAccount user = UserAccountServices.getInstance().findUserAccountByID(account);
    if(user==null) {
      user = new UserAccount(account, account);
    }
    UserProfile newProfile = new UserProfile(
        req.getParameter("profile.employeeId"),
        req.getParameter("profile.name"),
        req.getParameter("profile.email"),
        req.getParameter("profile.mobile")
    );
    newProfile.setFirstName(req.getParameter("profile.firstName"));
    newProfile.setLastName(req.getParameter("profile.lastName"));
 
    user.setProfile(newProfile);
    user.setId(0);
    UserAccount newAccount = user;
//    UserAccount newAccount = new UserAccount(
//      account,
//      user.getPassword(),
//      user.getToken(),     
//      newProfile
//    );
    String[] grps = req.getParameterValues("myGroups");
    StringBuilder myGroups = new StringBuilder("");
    for(String grp : grps) {
      myGroups.append(grp).append(",");
    }
//    System.out.println("---- myGroups = " + myGroups);
    newAccount.setMyGroups(myGroups.substring(0, myGroups.length()>0?myGroups.length()-1:0));
     
    return newAccount;
  }
View Full Code Here

TOP

Related Classes of com.foxconn.gds.security.model.UserAccount

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.