Rev 1408 | Rev 1686 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1408 | Rev 1585 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.web.controllers.authenticate; |
1 | package pt.estgp.estgweb.web.controllers.authenticate; |
2 | 2 | ||
3 | import org.apache.struts.action.*; |
- | |
4 | import org.apache.log4j.Logger; |
3 | import org.apache.log4j.Logger; |
5 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
- | |
6 | import pt.estgp.estgweb.web.utils.RequestUtils; |
- | |
7 | import pt.estgp.estgweb.web.exceptions.NoCookiesException; |
- | |
8 | import pt.estgp.estgweb.web.UserSessionProxy; |
4 | import org.apache.struts.action.*; |
9 | import pt.estgp.estgweb.web.form.profile.ProfileForm; |
- | |
10 | import pt.estgp.estgweb.services.authenticate.AuthenticateException; |
- | |
11 | import pt.estgp.estgweb.Globals; |
5 | import pt.estgp.estgweb.Globals; |
12 | import pt.estgp.estgweb.domain.UserSession; |
6 | import pt.estgp.estgweb.domain.User; |
13 | import pt.estgp.estgweb.domain.UserImpl; |
7 | import pt.estgp.estgweb.domain.UserImpl; |
- | 8 | import pt.estgp.estgweb.domain.UserSession; |
|
14 | import pt.estgp.estgweb.domain.views.UserView; |
9 | import pt.estgp.estgweb.domain.views.UserView; |
- | 10 | import pt.estgp.estgweb.services.authenticate.AuthenticateException; |
|
- | 11 | import pt.estgp.estgweb.web.UserSessionProxy; |
|
- | 12 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
|
- | 13 | import pt.estgp.estgweb.web.exceptions.NoCookiesException; |
|
- | 14 | import pt.estgp.estgweb.web.form.profile.ProfileForm; |
|
- | 15 | import pt.estgp.estgweb.web.utils.RequestUtils; |
|
15 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
16 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
16 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
17 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
17 | 18 | ||
- | 19 | import javax.servlet.ServletException; |
|
18 | import javax.servlet.http.HttpServletRequest; |
20 | import javax.servlet.http.HttpServletRequest; |
19 | import javax.servlet.http.HttpServletResponse; |
21 | import javax.servlet.http.HttpServletResponse; |
20 | import javax.servlet.ServletException; |
- | |
21 | import java.io.IOException; |
22 | import java.io.IOException; |
22 | 23 | ||
23 | /** |
24 | /** |
24 | * @author Jorge Machado |
25 | * @author Jorge Machado |
25 | * @date 26/Fev/2008 |
26 | * @date 26/Fev/2008 |
Line 77... | Line 78... | ||
77 | logger.fatal(e,e); |
78 | logger.fatal(e,e); |
78 | } |
79 | } |
79 | return mapping.findForward("error500"); |
80 | return mapping.findForward("error500"); |
80 | } |
81 | } |
81 | 82 | ||
- | 83 | ||
82 | public ActionForward checkin(ActionMapping mapping, |
84 | public ActionForward checkin(ActionMapping mapping, |
83 | ActionForm form , |
85 | ActionForm form , |
84 | HttpServletRequest request, |
86 | HttpServletRequest request, |
85 | HttpServletResponse response) |
87 | HttpServletResponse response) |
86 | throws 1.5.0/docs/api/java/io/IOException.html">IOException,ServletException |
88 | throws 1.5.0/docs/api/java/io/IOException.html">IOException,ServletException |
Line 166... | Line 168... | ||
166 | return mapping.findForward("errorNoCookies"); |
168 | return mapping.findForward("errorNoCookies"); |
167 | logger.fatal(e,e); |
169 | logger.fatal(e,e); |
168 | } |
170 | } |
169 | return mapping.findForward("error500"); |
171 | return mapping.findForward("error500"); |
170 | } |
172 | } |
- | 173 | ||
- | 174 | ||
- | 175 | public ActionForward changePassword(ActionMapping mapping, |
|
- | 176 | ActionForm form , |
|
- | 177 | HttpServletRequest request, |
|
- | 178 | HttpServletResponse response) |
|
- | 179 | throws 1.5.0/docs/api/java/io/IOException.html">IOException,ServletException |
|
- | 180 | { |
|
- | 181 | ||
- | 182 | 1.5.0/docs/api/java/lang/String.html">String password = request.getParameter("password"); |
|
- | 183 | 1.5.0/docs/api/java/lang/String.html">String password2 = request.getParameter("password2"); |
|
- | 184 | ||
- | 185 | if(password == null || password2 == null || password.trim().length() < 5 || !password.equals(password2)) |
|
- | 186 | { |
|
- | 187 | addError(request, "fail.change.pass"); |
|
- | 188 | return mapping.findForward("fail.change.pass"); |
|
- | 189 | } |
|
- | 190 | else{ |
|
- | 191 | boolean okBig = false; |
|
- | 192 | boolean okSmall = false; |
|
- | 193 | for(char c: password.toCharArray()) |
|
- | 194 | { |
|
- | 195 | if(c >= 'A' && c <='Z') |
|
- | 196 | { |
|
- | 197 | okBig = true; |
|
- | 198 | ||
- | 199 | } |
|
- | 200 | if(c >= 'a' && c <='z') |
|
- | 201 | { |
|
- | 202 | okSmall = true; |
|
- | 203 | } |
|
- | 204 | } |
|
- | 205 | if(!okBig || !okSmall) |
|
- | 206 | { |
|
- | 207 | addError(request, "fail.change.pass"); |
|
- | 208 | return mapping.findForward("fail.change.pass"); |
|
- | 209 | } |
|
- | 210 | else |
|
- | 211 | { |
|
- | 212 | try |
|
- | 213 | { |
|
- | 214 | IServiceManager sm = ServiceManager.getInstance(); |
|
- | 215 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{password}; |
|
- | 216 | sm.execute(RequestUtils.getRequester(request, response),"ChangePassword",args); |
|
- | 217 | addError(request, "success.change.pass"); |
|
- | 218 | return mapping.findForward("success"); |
|
- | 219 | } |
|
- | 220 | catch (AuthenticateException e) |
|
- | 221 | { |
|
- | 222 | ActionMessages actionMessages = new ActionMessages(); |
|
- | 223 | actionMessages.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage(e.getMessage())); |
|
- | 224 | saveErrors(request, actionMessages); |
|
- | 225 | return mapping.getInputForward(); |
|
- | 226 | } |
|
- | 227 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
|
- | 228 | { |
|
- | 229 | if(e instanceof NoCookiesException) |
|
- | 230 | return mapping.findForward("errorNoCookies"); |
|
- | 231 | logger.fatal(e,e); |
|
- | 232 | } |
|
- | 233 | } |
|
- | 234 | ||
- | 235 | } |
|
- | 236 | ||
- | 237 | return mapping.findForward("error500"); |
|
- | 238 | } |
|
- | 239 | ||
- | 240 | public ActionForward requestChangePassword(ActionMapping mapping, |
|
- | 241 | ActionForm form , |
|
- | 242 | HttpServletRequest request, |
|
- | 243 | HttpServletResponse response) |
|
- | 244 | throws 1.5.0/docs/api/java/io/IOException.html">IOException,ServletException |
|
- | 245 | { |
|
- | 246 | ||
- | 247 | 1.5.0/docs/api/java/lang/String.html">String identifier = request.getParameter("identifier"); |
|
- | 248 | ||
- | 249 | try |
|
- | 250 | { |
|
- | 251 | IServiceManager sm = ServiceManager.getInstance(); |
|
- | 252 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{identifier}; |
|
- | 253 | User u = (User) sm.execute(RequestUtils.getRequester(request, response),"RequestChangePassword",args); |
|
- | 254 | if(u == null) |
|
- | 255 | { |
|
- | 256 | addError(request,"fail.request.change.pass"); |
|
- | 257 | } |
|
- | 258 | request.setAttribute("UserRequesterPasswordChange",u); |
|
- | 259 | return mapping.findForward("success"); |
|
- | 260 | } |
|
- | 261 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
|
- | 262 | { |
|
- | 263 | if(e instanceof NoCookiesException) |
|
- | 264 | return mapping.findForward("errorNoCookies"); |
|
- | 265 | logger.fatal(e,e); |
|
- | 266 | } |
|
- | 267 | ||
- | 268 | ||
- | 269 | return mapping.findForward("error500"); |
|
- | 270 | } |
|
- | 271 | ||
- | 272 | ||
171 | } |
273 | } |