Guest User

forgotPassword

a guest
May 8th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.12 KB | None | 0 0
  1. def forgotPassword = {
  2.  
  3.  
  4.         if (!request.post) {
  5.             // show the form
  6.             return
  7.         }
  8.         //campo em branco
  9.         String email = params.email
  10.         def user = User.findByEmail(email)
  11.  
  12.         if (!email) {
  13.             flash.error = message(code: 'Campo email em branco')
  14.             redirect action: 'forgotPassword'
  15.             return
  16.  
  17.         }else if (!user)
  18.         {
  19.             flash.error = message(code:'Email não encontrado')
  20.             redirect action:'forgotPassword'
  21.             return
  22.         }else
  23.         {
  24.             def registrationCode = new RegistrationCode(user: user.username)
  25.             registrationCode.save(flush:true)
  26.  
  27.             String url = generateLink('resetPassword', [t: registrationCode.token])
  28.            
  29.             //def conf = springSecurityUtils.securityConfig
  30.            
  31.             //def body = 'Usuario.:'+user.username+"""Senha.:"""+user.password
  32.            
  33.             def body = """Usuario: ${user.username}
  34.                           Link: <a href="${url}">clique aqui</a> """
  35.            
  36.            
  37.             if (body.contains('$')) {
  38.                 body = evaluate(body, [user: user, url: url])
  39.             }
  40.            
  41.             mailService.sendMail {
  42.                 to user.email
  43.                 from '[email protected]'
  44.                 subject 'Teste recuperar senha'
  45.                 html body.toString()
  46.             }
  47.            
  48.         }
  49.  
  50.         [emailSent: true]
Advertisement
Add Comment
Please, Sign In to add comment