package system import ( "time" log "dev.sum7.de/sum7/warehost/lib/log" libpassword "dev.sum7.de/sum7/warehost/lib/password" "github.com/go-xorm/xorm" ) // Login object for request type RequestLogin struct { Username string `json:"username"` Password string `json:"password"` } // Login found type Login struct { Id int64 `json:"id"` Username string `xorm:"varchar(255) not null unique 'mail'" json:"username"` Password string `xorm:"varchar(255) not null 'password'" json:"-"` Active bool `xorm:"boolean default false 'active'" json:"active"` Code string `xorm:"varchar(255) 'code'" json:"-"` Superadmin bool `xorm:"boolean default false 'superadmin'" json:"superadmin"` CreateAt time.Time `xorm:"timestampz 'createat'" json:"createat"` LastLoginAt time.Time `xorm:"timestampz 'lastloginat'" json:"lastloginat"` } func SyncModels(dbconnection *xorm.Engine) { err := dbconnection.Sync(new(Login)) if err != nil { log.Log.Fatal("create table \"login\" ", err) } result, err := dbconnection.Count(new(Login)) if err != nil { log.Log.Error("get \"login\" count ", err) } if result <= 0 { login := new(Login) login.Username = "root" login.Password = libpassword.NewHesh("root") login.CreateAt = time.Now() login.Active = true login.Superadmin = true _, err := dbconnection.Insert(login) if err == nil { log.Log.Warn("Create user \"root\"") } else { log.Log.Fatal("cound not first user \"root\" ", err) } } }