diff --git a/controllers/login.go b/controllers/login.go index b349000..8790ff6 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -7,7 +7,6 @@ import ( "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" "net/http" - "strings" ) type LoginController struct { @@ -18,7 +17,6 @@ const ( UrlXmppAuth = "http://auth.xmpp.kingpenguin.tk/auth" ) - func (c *LoginController) Prepare() { } @@ -68,26 +66,23 @@ func (c *LoginController) Post() { func isLoginOK(lgn, pwd string) bool { ret := false - if len(strings.Split(lgn, "@")) != 1 { - // JID inside + usr := user.GetUserByLogin(lgn) + if usr.Id == 0 { + return ret + } + + log.Info("Standard auth") + ret = pwd != "" && pwd == usr.Password + + if !ret && usr.JID != "" { log.Info("Auth by JID") - usr := user.GetUserByLogin(strings.Split(lgn, "/")[0]) - if usr.Id == 0 { - // User is not in database - ret = false + resp, _ := http.Get(UrlXmppAuth + "?domain=datahouse.kingpenguin.tk&method=POST&jid=" + usr.JID + "&transaction_id=datahouse") + httpStatusCode := resp.StatusCode + if resp != nil && httpStatusCode == 200 { + ret = true } 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 - } + ret = false } - } else { - log.Info("Standard auth") - usr := user.GetUserByLogin(lgn) - ret = pwd != "" && pwd == usr.Password } return ret }