- Timestamp:
- 03/14/12 19:30:24 (12 years ago)
- Location:
- tapas/web
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
tapas/web/resources/js/classesForJQuery/LoginButton.js
r403 r412 224 224 { 225 225 this.errors = jQuery.parseJSON( result ).errors; 226 this.setJSONUser( null != jQuery.parseJSON( result ).jSON People ? jQuery.parseJSON( result ).jSONPeople: false );226 this.setJSONUser( null != jQuery.parseJSON( result ).jSONUser ? jQuery.parseJSON( result ).jSONUser : false ); 227 227 if( null == this.errors ) 228 228 this.updateLoginOrLogout(); -
tapas/web/resources/templates/templateBackoffice_script.jsp
r409 r412 1 <%@ page import="com.ether.WebHelper" %> 1 2 <script type="text/javascript"> 2 3 var InterfaceTemplate = Class.create( { … … 15 16 <%--this.webmaster = "<%=Context.getWebmaster(request)%>";--%> 16 17 <%--this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>";--%> 17 <%--this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;--%>18 this.jSONUser = <%=WebHelper.getJSONUser( request )%> ? <%=WebHelper.getJSONUser( request )%> : false; 18 19 19 20 /** ************ CREATE ************ **/ -
tapas/web/src/com/ether/ControllerEther.java
r409 r412 5 5 import com.ether.annotation.ParamName; 6 6 import com.ether.annotation.UseJSON; 7 import com.ether.user.User; 7 8 import net.sf.json.JSON; 8 9 import net.sf.json.JSONArray; … … 48 49 } 49 50 51 /** 52 * This method logs a user 53 * 54 * @param login 55 * @param password 56 * @param request 57 * @return 58 * @throws ServiceException 59 */ 60 @ControllerMethod(requestMandatory = true, jsonResult = true) 61 public JSONObject login( @ParamName(ParameterConstants.PARAMETER_LOGIN) final String login, 62 @ParamName(ParameterConstants.PARAMETER_PWD) final String password, 63 @NotNull final HttpServletRequest request ) 64 throws ServiceException 65 { 66 final JSONObject jSONUser = new JSONObject(); 67 final JSONObject result = new JSONObject(); 68 69 if( login != null && password != null ) 70 { 71 try 72 { 73 final User user = _tapasService.getUserByEmail( login ); 74 final String encryptedPassword = EtherHelper.encryptPassword( password ); 75 if( user == null ) 76 result.put( "errors", "login.error.notFound" ); 77 else if( !encryptedPassword.equals( user.getPassword() ) ) 78 result.put( "errors", "login.error.wrongPassword" ); 79 else 80 { 81 request.getSession().setAttribute( "SES_USER", user ); 82 jSONUser.put( "name", user.getLastName() ); 83 jSONUser.put( "firstName", user.getFirstName() ); 84 jSONUser.put( "role", user.getRole().name() ); 85 } 86 } 87 catch( Exception e ) 88 { 89 result.put( "errors", "login.error.failed" ); 90 } 91 } 92 93 if( !jSONUser.isEmpty() ) 94 result.put( "jSONUser", jSONUser ); 95 return result; 96 } 97 98 @ControllerMethod(requestMandatory = true, jsonResult = true) 99 public JSONObject logout( @NotNull final HttpServletRequest request ) 100 throws ServiceException 101 { 102 request.getSession().setAttribute( "SES_USER", null ); 103 request.getSession().invalidate(); 104 105 return new JSONObject(); 106 } 107 50 108 @Override 51 109 @Nullable … … 95 153 if( methodDescription.isRequestMandatory() ) 96 154 params[params.length - 1] = request; 155 156 if( methodDescription.isBackofficeMethod() ) 157 { 158 final String defaultView = null != methodDescription.getDefaultView() ? methodDescription.getDefaultView() : methodDescription.getView(); 159 final User user = (User) request.getSession().getAttribute( "SES_USER" ); 160 if( null == user ) 161 { 162 return new ModelAndView( defaultView, "errors", "login.error.unknown" ); 163 } 164 else if( null != user && !user.isAccessToBO() ) 165 { 166 return new ModelAndView( defaultView, "errors", "login.error.bo.notAccepted" ); 167 } 168 } 97 169 98 170 final Object result; -
tapas/web/src/com/ether/WebHelper.java
r402 r412 2 2 3 3 import com.ether.WebException.WebCode; 4 import com.ether.user.User; 5 import net.sf.json.JSONObject; 4 6 import org.apache.commons.logging.Log; 5 7 import org.apache.commons.logging.LogFactory; … … 68 70 } 69 71 72 /** 73 * This method returns the user in session if there is one 74 * 75 * @param request 76 * @return 77 */ 78 public static JSONObject getJSONUser( @NotNull final HttpServletRequest request ) 79 { 80 final JSONObject jSONPeople = new JSONObject(); 81 82 final User user = (User) request.getSession().getAttribute( "SES_USER" ); 83 if( null == user ) 84 return null; 85 86 jSONPeople.put( "name", user.getLastName() ); 87 jSONPeople.put( "firstName", user.getFirstName() ); 88 jSONPeople.put( "role", user.getRole() ); 89 return jSONPeople; 90 } 91 92 70 93 private static final Log LOGGER = LogFactory.getLog( WebHelper.class ); 71 94
Note: See TracChangeset
for help on using the changeset viewer.