Add XMPP auth
This commit is contained in:
parent
3147a064db
commit
c221349a9c
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue