:toda:初次提交
This commit is contained in:
62
internal/logic/captcha/captcha.go
Normal file
62
internal/logic/captcha/captcha.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"kami/internal/service"
|
||||
)
|
||||
|
||||
func init() {
|
||||
service.RegisterCaptcha(New())
|
||||
}
|
||||
|
||||
func New() *sCaptcha {
|
||||
return &sCaptcha{
|
||||
driver: &base64Captcha.DriverString{
|
||||
Height: 80,
|
||||
Width: 240,
|
||||
NoiseCount: 50,
|
||||
ShowLineOptions: 20,
|
||||
Length: 4,
|
||||
Source: "abcdefghjkmnpqrstuvwxyz23456789",
|
||||
Fonts: []string{"chromohv.ttf"},
|
||||
},
|
||||
store: base64Captcha.DefaultMemStore,
|
||||
}
|
||||
}
|
||||
|
||||
type sCaptcha struct {
|
||||
driver *base64Captcha.DriverString
|
||||
store base64Captcha.Store
|
||||
}
|
||||
|
||||
var (
|
||||
captcha = sCaptcha{
|
||||
driver: &base64Captcha.DriverString{
|
||||
Height: 80,
|
||||
Width: 240,
|
||||
NoiseCount: 50,
|
||||
ShowLineOptions: 20,
|
||||
Length: 4,
|
||||
Source: "abcdefghjkmnpqrstuvwxyz23456789",
|
||||
Fonts: []string{"chromohv.ttf"},
|
||||
},
|
||||
store: base64Captcha.DefaultMemStore,
|
||||
}
|
||||
)
|
||||
|
||||
// GetVerifyImgString 获取字母数字混合验证码
|
||||
func (s *sCaptcha) GetVerifyImgString(ctx context.Context) (idKeyC string, base64stringC string, err error) {
|
||||
driver := s.driver.ConvertFonts()
|
||||
c := base64Captcha.NewCaptcha(driver, s.store)
|
||||
idKeyC, base64stringC, err = c.Generate()
|
||||
return
|
||||
}
|
||||
|
||||
// VerifyString 验证输入的验证码是否正确
|
||||
func (s *sCaptcha) VerifyString(id, answer string) bool {
|
||||
c := base64Captcha.NewCaptcha(s.driver, s.store)
|
||||
answer = gstr.ToLower(answer)
|
||||
return c.Verify(id, answer, true)
|
||||
}
|
||||
31
internal/logic/user_center/user_center.go
Normal file
31
internal/logic/user_center/user_center.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package user_center
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kami/internal/dao"
|
||||
"kami/internal/model/entity"
|
||||
)
|
||||
|
||||
type sUserCenter struct {
|
||||
}
|
||||
|
||||
func (c *sUserCenter) Login(ctx context.Context, userInfo entity.User) (err error) {
|
||||
// 登录
|
||||
var resUserInfo *entity.User
|
||||
err = dao.User.Ctx(ctx).
|
||||
Where(dao.User.Columns().Username, userInfo.Username).
|
||||
WhereOr(dao.User.Columns().Phone, userInfo.Phone).Scan(&resUserInfo)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resUserInfo.Id == "" {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *sUserCenter) checkPassword(oldPassword, newPassword string) {
|
||||
// 检查新密码和旧密码是不是想同
|
||||
}
|
||||
14
resource/casbin/rbac_model.conf
Normal file
14
resource/casbin/rbac_model.conf
Normal file
@@ -0,0 +1,14 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act
|
||||
|
||||
[role_definition]
|
||||
g = _, _
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow))
|
||||
|
||||
[matchers]
|
||||
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
|
||||
5
resource/casbin/rbac_policy.csv
Normal file
5
resource/casbin/rbac_policy.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
p, alice, data1, read
|
||||
p, bob, data2, write
|
||||
p, data2_admin, data2, read
|
||||
p, data2_admin, data2, write
|
||||
g, alice, data2_admin
|
||||
|
Reference in New Issue
Block a user