Add XMPP auth

This commit is contained in:
chteufleur 2016-06-22 19:44:10 +02:00
parent 3147a064db
commit c221349a9c
2 changed files with 41 additions and 4 deletions

View File

@ -2,15 +2,32 @@ package controllers
import ( import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"git.kingpenguin.tk/chteufleur/datahouse.git/models/user" "git.kingpenguin.tk/chteufleur/datahouse.git/models/user"
"git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables"
"net/http"
"strings"
) )
type LoginController struct { type LoginController struct {
beego.Controller 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() { func (c *LoginController) Prepare() {
} }
@ -59,7 +76,27 @@ func (c *LoginController) Post() {
} }
func isLoginOK(lgn, pwd string) bool { func isLoginOK(lgn, pwd string) bool {
ret := pwd != "" // Do not authorize empty password ret := false
usr := user.GetUserByLogin(lgn) if len(strings.Split(lgn, "@")) != 1 {
return ret && pwd == usr.Password // 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
} }

View File

@ -64,7 +64,7 @@ func main() {
go reborn() go reborn()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
models.ChanRuns <- xmpp_manager.EndRun // models.ChanRuns <- xmpp_manager.EndRun
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
models.ChanRuns <- watchlog.EndRun models.ChanRuns <- watchlog.EndRun