Add authication by XMPP (XEP-0070)

This commit is contained in:
chteufleur 2016-12-16 21:40:08 +01:00
parent 295d564951
commit 3ff845ed90
1 changed files with 14 additions and 19 deletions

View File

@ -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,15 +66,17 @@ func (c *LoginController) Post() {
func isLoginOK(lgn, pwd string) bool {
ret := false
if len(strings.Split(lgn, "@")) != 1 {
// JID inside
log.Info("Auth by JID")
usr := user.GetUserByLogin(strings.Split(lgn, "/")[0])
usr := user.GetUserByLogin(lgn)
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)
return ret
}
log.Info("Standard auth")
ret = pwd != "" && pwd == usr.Password
if !ret && usr.JID != "" {
log.Info("Auth by JID")
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
@ -84,10 +84,5 @@ func isLoginOK(lgn, pwd string) bool {
ret = false
}
}
} else {
log.Info("Standard auth")
usr := user.GetUserByLogin(lgn)
ret = pwd != "" && pwd == usr.Password
}
return ret
}