Changeset 2211
- Timestamp:
- May 3, 2006, 5:02:47 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/User.java
r2101 r2211 3 3 4 4 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 7 8 8 9 This file is part of BASE. … … 798 799 { 799 800 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; 800 840 } 801 841 -
trunk/www/admin/users/index.jsp
r2197 r2211 2 2 ------------------------------------------------------------------ 3 3 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 6 7 7 8 This file is part of BASE. … … 42 43 import="net.sf.basedb.core.PermissionDeniedException" 43 44 import="net.sf.basedb.core.ItemAlreadyExistsException" 45 import="net.sf.basedb.core.DatabaseException" 44 46 import="net.sf.basedb.util.RemovableUtil" 45 47 import="net.sf.basedb.clients.web.Base" … … 227 229 if (roleId != -1) Role.getById(dc, roleId).addUser(user); 228 230 } 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 } 230 249 cc.removeObject("item"); 231 250 }
Note: See TracChangeset
for help on using the changeset viewer.