fix all error and bug !!!!!!!!!!!!!

This commit is contained in:
Jay
2018-09-21 01:14:08 +08:00
parent 07436cd8df
commit 906b7be381
24 changed files with 133 additions and 109 deletions
+16 -1
View File
@@ -24,7 +24,7 @@ func CheckSession(c *context.Context) {
case model.Account:
name = userData.(model.Account).Account
case twitch.UserInfo:
name = userData.(twitch.UserInfo).DisplayName
name = userData.(twitch.UserInfo).Login
default:
c.LoginFirst(nil)
return
@@ -85,3 +85,18 @@ func UserLogout(c *context.Context) {
c.Success(nil)
}
// GetSessionData -
func GetSessionData(c *context.Context) {
session := sessions.Default(c.Context)
loginUser := session.Get("loginUser")
if loginUser == nil {
c.LoginFirst(nil)
return
}
user := map[string]interface{}{
"user": loginUser,
}
c.Success(user)
}
+9 -7
View File
@@ -1,10 +1,10 @@
package api
import (
"fmt"
"time"
"git.trj.tw/golang/mtfosbot/model"
"git.trj.tw/golang/mtfosbot/module/apis/twitch"
"git.trj.tw/golang/mtfosbot/module/context"
"git.trj.tw/golang/mtfosbot/module/twitch-irc"
"git.trj.tw/golang/mtfosbot/module/utils"
@@ -49,7 +49,7 @@ func GetChannels(c *context.Context) {
c.LoginFirst(nil)
return
}
user, ok := u.(model.TwitchChannel)
user, ok := u.(twitch.UserInfo)
if !ok {
c.LoginFirst(nil)
return
@@ -121,9 +121,12 @@ func GetChannelList(c *context.Context) {
return
}
mapList := make([]map[string]interface{}, len(list))
for k, v := range list {
mapList[k] = utils.ToMap(v)
mapList := make([]map[string]interface{}, 0)
for _, v := range list {
if v == nil {
continue
}
mapList = append(mapList, utils.ToMap(v))
}
c.Success(map[string]interface{}{
@@ -221,7 +224,6 @@ func GetDonateSetting(c *context.Context) {
ds, err := model.GetDonateSettingByChannel(chdata.ID)
if err != nil {
fmt.Println(ds, err)
c.ServerError(nil)
return
}
@@ -251,7 +253,7 @@ func UpdateDonateSetting(c *context.Context) {
End int64 `json:"end" binding:"exists"`
Title string `json:"title" binding:"required"`
Amount int `json:"amount" binding:"exists"`
StartAmount int `json:"start_amount"`
StartAmount int `json:"start_amount" binding:"exists"`
}{}
err := c.BindData(&bodyArg)
if err != nil {
-2
View File
@@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"git.trj.tw/golang/mtfosbot/module/config"
@@ -78,7 +77,6 @@ func GetLineMessage(c *context.Context) {
err := json.Unmarshal(raw, &events)
if err != nil {
fmt.Println("parse line message error ::: ", err)
c.ServerError(nil)
return
}
+1 -1
View File
@@ -44,7 +44,6 @@ func NewServ() *gin.Engine {
// SetRoutes - set routes
func SetRoutes(r *gin.Engine) {
r.GET("/", func(c *gin.Context) {
fmt.Println("in next")
c.JSON(200, gin.H{
"message": "ok",
})
@@ -60,6 +59,7 @@ func SetRoutes(r *gin.Engine) {
{
apiGroup.POST("/login", context.PatchCtx(api.UserLogin))
apiGroup.POST("/logout", context.PatchCtx(api.UserLogout))
apiGroup.GET("/session", context.PatchCtx(api.CheckSession), context.PatchCtx(api.GetSessionData))
apiGroup.GET("/twitch/channel/:chid/opay/bar", context.PatchCtx(api.GetDonateBarStatus))
}
apiTwitchGroup := apiGroup.Group("/twitch", context.PatchCtx(api.CheckSession))
+6 -15
View File
@@ -14,6 +14,7 @@ import (
// OAuthLogin -
func OAuthLogin(c *context.Context) {
session := sessions.Default(c.Context)
twOauth := `https://id.twitch.tv/oauth2/authorize`
conf := config.GetConf()
redirectTo := strings.TrimRight(conf.URL, "/")
redirectTo += "/twitch/oauth"
@@ -29,17 +30,7 @@ func OAuthLogin(c *context.Context) {
session.Save()
}
u, err := url.Parse(redirectTo)
if err != nil {
c.ServerError(nil)
return
}
finalURL, err := u.Parse(qs.Encode())
if err != nil {
c.ServerError(nil)
return
}
c.Redirect(301, finalURL.String())
c.Redirect(302, twOauth+"?"+qs.Encode())
}
// OAuthProc -
@@ -52,7 +43,7 @@ func OAuthProc(c *context.Context) {
tokenData, err := twitchapi.GetTokenData(code)
if err != nil {
c.DataFormat(nil)
c.DataFormat("token get fail")
return
}
@@ -76,7 +67,7 @@ func OAuthProc(c *context.Context) {
if chData == nil {
chData = &model.TwitchChannel{
ID: userData.ID,
Name: userData.DisplayName,
Name: userData.Login,
}
err = chData.Add()
if err != nil {
@@ -84,8 +75,8 @@ func OAuthProc(c *context.Context) {
return
}
} else {
if userData.DisplayName != chData.Name {
chData.UpdateName(userData.DisplayName)
if userData.Login != chData.Name {
chData.UpdateName(userData.Login)
}
}