简体   繁体   中英

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!

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:

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. 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. Therefore the users cannot be persisted in your bootstrap.groovy. Double check, that save works:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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