Pegar variáveis email e password de um formulário para fazer
24/03/2009 00:00
0
Olá Pessoal!
estou tendo um problema na hora de executar o método doLogin() no controlle pq as variáveis não estão sendo carregadas no formulário:
Alguém pode me ajudar, estou começando agora no grails:
segue o método no arquivo usuarioSistemaController:


def login = {
}

def doLogin = {
def usuarioSistema = UsuarioSistema.findWhere(email:params['email'],password:params['password'])
session.usuarioSistema = usuarioSistema
if (usuarioSistema)
redirect(controller:'usuarioSistema',action:'list')
else
redirect(controller:'usuarioSistema',action:'login')
print 'leu aqui!'
}

segue o form:

<g&#58;form action=&quot;doLogin&quot; method=&quot;get&quot;>
<div class=&quot;dialog&quot;>
<p>Enter your login details below&#58;</p>
<table class=&quot;userForm&quot; summary=&quot;layout table&quot;>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;20%&quot;>
<label for=&quot;email&quot;>Email&#58;</label>
</td>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;80%&quot;>
<input id=&quot;email&quot; type=&quot;text&quot; name=&quot;email&quot; value=&quot;$&#123;usuarioSistema?.email&#125;&quot; />
</td>
</tr>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;20%&quot;>
<label for=&quot;password&quot;>Password&#58;</label>
</td>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;80%&quot;>
<input id=&quot;password&quot; type=&quot;password&quot; name=&quot;password&quot; value=&quot;$&#123;usuarioSistema?.password&#125;&quot; />
</td>
</tr>
</table>
</div>
<div class=&quot;buttons&quot;>
<span class=&quot;formButton&quot;>
<input type=&quot;submit&quot; value=&quot;Login&quot;></input>
</span>
</div>
</g&#58;form>
Tags: Grails


0
93!

Fala ae!
Tô formatando seu código só pra facilitar a leitura, blz?


def login = &#123;
&#125;

def doLogin = &#123;
def usuarioSistema = UsuarioSistema.findWhere(email&#58;params['email'],password&#58;params['password'])
session.usuarioSistema = usuarioSistema
if (usuarioSistema)
redirect(controller&#58;'usuarioSistema',action&#58;'list')
else
redirect(controller&#58;'usuarioSistema',action&#58;'login')
print 'leu aqui!'
&#125;



<g&#58;form action=&quot;doLogin&quot; method=&quot;get&quot;>
<div class=&quot;dialog&quot;>
<p>Enter your login details below&#58;</p>
<table class=&quot;userForm&quot; summary=&quot;layout table&quot;>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;20%&quot;>
<label for=&quot;email&quot;>Email&#58;</label>
</td>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;80%&quot;>
<input id=&quot;email&quot; type=&quot;text&quot; name=&quot;email&quot; value=&quot;$&#123;usuarioSistema?.email&#125;&quot; />
</td>
</tr>
<tr class=&quot;prop&quot;>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;20%&quot;>
<label for=&quot;password&quot;>Password&#58;</label>
</td>
<td valign=&quot;top&quot; style=&quot;text-align&#58;left;&quot; width=&quot;80%&quot;>
<input id=&quot;password&quot; type=&quot;password&quot; name=&quot;password&quot; value=&quot;$&#123;usuarioSistema?.password&#125;&quot; />
</td>
</tr>
</table>
</div>
<div class=&quot;buttons&quot;>
<span class=&quot;formButton&quot;>
<input type=&quot;submit&quot; value=&quot;Login&quot;></input>
</span>
</div>
</g&#58;form>


Para formatar &quot;html&quot;:
<!-- m --><a class="postlink" href="http://www.pseltd.com/xhtml_formatter.aspx">http://www.pseltd.com/xhtml_formatter.aspx</a><!-- m -->

93,93/93
24/03/2009 00:00


0
Pessoal consegui a solução do código!!!
vejam o modo certo de pegar as variáveis do form e executar o doLogin()



def login = &#123;
&#125;

def doLogin = &#123;
def usuarioSistema = UsuarioSistema.findByEmailAndPassword(params['email'],params['password'])

if (usuarioSistema)&#123;
session.usuarioSistema = usuarioSistema
redirect(controller&#58;'usuarioSistema',action&#58;'list')
//redirect(controller&#58;'news',action&#58;'list')
&#125;else
redirect(controller&#58;'usuarioSistema',action&#58;'login')
&#125;





<g&#58;form action=&quot;doLogin&quot; method=&quot;get&quot;>
<div class=&quot;dialog&quot;>
<p>Enter your login details below&#58;</p>
<table class=&quot;userForm&quot;>
<tr class='prop'>
<td valign='top' style='text-align&#58;left;' width='20%'>
<label for='email'>Email&#58;</label>
</td>
<td valign='top' style='text-align&#58;left;' width='80%'>
<input id=&quot;email&quot; type='text' name='email' value='$&#123;usuarioSistema?.email&#125;' />
</td>
</tr>
<tr class='prop'>
<td valign='top' style='text-align&#58;left;' width='20%'>
<label for='password'>Password&#58;</label>
</td>
<td valign='top' style='text-align&#58;left;' width='80%'>
<input id=&quot;password&quot; type='password' name='password'
value='$&#123;usuarioSistema?.password&#125;' />
</td>
</tr>
</table>
</div>
<div class=&quot;buttons&quot;>
<span class=&quot;formButton&quot;>
<input type=&quot;submit&quot; value=&quot;Login&quot;></input>
</span>
</div>
</g&#58;form>



Obrigado!
24/03/2009 00:00



Ainda não faz parte da comunidade???

Para se registrar, clique aqui.


Aprenda Groovy e Grails com a Formação itexto!

Newsletter Semana Groovy

Assinar

Envie seu link!


Livro de Grails


/dev/All

Os melhores blogs de TI (e em português) em um único lugar!

 
Creative Commons
RSS Grails Brasil é mantido por itexto Consultoria.
Em caso de problemas contacte Henrique Lobo Weissmann (Kico) por e-mail: kico@itexto.com.br
Todo o conteúdo presente neste site adota o Creative Commons como licença padrão.
Ver: 4.14.0
itexto