✨ 重新初始化项目
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"Lee-WineList/core"
|
||||
"Lee-WineList/model/param"
|
||||
"Lee-WineList/oauth2"
|
||||
"Lee-WineList/repository"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -30,7 +29,6 @@ func (l loginApi) Login(ctx *gin.Context) {
|
||||
core.R(ctx).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户基础账号信息
|
||||
userId, err := oauth2.OAuthServer.UserAuthorizationHandler(ctx.Writer, ctx.Request)
|
||||
if err != nil {
|
||||
@@ -40,10 +38,13 @@ func (l loginApi) Login(ctx *gin.Context) {
|
||||
}
|
||||
// 重新组装登录参数
|
||||
ctx.Request.Form = url.Values{
|
||||
"username": {userId},
|
||||
"password": {p.Password},
|
||||
"scope": {"ALL"},
|
||||
"grant_type": {"password"},
|
||||
"username": {userId},
|
||||
"password": {p.Password},
|
||||
"scope": {"ALL"},
|
||||
"grant_type": {"password"},
|
||||
"invite_code": {p.InviteCode},
|
||||
"nickName": {p.NickName},
|
||||
"avatarUrl": {p.AvatarUrl},
|
||||
}
|
||||
|
||||
// 参数解析成功,进行登录
|
||||
@@ -52,11 +53,7 @@ func (l loginApi) Login(ctx *gin.Context) {
|
||||
core.R(ctx).FailWithMessage("系统错误,登录失败")
|
||||
return
|
||||
}
|
||||
// 登录成功才更新登录时间
|
||||
if ctx.Writer.Status() == http.StatusOK {
|
||||
// 登录成功,更新登录时间和IP
|
||||
go repository.Login().UpdateLastLoginInfo(userId, ctx.ClientIP(), p.UserIdentity)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Refresh 刷新登录Token
|
||||
@@ -107,3 +104,13 @@ func (loginApi) Logout(ctx *gin.Context) {
|
||||
|
||||
r.Ok()
|
||||
}
|
||||
|
||||
func (l loginApi) GetWeChatToken(c *gin.Context) {
|
||||
wechaetToken, err := http.Get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3d38ce1103a82225&secret=3c41ca428b4d0f43cfaef6f567a1cc06")
|
||||
if err != nil {
|
||||
log.Errorf("获取微信Token失败: %v", err)
|
||||
core.R(c).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
core.R(c).OkWithData(wechaetToken)
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ func (u userApi) GetUser(ctx *gin.Context) {
|
||||
// 转换为VO
|
||||
var v vo.UserVO
|
||||
v.ParseOrdinary(ue)
|
||||
|
||||
core.R(ctx).OkWithData(v)
|
||||
}
|
||||
|
||||
@@ -56,11 +57,11 @@ func (u userApi) BindingWeChat(ctx *gin.Context) {
|
||||
core.R(ctx).FailWithMessage("系统错误,请稍后再试")
|
||||
return
|
||||
}
|
||||
log.Debugf("用户[%v]的UnionId为[%v],OpenId为[%v]", loginUser.Id, unionId, openId)
|
||||
if repository.User().CheckUnionIdIsExist(unionId, openId) {
|
||||
core.R(ctx).FailWithMessage("该微信已绑定其他账号")
|
||||
return
|
||||
}
|
||||
//log.Debugf("用户[%v]的UnionId为[%v],OpenId为[%v]", loginUser.Id, unionId, openId)
|
||||
//if repository.User().CheckUnionIdIsExist(unionId, openId) {
|
||||
// core.R(ctx).FailWithMessage("该微信已绑定其他账号")
|
||||
// return
|
||||
//}
|
||||
// 解析成功,修改用户信息
|
||||
loginUser.WechatUnionId = &unionId
|
||||
loginUser.WechatOpenId = &openId
|
||||
@@ -100,5 +101,6 @@ func (u userApi) UpdateUser(ctx *gin.Context) {
|
||||
core.R(ctx).FailWithMessage("修改用户信息失败: " + err.Error())
|
||||
return
|
||||
}
|
||||
// 操作成功,更新头像和昵称
|
||||
core.R(ctx).Ok()
|
||||
}
|
||||
|
50
api/app/wine.go
Normal file
50
api/app/wine.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"Lee-WineList/core"
|
||||
"Lee-WineList/model/param"
|
||||
"Lee-WineList/repository"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type wineApi struct {
|
||||
}
|
||||
|
||||
func WineApi() *wineApi {
|
||||
return &wineApi{}
|
||||
}
|
||||
|
||||
// GetList 获取酒品列表
|
||||
func (w *wineApi) GetList(ctx *gin.Context) {
|
||||
var p param.GetWineList
|
||||
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
core.R(ctx).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
wines, err := repository.Wine().GetWineList(p)
|
||||
if err != nil {
|
||||
core.R(ctx).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
core.R(ctx).OkWithData(wines)
|
||||
}
|
||||
|
||||
// Add 添加酒单
|
||||
func (w *wineApi) Add(ctx *gin.Context) {
|
||||
var p param.AddWine
|
||||
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
core.R(ctx).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := repository.Wine().Add(p); err != nil {
|
||||
core.R(ctx).FailWithMessage(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
core.R(ctx).OkWithMessage("添加成功")
|
||||
}
|
29
api/base.go
29
api/base.go
@@ -2,39 +2,14 @@ package api
|
||||
|
||||
import (
|
||||
"Lee-WineList/client"
|
||||
"Lee-WineList/common/constant"
|
||||
"Lee-WineList/core"
|
||||
"Lee-WineList/model/entity"
|
||||
"git.echol.cn/loser/logger/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetAdminUser 获取登录的管理员信息
|
||||
func GetAdminUser(ctx *gin.Context, u *entity.AdminUser) {
|
||||
userId := ctx.Request.Header.Get("userId")
|
||||
if userId == "" {
|
||||
ctx.Abort()
|
||||
core.R(ctx).FailWithMessageAndCode("未授权操作", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
u.Id = userId
|
||||
// 查询用户信息
|
||||
err := client.MySQL.Where("id = ?", u.Id).First(&u).Error
|
||||
if err != nil {
|
||||
log.Errorf("获取用户信息失败:%s", err.Error())
|
||||
core.R(ctx).FailWithMessageAndCode("用户状态异常", http.StatusBadRequest)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
// 校验
|
||||
if u.Status != constant.UserStatusActive {
|
||||
core.R(ctx).FailWithMessageAndCode("用户已被禁用", http.StatusBadRequest)
|
||||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// GetUser 获取登录的普通用户信息,dontResponse表示只获取用户信息,不论对错, dontCheck表示不检查微信绑定
|
||||
func GetUser(ctx *gin.Context, u *entity.User, dontResponse, dontCheck bool) {
|
||||
userId := ctx.Request.Header.Get("userId")
|
||||
@@ -45,7 +20,7 @@ func GetUser(ctx *gin.Context, u *entity.User, dontResponse, dontCheck bool) {
|
||||
}
|
||||
return
|
||||
}
|
||||
u.Id = userId
|
||||
u.Id, _ = strconv.Atoi(userId)
|
||||
|
||||
// 查询
|
||||
err := client.MySQL.Take(&u).Error
|
||||
|
Reference in New Issue
Block a user