| 1 | class Person { |
|---|
| 2 | static transients = ['pass'] |
|---|
| 3 | static hasMany = [authorities: Authority, |
|---|
| 4 | personGroups: PersonGroup, |
|---|
| 5 | taskModifications: TaskModification, |
|---|
| 6 | entries: Entry, |
|---|
| 7 | tasks: Task, |
|---|
| 8 | addresses: Address] |
|---|
| 9 | |
|---|
| 10 | static belongsTo = [Authority] |
|---|
| 11 | |
|---|
| 12 | Department department |
|---|
| 13 | |
|---|
| 14 | String loginName |
|---|
| 15 | String firstName |
|---|
| 16 | String lastName |
|---|
| 17 | String employeeID |
|---|
| 18 | |
|---|
| 19 | /* Set after login by 'welcome' action, default to 12 hours, aka "sess.setMaxInactiveInterval(seconds) */ |
|---|
| 20 | Integer sessionTimeout = 43200 |
|---|
| 21 | |
|---|
| 22 | /** MD5 Password */ |
|---|
| 23 | String password |
|---|
| 24 | |
|---|
| 25 | /** enabled */ |
|---|
| 26 | boolean isActive = true |
|---|
| 27 | |
|---|
| 28 | String email |
|---|
| 29 | boolean emailShow = true |
|---|
| 30 | |
|---|
| 31 | /** description */ |
|---|
| 32 | String description = '' |
|---|
| 33 | |
|---|
| 34 | /** plain password to create a MD5 password */ |
|---|
| 35 | String pass |
|---|
| 36 | |
|---|
| 37 | static constraints = { |
|---|
| 38 | loginName(blank: false, unique: true, minSize:4) //minSize:7 |
|---|
| 39 | firstName(blank: false) |
|---|
| 40 | lastName(blank: false) |
|---|
| 41 | employeeID(blank: true, nullable:true) |
|---|
| 42 | description() |
|---|
| 43 | department(nullable:true) |
|---|
| 44 | email() |
|---|
| 45 | emailShow() |
|---|
| 46 | isActive() |
|---|
| 47 | //Enforcing minSize on password does not work since "" gets encoded to a string. |
|---|
| 48 | password(blank: false) |
|---|
| 49 | //So we need to use pass for validation then encode it for above. |
|---|
| 50 | pass(blank: false, minSize:4) //minSize:7 |
|---|
| 51 | sessionTimeout(min:60, max:43200) |
|---|
| 52 | |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | //Overriding the default toString method |
|---|
| 56 | String toString() {"${this.firstName} ${this.lastName}"} |
|---|
| 57 | |
|---|
| 58 | // This additional setter is used to convert the checkBoxList string or string array |
|---|
| 59 | // of ids selected to the corresponding domain objects. |
|---|
| 60 | public void setPersonGroupsFromCheckBoxList(ids) { |
|---|
| 61 | def idList = [] |
|---|
| 62 | if(ids instanceof String) { |
|---|
| 63 | if(ids.isInteger()) |
|---|
| 64 | idList << ids.toInteger() |
|---|
| 65 | } |
|---|
| 66 | else { |
|---|
| 67 | ids.each() { |
|---|
| 68 | if(it.isInteger()) |
|---|
| 69 | idList << it.toInteger() |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | this.personGroups = idList.collect { PersonGroup.get( it ) } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | } // end class |
|---|