Changeset 414 for tapas/web/src/com/ether/ControllerEponge.java
- Timestamp:
- 03/15/12 12:53:14 (12 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
tapas/web/src/com/ether/ControllerEponge.java
r366 r414 5 5 import com.ether.user.User; 6 6 import com.ether.user.UserRole; 7 import com.ether.user.UserState;8 import com.medias.Constantes;9 import com.medias.Context;10 import com.medias.annuaire.Personne;11 import com.medias.mail.Mail;12 import com.medias.mail.MailFactory;13 7 import net.sf.json.JSONObject; 14 8 import org.apache.commons.logging.Log; … … 17 11 import org.jetbrains.annotations.Nullable; 18 12 19 import javax.mail.MessagingException;20 13 import javax.servlet.http.HttpServletRequest; 21 14 import java.security.DigestException; 22 15 import java.security.NoSuchAlgorithmException; 23 import java.util.ArrayList;24 16 import java.util.Date; 25 17 import java.util.HashMap; … … 28 20 /** 29 21 * @author vmipsl 30 * @date 1 2 nov 201122 * @date 15 march 2012 31 23 */ 32 24 public class ControllerEponge … … 36 28 /** *********************** VIEWS ***************************** **/ 37 29 /** *********************************************************** **/ 38 @ControllerMethod(view = VIEW_ ERRORS)39 public Map<String, Object> viewErrors()40 throws ServiceException30 @ControllerMethod(view = VIEW_INIT) 31 public Map<String, Object> home() 32 throws WebException 41 33 { 42 34 return new HashMap<String, Object>(); 43 35 } 44 36 45 @ControllerMethod(view = VIEW_ LOGIN)46 public Map<String, Object> view Login()37 @ControllerMethod(view = VIEW_ERRORS) 38 public Map<String, Object> viewErrors() 47 39 throws ServiceException 48 40 { … … 56 48 final MethodDescription methodDescription = getMethods().get( "viewHomeDataProtocol" ); 57 49 58 if( Context.getLangue( request ).equals( Constantes.french_language ) )59 methodDescription.setView( VIEW_DATA_PROTOCOL_FR );60 else61 methodDescription.setView( VIEW_DATA_PROTOCOL_EN );50 // if( Context.getLangue( request ).equals( Constantes.french_language ) ) 51 // methodDescription.setView( VIEW_DATA_PROTOCOL_FR ); 52 // else 53 // methodDescription.setView( VIEW_DATA_PROTOCOL_EN ); 62 54 return new HashMap<String, Object>(); 63 55 } … … 66 58 /** *********************** CALLS ***************************** **/ 67 59 /** *********************************************************** **/ 60 /** 61 * This method logs a user 62 * 63 * @param login 64 * @param password 65 * @param request 66 * @return 67 * @throws ServiceException 68 */ 68 69 @ControllerMethod(requestMandatory = true, jsonResult = true) 69 70 public JSONObject login( @ParamName(ParameterConstants.PARAMETER_LOGIN) final String login, … … 72 73 throws ServiceException 73 74 { 74 final JSONObject jSON People= new JSONObject();75 final JSONObject jSONUser = new JSONObject(); 75 76 final JSONObject result = new JSONObject(); 76 77 … … 79 80 try 80 81 { 81 final User user = get EtherService().getUserByEmail( login );82 final User user = getTapasService().getUserByEmail( login ); 82 83 final String encryptedPassword = EtherHelper.encryptPassword( password ); 83 84 if( user == null ) … … 85 86 else if( !encryptedPassword.equals( user.getPassword() ) ) 86 87 result.put( "errors", "login.error.wrongPassword" ); 87 else if( !UserState.ACCEPTED.equals( user.getState() ) )88 result.put( "errors", "login.error.notAccepted" );89 88 else 90 89 { 91 Personne person = getEtherService().getPeopleByEmail( user.getEmail() ); 92 if( person == null ) 93 { 94 // This is a simple user with no set of data _ Personne in session is used for tests in .jsp 95 person = new Personne(); 96 person.setNom( user.getLastName() ); 97 person.setPrenom( user.getFirstName() ); 98 person.setMail( user.getEmail() ); 99 person.setRoles( user.getRole().name() ); 100 // Can't be null because of the tests in .jsp (upload.jsp by example) 101 person.setJeux( new ArrayList<String>() ); 102 } 103 104 request.getSession().setAttribute( "SES_USER", person ); 105 jSONPeople.put( "name", user.getLastName() ); 106 jSONPeople.put( "firstName", user.getFirstName() ); 107 jSONPeople.put( "role", user.getRole().name() ); 90 request.getSession().setAttribute( "SES_USER", user ); 91 jSONUser.put( "name", user.getLastName() ); 92 jSONUser.put( "firstName", user.getFirstName() ); 93 jSONUser.put( "role", user.getRole().name() ); 108 94 } 109 95 } … … 114 100 } 115 101 116 if( !jSON People.isEmpty() )117 result.put( "jSON People", jSONPeople);102 if( !jSONUser.isEmpty() ) 103 result.put( "jSONUser", jSONUser ); 118 104 return result; 119 105 } … … 129 115 } 130 116 117 131 118 @ControllerMethod(jsonResult = true) 132 119 public JSONObject createAccount( @NotNull @ParamName(ParameterConstants.PARAMETER_NAME) final String lastName, … … 138 125 try 139 126 { 140 final User existingUser = get EtherService().getUserByEmail( email );127 final User existingUser = getTapasService().getUserByEmail( email ); 141 128 if( null == existingUser ) 142 129 { … … 144 131 145 132 final String encryptedPassword = EtherHelper.encryptPassword( password ); 146 final User user = new User( lastName, firstName, email, encryptedPassword, UserRole. COORDINATOR, UserState.WAITING, false, creationDate );133 final User user = new User( lastName, firstName, email, encryptedPassword, UserRole.USER, false, creationDate ); 147 134 148 get EtherService().createUser( user );135 getTapasService().createUser( user ); 149 136 150 137 // Send email to administrator to inform there is a new account … … 175 162 throws WebException 176 163 { 177 try178 {179 final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" );180 final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" );181 final String toPI = (String) getServletContext().getAttribute( "APP_PI" );182 final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur";183 final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" +184 " - Nom : " + user.getLastName() + '\n' +185 " - Prénom : " + user.getFirstName() + '\n' +186 " - Email : " + user.getEmail() + "\n\n" +187 "Tu peux accepter ou refuser son inscription via le BO : http://ether.ipsl.jussieu.fr/megapoli/backoffice\n\n" +188 "Bonne soirée,\nLe serveur masqué";189 190 final Mail mailAdministrator = new Mail( from, from, null, content, subject );191 mailFactory.sendMail( mailAdministrator );192 final Mail mailPI = new Mail( from, toPI, null, content, subject );193 mailFactory.sendMail( mailPI );194 }195 catch( MessagingException e )196 {197 throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the megapoli administrator" );198 }164 // try 165 // { 166 // final MailFactory mailFactory = (MailFactory) getServletContext().getAttribute( "APP_MAILFACTORY" ); 167 // final String from = (String) getServletContext().getAttribute( "APP_WEBMASTER" ); 168 // final String toPI = (String) getServletContext().getAttribute( "APP_PI" ); 169 // final String subject = "[MEGAPOLI] Nouvelle demande de compte utilisateur"; 170 // final String content = "Hello Matthias,\n\nUne nouvelle demande de compte vient d'arriver.\n\n" + 171 // " - Nom : " + user.getLastName() + '\n' + 172 // " - Prénom : " + user.getFirstName() + '\n' + 173 // " - Email : " + user.getEmail() + "\n\n" + 174 // "Tu peux accepter ou refuser son inscription via le BO : http://ether.ipsl.jussieu.fr/megapoli/backoffice\n\n" + 175 // "Bonne soirée,\nLe serveur masqué"; 176 // 177 // final Mail mailAdministrator = new Mail( from, from, null, content, subject ); 178 // mailFactory.sendMail( mailAdministrator ); 179 // final Mail mailPI = new Mail( from, toPI, null, content, subject ); 180 // mailFactory.sendMail( mailPI ); 181 // } 182 // catch( MessagingException e ) 183 // { 184 // throw new WebException( WebException.WebCode.ERROR_EMAIL_CANNOT_BE_SEND, "The email cannot be send to the megapoli administrator" ); 185 // } 199 186 } 200 187 201 188 private static final Log LOGGER = LogFactory.getLog( ControllerEponge.class ); 202 189 190 private static final String VIEW_INIT = "init"; 203 191 private static final String VIEW_ERRORS = "project/errors"; 204 private static final String VIEW_LOGIN = "project/login";205 192 private static final String VIEW_DATA_PROTOCOL_EN = "project/home_dataProtocol_en"; 206 193 private static final String VIEW_DATA_PROTOCOL_FR = "project/home_dataProtocol_fr";
Note: See TracChangeset
for help on using the changeset viewer.