简体   繁体   English

Grails登录不起作用

[英]Grails login doesn't work

I'm new to Grails, and having a problem that is no doubt trivial, but I cannot find anything online! 我是Grails的新手,并且遇到的问题无疑是微不足道的,但我在网上找不到任何东西!

I have a class: 我有一堂课:

package lib

class Login {

  String name
  String email
  String password
  String phonenumber

  static constraints = {
  }

}

In my Bootstrap file I create two instances of this class: 在我的Bootstrap文件中,创建此类的两个实例:

new Login(email:"tom", password:"password1")
new Login(email:"ian", password:"password2")

Now I have set up a Login form and I am trying to loop over these values and do something if they match: 现在,我已经设置了一个“登录”表单,并且尝试遍历这些值,并在它们匹配时执行一些操作:

def submit() {

  def result = Login.findAll { email == params.email && password == params.password }
  if (result.size() > 0) {
    println "good login"
  }
  else {
    println "bad login"
  }

  // some other stuff
}

The problem is that it is printing "bad login" every time, every when the entered email and password match those declared in the Bootstrap file. 问题在于,每次输入的电子邮件和密码与Bootstrap文件中声明的电子邮件和密码匹配时,它每次都会打印“错误登录”。 It's probably just a misunderstanding on my end, but I can't figure it out! 这可能只是我的误解,但我无法弄清楚!

Thanks. 谢谢。

phonenumber and name are null in your initialisation. phonenumbername在您初始化时为空。 Therefore the users cannot be persisted in your bootstrap.groovy. 因此,用户无法持久保存在bootstrap.groovy中。 Double check, that save works: 仔细检查,以节省工作:

def login1 = new Login(..)
if (!login1.save()) {
    log.error("Login cannot be persisted: " + login1.errors);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM