This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2016-11-27 10:46:50 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
|
|
|
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
|
|
|
libpassword "dev.sum7.eu/sum7/warehost/lib/password"
|
|
|
|
system "dev.sum7.eu/sum7/warehost/system"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WarehostAuth struct {
|
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
|
2016-12-20 00:35:03 +01:00
|
|
|
func (auth WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) {
|
2016-11-27 10:46:50 +01:00
|
|
|
returndata = false
|
|
|
|
var login = system.Login{Username: user}
|
2016-12-20 00:35:03 +01:00
|
|
|
auth.db.Where("mail = ?", user).First(&login)
|
2016-11-27 10:46:50 +01:00
|
|
|
if login.ID <= 0 {
|
|
|
|
liblog.Log.Warn("user not found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if login.Active {
|
|
|
|
output, _ := libpassword.Validate(login.Password, pass)
|
|
|
|
if output {
|
|
|
|
returndata = true
|
|
|
|
liblog.Log.Info("done")
|
|
|
|
} else {
|
|
|
|
liblog.Log.Warn("wrong password")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
liblog.Log.Warn("not active")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|