Add auth api Add Test Router Add More Error info Add More Config ....

dev 1.0.2
aimerforreimu 6 years ago
parent ac6d076d0c
commit dea98de8fa
  1. 6
      README.md
  2. 20
      auxpiAll/all.go
  3. 426
      auxpiAll/all_easyjson.go
  4. 0
      auxpiAll/auxpiRun.log
  5. 1
      auxpiAll/e/code.go
  6. 10
      auxpiAll/logging.go
  7. 36
      controllers/api/base/api.go
  8. 13
      controllers/api/v1/auth/auth.go
  9. 22
      controllers/api/v1/auth/register.go
  10. 33
      controllers/api/v1/user/user.go
  11. 2
      main.go
  12. 74
      middleware/xsrf.go
  13. 13
      routers/api/auth/auth.go
  14. 4
      routers/api/v1/upload.go
  15. 29
      routers/router.go
  16. 7
      server/Sina.go

@ -50,16 +50,12 @@
**演示站点为 [AuXpI 图床](https://imgx.0w0.tn/)**
**因为服务器在国外,可能会上传稍微慢一些 ~**
**因为服务器在国外,可能会上传稍微慢一些~**
使用该图床有两种选择,一种选择是使用 Release 中已经编译好的文件,另外一种选择是自己编译代码。
### 萌新安装教程
请看 [https://0w0.tn/archives/auxpi-install-guide-moe.html](https://0w0.tn/archives/auxpi-install-guide-moe.html)
### 从 Release 中获取编译完成的文件
首先需要到 [Release](https://github.com/aimerforreimu/AUXPI/releases) 中下载符合您服务器需要的最新版本的压缩包,然后在您的服务器端进行解压,解压完成以后的目录为 (以 Linux/Mac 系统为例):

@ -96,6 +96,12 @@ type picInfo struct {
Pid string `json:"pid"`
}
type SinaError struct {
Retcode string `json:"retcode"`
Reason string `json:"reason"`
}
//Api & upload Json
type ResultJson struct {
Code int `json:"code"`
@ -125,3 +131,17 @@ type DbOption struct {
DblPass string `json:"dbl_pass"`
TablePrefix string `json:"table_prefix"`
}
//User Info Struct
type UserInfo struct {
User string `json:"user"`
Status string `json:"status"`
Code int `json:"code"`
Token string `json:"token"`
Name string `json:"name"`
Avatar string `json:"avatar"`
Introduction string `json:"introduction"`
Roles []string `json:"roles"`
Setting interface{} `json:"setting"`
}

@ -231,7 +231,218 @@ func (v *fileData) UnmarshalJSON(data []byte) error {
func (v *fileData) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll1(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll2(in *jlexer.Lexer, out *UploadConfig) {
func easyjsonB926644bDecodeAuxpiAuxpiAll2(in *jlexer.Lexer, out *UserInfo) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "user":
out.User = string(in.String())
case "status":
out.Status = string(in.String())
case "code":
out.Code = int(in.Int())
case "token":
out.Token = string(in.String())
case "name":
out.Name = string(in.String())
case "avatar":
out.Avatar = string(in.String())
case "introduction":
out.Introduction = string(in.String())
case "roles":
if in.IsNull() {
in.Skip()
out.Roles = nil
} else {
in.Delim('[')
if out.Roles == nil {
if !in.IsDelim(']') {
out.Roles = make([]string, 0, 4)
} else {
out.Roles = []string{}
}
} else {
out.Roles = (out.Roles)[:0]
}
for !in.IsDelim(']') {
var v1 string
v1 = string(in.String())
out.Roles = append(out.Roles, v1)
in.WantComma()
}
in.Delim(']')
}
case "setting":
if m, ok := out.Setting.(easyjson.Unmarshaler); ok {
m.UnmarshalEasyJSON(in)
} else if m, ok := out.Setting.(json.Unmarshaler); ok {
_ = m.UnmarshalJSON(in.Raw())
} else {
out.Setting = in.Interface()
}
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll2(out *jwriter.Writer, in UserInfo) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"user\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.User))
}
{
const prefix string = ",\"status\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Status))
}
{
const prefix string = ",\"code\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Int(int(in.Code))
}
{
const prefix string = ",\"token\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Token))
}
{
const prefix string = ",\"name\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Name))
}
{
const prefix string = ",\"avatar\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Avatar))
}
{
const prefix string = ",\"introduction\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Introduction))
}
{
const prefix string = ",\"roles\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if in.Roles == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v2, v3 := range in.Roles {
if v2 > 0 {
out.RawByte(',')
}
out.String(string(v3))
}
out.RawByte(']')
}
}
{
const prefix string = ",\"setting\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
if m, ok := in.Setting.(easyjson.Marshaler); ok {
m.MarshalEasyJSON(out)
} else if m, ok := in.Setting.(json.Marshaler); ok {
out.Raw(m.MarshalJSON())
} else {
out.Raw(json.Marshal(in.Setting))
}
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v UserInfo) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll2(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v UserInfo) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll2(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *UserInfo) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll2(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *UserInfo) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll2(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll3(in *jlexer.Lexer, out *UploadConfig) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -266,7 +477,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll2(in *jlexer.Lexer, out *UploadConfig) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll2(out *jwriter.Writer, in UploadConfig) {
func easyjsonB926644bEncodeAuxpiAuxpiAll3(out *jwriter.Writer, in UploadConfig) {
out.RawByte('{')
first := true
_ = first
@ -306,27 +517,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll2(out *jwriter.Writer, in UploadConfig)
// MarshalJSON supports json.Marshaler interface
func (v UploadConfig) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll2(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll3(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v UploadConfig) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll2(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll3(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *UploadConfig) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll2(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll3(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *UploadConfig) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll2(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll3(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll3(in *jlexer.Lexer, out *SmResponse) {
func easyjsonB926644bDecodeAuxpiAuxpiAll4(in *jlexer.Lexer, out *SmResponse) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -359,7 +570,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll3(in *jlexer.Lexer, out *SmResponse) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll3(out *jwriter.Writer, in SmResponse) {
func easyjsonB926644bEncodeAuxpiAuxpiAll4(out *jwriter.Writer, in SmResponse) {
out.RawByte('{')
first := true
_ = first
@ -389,27 +600,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll3(out *jwriter.Writer, in SmResponse) {
// MarshalJSON supports json.Marshaler interface
func (v SmResponse) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll3(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll4(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SmResponse) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll3(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll4(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SmResponse) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll3(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll4(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SmResponse) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll3(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll4(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll4(in *jlexer.Lexer, out *SmData) {
func easyjsonB926644bDecodeAuxpiAuxpiAll5(in *jlexer.Lexer, out *SmData) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -460,7 +671,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll4(in *jlexer.Lexer, out *SmData) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll4(out *jwriter.Writer, in SmData) {
func easyjsonB926644bEncodeAuxpiAuxpiAll5(out *jwriter.Writer, in SmData) {
out.RawByte('{')
first := true
_ = first
@ -580,27 +791,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll4(out *jwriter.Writer, in SmData) {
// MarshalJSON supports json.Marshaler interface
func (v SmData) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll4(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll5(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SmData) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll4(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll5(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SmData) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll4(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll5(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SmData) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll4(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll5(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll5(in *jlexer.Lexer, out *SiteConfig) {
func easyjsonB926644bDecodeAuxpiAuxpiAll6(in *jlexer.Lexer, out *SiteConfig) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -655,7 +866,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll5(in *jlexer.Lexer, out *SiteConfig) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll5(out *jwriter.Writer, in SiteConfig) {
func easyjsonB926644bEncodeAuxpiAuxpiAll6(out *jwriter.Writer, in SiteConfig) {
out.RawByte('{')
first := true
_ = first
@ -795,27 +1006,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll5(out *jwriter.Writer, in SiteConfig) {
// MarshalJSON supports json.Marshaler interface
func (v SiteConfig) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll5(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll6(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SiteConfig) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll5(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll6(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SiteConfig) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll5(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll6(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SiteConfig) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll5(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll6(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll6(in *jlexer.Lexer, out *SinaPics) {
func easyjsonB926644bDecodeAuxpiAuxpiAll7(in *jlexer.Lexer, out *SinaPics) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -846,7 +1057,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll6(in *jlexer.Lexer, out *SinaPics) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll6(out *jwriter.Writer, in SinaPics) {
func easyjsonB926644bEncodeAuxpiAuxpiAll7(out *jwriter.Writer, in SinaPics) {
out.RawByte('{')
first := true
_ = first
@ -866,27 +1077,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll6(out *jwriter.Writer, in SinaPics) {
// MarshalJSON supports json.Marshaler interface
func (v SinaPics) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll6(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll7(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SinaPics) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll6(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll7(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SinaPics) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll6(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll7(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SinaPics) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll6(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll7(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll7(in *jlexer.Lexer, out *SinaMsg) {
func easyjsonB926644bDecodeAuxpiAuxpiAll8(in *jlexer.Lexer, out *SinaMsg) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -919,7 +1130,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll7(in *jlexer.Lexer, out *SinaMsg) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll7(out *jwriter.Writer, in SinaMsg) {
func easyjsonB926644bEncodeAuxpiAuxpiAll8(out *jwriter.Writer, in SinaMsg) {
out.RawByte('{')
first := true
_ = first
@ -949,27 +1160,110 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll7(out *jwriter.Writer, in SinaMsg) {
// MarshalJSON supports json.Marshaler interface
func (v SinaMsg) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll7(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll8(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SinaMsg) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll7(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll8(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SinaMsg) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll7(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll8(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SinaMsg) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll7(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll8(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll8(in *jlexer.Lexer, out *SinaData) {
func easyjsonB926644bDecodeAuxpiAuxpiAll9(in *jlexer.Lexer, out *SinaError) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "retcode":
out.Retcode = string(in.String())
case "reason":
out.Reason = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll9(out *jwriter.Writer, in SinaError) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"retcode\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Retcode))
}
{
const prefix string = ",\"reason\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Reason))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v SinaError) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll9(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SinaError) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll9(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SinaError) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll9(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SinaError) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll9(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll10(in *jlexer.Lexer, out *SinaData) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -1004,7 +1298,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll8(in *jlexer.Lexer, out *SinaData) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll8(out *jwriter.Writer, in SinaData) {
func easyjsonB926644bEncodeAuxpiAuxpiAll10(out *jwriter.Writer, in SinaData) {
out.RawByte('{')
first := true
_ = first
@ -1044,27 +1338,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll8(out *jwriter.Writer, in SinaData) {
// MarshalJSON supports json.Marshaler interface
func (v SinaData) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll8(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll10(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v SinaData) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll8(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll10(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *SinaData) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll8(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll10(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *SinaData) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll8(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll10(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll9(in *jlexer.Lexer, out *ResultJson) {
func easyjsonB926644bDecodeAuxpiAuxpiAll11(in *jlexer.Lexer, out *ResultJson) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -1099,7 +1393,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll9(in *jlexer.Lexer, out *ResultJson) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll9(out *jwriter.Writer, in ResultJson) {
func easyjsonB926644bEncodeAuxpiAuxpiAll11(out *jwriter.Writer, in ResultJson) {
out.RawByte('{')
first := true
_ = first
@ -1139,27 +1433,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll9(out *jwriter.Writer, in ResultJson) {
// MarshalJSON supports json.Marshaler interface
func (v ResultJson) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll9(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll11(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v ResultJson) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll9(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll11(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *ResultJson) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll9(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll11(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *ResultJson) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll9(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll11(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll10(in *jlexer.Lexer, out *RespJson) {
func easyjsonB926644bDecodeAuxpiAuxpiAll12(in *jlexer.Lexer, out *RespJson) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -1200,7 +1494,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll10(in *jlexer.Lexer, out *RespJson) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll10(out *jwriter.Writer, in RespJson) {
func easyjsonB926644bEncodeAuxpiAuxpiAll12(out *jwriter.Writer, in RespJson) {
out.RawByte('{')
first := true
_ = first
@ -1246,27 +1540,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll10(out *jwriter.Writer, in RespJson) {
// MarshalJSON supports json.Marshaler interface
func (v RespJson) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll10(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll12(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v RespJson) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll10(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll12(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *RespJson) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll10(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll12(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *RespJson) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll10(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll12(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll11(in *jlexer.Lexer, out *DbOption) {
func easyjsonB926644bDecodeAuxpiAuxpiAll13(in *jlexer.Lexer, out *DbOption) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -1309,7 +1603,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll11(in *jlexer.Lexer, out *DbOption) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll11(out *jwriter.Writer, in DbOption) {
func easyjsonB926644bEncodeAuxpiAuxpiAll13(out *jwriter.Writer, in DbOption) {
out.RawByte('{')
first := true
_ = first
@ -1389,27 +1683,27 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll11(out *jwriter.Writer, in DbOption) {
// MarshalJSON supports json.Marshaler interface
func (v DbOption) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll11(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll13(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v DbOption) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll11(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll13(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *DbOption) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll11(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll13(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *DbOption) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll11(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll13(l, v)
}
func easyjsonB926644bDecodeAuxpiAuxpiAll12(in *jlexer.Lexer, out *Account) {
func easyjsonB926644bDecodeAuxpiAuxpiAll14(in *jlexer.Lexer, out *Account) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -1446,7 +1740,7 @@ func easyjsonB926644bDecodeAuxpiAuxpiAll12(in *jlexer.Lexer, out *Account) {
in.Consumed()
}
}
func easyjsonB926644bEncodeAuxpiAuxpiAll12(out *jwriter.Writer, in Account) {
func easyjsonB926644bEncodeAuxpiAuxpiAll14(out *jwriter.Writer, in Account) {
out.RawByte('{')
first := true
_ = first
@ -1496,23 +1790,23 @@ func easyjsonB926644bEncodeAuxpiAuxpiAll12(out *jwriter.Writer, in Account) {
// MarshalJSON supports json.Marshaler interface
func (v Account) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjsonB926644bEncodeAuxpiAuxpiAll12(&w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll14(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Account) MarshalEasyJSON(w *jwriter.Writer) {
easyjsonB926644bEncodeAuxpiAuxpiAll12(w, v)
easyjsonB926644bEncodeAuxpiAuxpiAll14(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *Account) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjsonB926644bDecodeAuxpiAuxpiAll12(&r, v)
easyjsonB926644bDecodeAuxpiAuxpiAll14(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Account) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjsonB926644bDecodeAuxpiAuxpiAll12(l, v)
easyjsonB926644bDecodeAuxpiAuxpiAll14(l, v)
}

@ -5,6 +5,7 @@ const (
ERROR = 500
INVALID_PARAMS = 400
METHOD_NOT_ALLOWED = 405
FORBIDDEN =403
ERROR_FILE_IS_EMPTY = 10001
ERROR_FILE_IS_TOO_LARGE = 10002

@ -1,10 +0,0 @@
package auxpi
import "github.com/astaxie/beego/logs"
func init() {
logs.SetLogger(logs.AdapterFile,`{"filename":"auxpiRun.log","level":6,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
logs.Async(1e3)
//logs.EnableFuncCallDepth(true)
}

@ -14,12 +14,46 @@ func (this *ApiController) Prepare() {
this.EnableXSRF = false
}
//跨域Option
func (c *ApiController) Options() {
c.AllowCross() //允许跨域
c.Data["json"] = map[string]interface{}{"status": 200, "message": "ok", "moreinfo": ""}
c.ServeJSON()
}
//跨域Allow
func (c *ApiController) AllowCross() {
c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "http://localhost:9527") //允许访问源
c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") //允许post访问
c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization") //header的类型
c.Ctx.ResponseWriter.Header().Set("Access-Control-Max-Age", "1728000")
c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true")
c.Ctx.ResponseWriter.Header().Set("content-type", "application/json") //返回数据格式是json
}
//调试 APi 只有 dev 模式下才能使用
func (this *ApiController) Test() {
data := make(map[string]interface{})
data["_xsrf"] = this.XSRFToken()
resp := &auxpi.RespJson{
200,
"你好世界级",
make(map[string]interface{}),
data,
}
this.Data["json"] = resp
this.ServeJSON()
}
func (this *ApiController) LoginTest() {
this.AllowCross()
data := make(map[string]interface{})
//data["_xsrf"] = this.XSRFToken()
token := "oasu09w4rsdlkfjasod9fuwer"
data["token"] = token
resp := &auxpi.RespJson{
200,
"login",
data,
}
this.Data["json"] = resp
this.ServeJSON()

@ -14,11 +14,13 @@ type Auth struct {
base.ApiController
}
type authInfo struct {
Username string `valid:"Required; MaxSize(32)"`
Password string `valid:"Required; MaxSize(32)"`
Username string `valid:"Required; MaxSize(32)" form:"username"`
Password string `valid:"Required; MaxSize(32)" form:"password"`
}
func (this *Auth) GetAuth() {
func (this *Auth) GetAuthByUserName() {
logs.Alert(this.GetString("username"))
logs.Alert(this.GetString("password"))
info := authInfo{}
code := e.INVALID_PARAMS
if err := this.ParseForm(&info); err != nil {
@ -27,6 +29,7 @@ func (this *Auth) GetAuth() {
}
valid := validation.Validation{}
ok, _ := valid.Valid(&info)
logs.Alert(info)
data := make(map[string]interface{})
if ok {
isExist := models.CheckAuth(info.Username, utils.GetSha256CodeWithSalt(info.Password))
@ -57,3 +60,7 @@ func (this *Auth) GetAuth() {
this.ServeJSON()
}
func (this *Auth) GetAuthByUserEmail() {
}

@ -0,0 +1,22 @@
package api
import "github.com/astaxie/beego"
type Register struct {
//base.ApiController
beego.Controller
}
type registerInfo struct {
//用户名只允许使用字母和数字
Username string `valid:Required;MinSize(6);MaxSize(32);Match(/[a-zA-Z0-9\-_]+/) form:"username"`
Password string `valid:Required;MinSize(6);MaxSize(32) form:"password"`
Email string `valid:Required;Email form"email"`
//TODO :验证码暂时不考虑
//Captcha string `valid:Required;MinSize(4);MaxSize(6)`
}
func register() {
}

@ -0,0 +1,33 @@
package user
import (
"auxpi/auxpiAll"
"auxpi/controllers/api/base"
)
type User struct {
base.ApiController
}
//Need Use Jwt
//admin: {
// roles: ['admin'],
// token: 'admin',
// introduction: '我是超级管理员',
// avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
// name: 'Super Admin'
// }
func (this *User)GetFakerUserInfo() {
role := make([]string,1)
role[0]="admin"
user := &auxpi.UserInfo{}
user.Token = "admin"
user.Introduction= "I am Super Man"
user.Avatar = "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"
user.Name = "Super Man"
user.Code = 200
user.Roles = role
this.Data["json"] = user
this.ServeJSON()
}

@ -3,9 +3,11 @@ package main
import (
_ "auxpi/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
func main() {
logs.SetLogger(logs.AdapterFile,`{"filename":"auxpi.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
beego.Run()
}

@ -0,0 +1,74 @@
package middleware
import (
"auxpi/auxpiAll"
"auxpi/auxpiAll/e"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/utils"
"strings"
)
var (
mCtx *context.Context
)
//自定义 CSRF 错误码返回
var XsrfError = func(ctx *context.Context) {
resp := &auxpi.RespJson{}
code := e.ERROR_ACCESS_DENIED
_xsrf := ctx.Request.Form.Get("_xsrf")
if _xsrf != getXSRFToken(beego.BConfig.WebConfig.XSRFKey, int64(beego.BConfig.WebConfig.XSRFExpire)) {
resp.Code = code
resp.Msg = e.GetMsg(code)
resp.Data = ""
}
ctx.Output.Header("Content-Type", "application/json; charset=UTF-8")
info, _ := resp.MarshalJSON()
ctx.ResponseWriter.Write(info)
return
}
func getXSRFToken(key string, expire int64) string {
beego.Alert(key)
beego.Alert(expire)
token, ok := GetSecureCookie(key, "_xsrf")
if !ok {
token = string(utils.RandomCreateBytes(32))
mCtx.SetSecureCookie(key, "_xsrf", token, expire)
}
return token
}
// GetSecureCookie Get secure cookie from request by a given key.
func GetSecureCookie(Secret, key string) (string, bool) {
val := mCtx.Input.Cookie(key)
if val == "" {
return "", false
}
parts := strings.SplitN(val, "|", 3)
if len(parts) != 3 {
return "", false
}
vs := parts[0]
timestamp := parts[1]
sig := parts[2]
h := hmac.New(sha1.New, []byte(Secret))
fmt.Fprintf(h, "%s%s", vs, timestamp)
if fmt.Sprintf("%02x", h.Sum(nil)) != sig {
return "", false
}
res, _ := base64.URLEncoding.DecodeString(vs)
return string(res), true
}

@ -1,10 +1,15 @@
package auth
import (
"auxpi/controllers/api/auth"
"auxpi/controllers/api/v1/auth"
"github.com/astaxie/beego"
)
func RegisterAuth() {
beego.Router("/auth",&api.Auth{},"post:GetAuth")
}
func RegisterAuth() {
ns :=
beego.NewNamespace("/api/v1",
beego.NSRouter("/auth/login", &api.Auth{}, "post:GetAuthByUserName"),
)
beego.AddNamespace(ns)
}

@ -3,6 +3,7 @@ package v1
import (
"auxpi/bootstrap"
"auxpi/controllers/api"
"auxpi/controllers/webUpload"
"github.com/astaxie/beego"
)
@ -12,8 +13,7 @@ func RegisterOpenApiV1() {
//不需要控制的 api 放到这里
ns :=
beego.NewNamespace("/api/v1",
beego.NSRouter("/web_upload/", &api.ApiUpLoadController{}, "post:UpLoadHandle"),
beego.NSRouter("/web_upload/", &controllers.WebUpLoadController{}, "post:UpLoadHandle"),
)
beego.AddNamespace(ns)
}

@ -7,10 +7,12 @@ package routers
import (
"auxpi/controllers"
"auxpi/controllers/api/base"
"auxpi/controllers/api/v1/user"
"auxpi/middleware"
"auxpi/routers/api/auth"
"auxpi/routers/api/v1"
"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
)
func init() {
@ -19,10 +21,13 @@ func init() {
beego.Router("/Sina", &page.PagesController{}, "get:SinaShow")
beego.Router("/Smms", &page.PagesController{}, "get:SmmsShow")
beego.Router("/about", &page.PagesController{}, "get:AboutShow")
//auth
auth.RegisterAuth()
//dev 模式会打开测试路由方便调试
if beego.BConfig.RunMode == "dev" {
//auth
auth.RegisterAuth()
//Vue 调试的时候需要跨域 ()
setCors()
//部分需要调试的路由
testRouter()
}
@ -30,11 +35,27 @@ func init() {
v1.RegisterControlApiV1()
v1.RegisterOpenApiV1()
//v2 版本路由注册
}
//测试路由,不要随便开启
func testRouter() {
beego.InsertFilter("/test", beego.BeforeRouter, middleware.JWT)
beego.InsertFilter("/api/v1/test/user_info", beego.BeforeRouter, middleware.JWT)
beego.Router("/test", &base.ApiController{}, "post:Test")
beego.Router("/auth/login", &base.ApiController{}, "post:LoginTest")
beego.Router("/api/v1/test/user_info",&user.User{},"get:GetFakerUserInfo")
}
//跨域设置
func setCors() {
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"http://localhost:9527"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type","X-Token"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
AllowCredentials: true,
}))
//Vue 跨域请求,需要允许跨域
beego.Router("*", &base.ApiController{}, "options:Options")
}

@ -6,6 +6,7 @@ import (
"encoding/base64"
"fmt"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/logs"
"hash/crc32"
"io/ioutil"
"net/http"
@ -64,6 +65,12 @@ func (this *Sina) getCookies(durl string, data map[string]string) (interface{})
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(request)
body,_ := ioutil.ReadAll(resp.Body)
sinaError := &auxpi.SinaError{}
sinaError.UnmarshalJSON(body)
if sinaError.Retcode == "101" {
logs.Alert("新浪图床上传错误:"+sinaError.Reason)
}
defer resp.Body.Close()
cookie := resp.Cookies()
//缓存 Cookie 缓存一个小时

Loading…
Cancel
Save