Changeset 2211


Ignore:
Timestamp:
May 3, 2006, 5:02:47 PM (17 years ago)
Author:
Martin Svensson
Message:

Fixes #37 New/Edit? user - Handling of duplicate login

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/User.java

    r2101 r2211  
    33
    44  BioArray Software Environment (BASE) - http://base.thep.lu.se/
    5   Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    6   Johan Vallon-Christersson, Jari H�kkinen, Nicklas Nordborg
     5  Copyright (C) 2002-2006 Lao Saal, Carl Troein,
     6  Johan Vallon-Christersson, Jari Häkkinen,
     7  Nicklas Nordborg, Martin Svensson
    78
    89  This file is part of BASE.
     
    798799  {
    799800    return Message.getQuery(this);
     801  }
     802 
     803 
     804  /**
     805    Check if a login name already exists in the database
     806      @param login The login name to look for
     807    @return TRUE if an user has the login. FALSE if the login is not in use.
     808  */
     809  public boolean loginIsUsed(DbControl dc, String login)
     810  {
     811    org.hibernate.Session session = dc.getHibernateSession();
     812    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_FOR_LOGIN");
     813    /*
     814      SELECT usr
     815      FROM UserData usr
     816      WHERE usr.login = :login
     817    */
     818    query.setString("login", login);
     819    UserData userData = HibernateUtil.loadData(UserData.class, query);
     820    return userData != null;
     821  }
     822 
     823  /**
     824      Check if an external ID already exists in the database
     825      @param externalid The externalID to look for
     826      @return TRUE if an user has the external ID. FALSE if the externalID is not in use.
     827  */ 
     828  public boolean externalIdIsUsed(DbControl dc, String externalid)
     829  {
     830    org.hibernate.Session session = dc.getHibernateSession();
     831    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_FOR_EXTERNAL_ID");
     832    /*
     833      SELECT usr
     834      FROM UserData usr
     835      WHERE usr.externalId = :externalId
     836    */
     837    query.setParameter("externalId", externalid);
     838    UserData userData = HibernateUtil.loadData(UserData.class, query);
     839    return userData != null;
    800840  }
    801841 
  • trunk/www/admin/users/index.jsp

    r2197 r2211  
    22  ------------------------------------------------------------------
    33  BioArray Software Environment (BASE) - http://base.thep.lu.se/
    4   Copyright (C) 2002-2004 Lao Saal, Carl Troein,
    5   Johan Vallon-Christersson, Jari Häkkinen, Nicklas Nordborg
     4  Copyright (C) 2002-2006 Lao Saal, Carl Troein,
     5  Johan Vallon-Christersson, Jari Häkkinen,
     6  Nicklas Nordborg, Martin Svensson
    67
    78  This file is part of BASE.
     
    4243  import="net.sf.basedb.core.PermissionDeniedException"
    4344  import="net.sf.basedb.core.ItemAlreadyExistsException"
     45  import="net.sf.basedb.core.DatabaseException"
    4446  import="net.sf.basedb.util.RemovableUtil"
    4547  import="net.sf.basedb.clients.web.Base"
     
    227229      if (roleId != -1) Role.getById(dc, roleId).addUser(user);
    228230    }
    229     dc.commit();
     231    try
     232    {
     233      dc.commit();
     234    }
     235    catch(DatabaseException dbex)
     236    {
     237      dc = sc.newDbControl();
     238      if(user.loginIsUsed(dc, login))
     239      {
     240        throw new ItemAlreadyExistsException("Login [" + login + "] is taken");
     241      }
     242      String externalid = Values.getStringOrNull(request.getParameter("external_id"));
     243      if(user.externalIdIsUsed(dc, externalid))
     244      {
     245        throw new ItemAlreadyExistsException("ExternalID [" + externalid + "] is taken.");
     246      }
     247      throw new DatabaseException(dbex.getMessage());
     248    }
    230249    cc.removeObject("item");
    231250  }
Note: See TracChangeset for help on using the changeset viewer.