✨ add go-captcha / add base auth api
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package api
|
||||
|
||||
import "schisandra-cloud-album/api/auth_api"
|
||||
import (
|
||||
"schisandra-cloud-album/api/auth_api"
|
||||
//"schisandra-cloud-album/api/captcha_api"
|
||||
)
|
||||
|
||||
// Apis 统一导出的api
|
||||
type Apis struct {
|
||||
AuthApi auth_api.AuthAPI
|
||||
//CaptchaAPI captcha_api.CaptchaAPI
|
||||
}
|
||||
|
||||
// Api new函数实例化,实例化完成后会返回结构体地指针类型
|
||||
|
@@ -2,7 +2,9 @@ package auth_api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"reflect"
|
||||
"schisandra-cloud-album/common/result"
|
||||
"schisandra-cloud-album/model"
|
||||
"schisandra-cloud-album/service"
|
||||
)
|
||||
|
||||
@@ -17,3 +19,67 @@ func (AuthAPI) GetUserList(c *gin.Context) {
|
||||
userList := authService.GetUserList()
|
||||
result.OkWithData(userList, c)
|
||||
}
|
||||
|
||||
// QueryUserByUsername
|
||||
// @Summary 根据用户名查询用户
|
||||
// @Tags 鉴权模块
|
||||
// @Param username query string true "用户名"
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/auth/user/query_by_username [get]
|
||||
func (AuthAPI) QueryUserByUsername(c *gin.Context) {
|
||||
username := c.Query("username")
|
||||
user := authService.QueryUserByName(username)
|
||||
if reflect.DeepEqual(user, model.ScaAuthUser{}) {
|
||||
result.FailWithMessage("用户不存在!", c)
|
||||
return
|
||||
}
|
||||
result.OkWithData(user, c)
|
||||
}
|
||||
|
||||
// QueryUserByUuid
|
||||
// @Summary 根据uuid查询用户
|
||||
// @Tags 鉴权模块
|
||||
// @Param uuid query string true "用户uuid"
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/auth/user/query_by_uuid [get]
|
||||
func (AuthAPI) QueryUserByUuid(c *gin.Context) {
|
||||
uuid := c.Query("uuid")
|
||||
user := authService.QueryUserByUuid(uuid)
|
||||
if reflect.DeepEqual(user, model.ScaAuthUser{}) {
|
||||
result.FailWithMessage("用户不存在!", c)
|
||||
return
|
||||
}
|
||||
result.OkWithData(user, c)
|
||||
}
|
||||
|
||||
// DeleteUser 删除用户
|
||||
// @Summary 删除用户
|
||||
// @Tags 鉴权模块
|
||||
// @Param uuid query string true "用户uuid"
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/auth/user/delete [delete]
|
||||
func (AuthAPI) DeleteUser(c *gin.Context) {
|
||||
uuid := c.Query("uuid")
|
||||
err := authService.DeleteUser(uuid)
|
||||
if err != nil {
|
||||
result.FailWithMessage("用户删除失败!", c)
|
||||
return
|
||||
}
|
||||
result.OkWithMessage("用户删除成功!", c)
|
||||
}
|
||||
|
||||
// QueryUserByPhone 根据手机号查询用户
|
||||
// @Summary 根据手机号查询用户
|
||||
// @Tags 鉴权模块
|
||||
// @Param phone query string true "手机号"
|
||||
// @Success 200 {string} json
|
||||
// @Router /api/auth/user/query_by_phone [get]
|
||||
func (AuthAPI) QueryUserByPhone(c *gin.Context) {
|
||||
phone := c.Query("phone")
|
||||
user := authService.QueryUserByPhone(phone)
|
||||
if reflect.DeepEqual(user, model.ScaAuthUser{}) {
|
||||
result.FailWithMessage("用户不存在!", c)
|
||||
return
|
||||
}
|
||||
result.OkWithData(user, c)
|
||||
}
|
||||
|
40
api/captcha_api/captcha_api.go
Normal file
40
api/captcha_api/captcha_api.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/wenlng/go-captcha/v2/base/option"
|
||||
"github.com/wenlng/go-captcha/v2/click"
|
||||
)
|
||||
|
||||
var textCapt click.Captcha
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
captData, err := textCapt.Generate()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
dotData := captData.GetData()
|
||||
if dotData == nil {
|
||||
log.Fatalln(">>>>> generate err")
|
||||
}
|
||||
|
||||
dots, _ := json.Marshal(dotData)
|
||||
fmt.Println(">>>>> ", string(dots))
|
||||
|
||||
err = captData.GetMasterImage().SaveToFile("./.caches/master.jpg", option.QualityNone)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = captData.GetThumbImage().SaveToFile("./.caches/thumb.png")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
3
api/captcha_api/index.go
Normal file
3
api/captcha_api/index.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
type CaptchaAPI struct{}
|
Reference in New Issue
Block a user