diff --git a/controllers/login.go b/controllers/login.go index 26d426b..cfef350 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -2,15 +2,32 @@ package controllers import ( "github.com/astaxie/beego" + "github.com/astaxie/beego/logs" "git.kingpenguin.tk/chteufleur/datahouse.git/models/user" "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" + + "net/http" + "strings" ) type LoginController struct { beego.Controller } +const ( + UrlXmppAuth = "http://auth.xmpp.kingpenguin.tk/auth" +) + +var ( + log = logs.NewLogger(10000) +) + +func init() { + log.SetLogger(variables.LogType, variables.LogParams) +} + + func (c *LoginController) Prepare() { } @@ -59,7 +76,27 @@ func (c *LoginController) Post() { } func isLoginOK(lgn, pwd string) bool { - ret := pwd != "" // Do not authorize empty password - usr := user.GetUserByLogin(lgn) - return ret && pwd == usr.Password + ret := false + if len(strings.Split(lgn, "@")) != 1 { + // JID inside + log.Info("Auth by JID") + usr := user.GetUserByLogin(strings.Split(lgn, "/")[0]) + if usr.Id == 0 { + // User is not in database + ret = false + } else { + resp, _ := http.Get(UrlXmppAuth+"?domain=datahouse.kingpenguin.tk&method=POST&jid="+lgn+"&transaction_id="+pwd) + httpStatusCode := resp.StatusCode + if resp != nil && httpStatusCode == 200 { + ret = true + } else { + ret = false + } + } + } else { + log.Info("Standard auth") + usr := user.GetUserByLogin(lgn) + ret = pwd != "" && pwd == usr.Password + } + return ret } diff --git a/main.go b/main.go index 3328c50..a3ca752 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { go reborn() time.Sleep(1 * time.Second) - models.ChanRuns <- xmpp_manager.EndRun +// models.ChanRuns <- xmpp_manager.EndRun time.Sleep(1 * time.Second) models.ChanRuns <- watchlog.EndRun