Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
14853cbb
Commit
14853cbb
authored
Dec 13, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
849f944f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
183 additions
and
35 deletions
+183
-35
app.ini
conf/app.ini
+2
-1
auth.go
models/auth.go
+4
-0
explore_app_category.go
models/explore_app_category.go
+54
-0
code.go
pkg/e/code.go
+9
-0
setting.go
pkg/setting/setting.go
+1
-0
jwt.go
pkg/util/jwt.go
+16
-13
auth.go
routers/api/auth.go
+1
-1
explore_app_category.go
routers/api/v1/explore_app_category.go
+48
-0
router.go
routers/router.go
+22
-20
category.go
service/explore_service/category.go
+26
-0
No files found.
conf/app.ini
View file @
14853cbb
[app]
[app]
PageSize
=
10
PageSize
=
10
JwtSecret
=
233
JwtSecret
=
bwallet
Timeout
=
60 * 60 * 24
PrefixUrl
=
http://127.0.0.1:8983
PrefixUrl
=
http://127.0.0.1:8983
RuntimeRootPath
=
runtime/
RuntimeRootPath
=
runtime/
...
...
models/auth.go
View file @
14853cbb
...
@@ -8,6 +8,10 @@ type Auth struct {
...
@@ -8,6 +8,10 @@ type Auth struct {
Password
string
`json:"password"`
Password
string
`json:"password"`
}
}
func
(
a
Auth
)
TableName
()
string
{
return
"coin_user"
}
func
CheckAuth
(
username
,
password
string
)
(
bool
,
error
)
{
func
CheckAuth
(
username
,
password
string
)
(
bool
,
error
)
{
var
auth
Auth
var
auth
Auth
err
:=
db
.
Select
(
"id"
)
.
Where
(
Auth
{
Username
:
username
,
Password
:
password
})
.
First
(
&
auth
)
.
Error
err
:=
db
.
Select
(
"id"
)
.
Where
(
Auth
{
Username
:
username
,
Password
:
password
})
.
First
(
&
auth
)
.
Error
...
...
models/explore_app_category.go
0 → 100644
View file @
14853cbb
package
models
import
"github.com/jinzhu/gorm"
type
ExploreAppCategory
struct
{
ID
uint64
`gorm:"primary_key;auto_increment" json:"id"`
Name
string
`gorm:"size:255;not null;" json:"name"`
Sort
uint32
`gorm:"not null;default:1" json:"sort"`
Limit
uint32
`gorm:"not null;default:1" json:"limit"`
Style
uint32
`gorm:"not null;default:1" json:"style"`
Status
uint8
`gorm:"not null;default:1" json:"status"`
PlatformId
uint64
`gorm:"not null;default:0" json:"platform_id"`
}
/**
* 通过id检查类别是否存在
* @param id
* @return
*/
func
ExistCategoryById
(
id
int
)
(
bool
,
error
)
{
var
category
ExploreAppCategory
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
category
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
/**
* 通过id获取指定类别信息
* @param id
* @return
*/
func
GetCategory
(
id
int
)
(
*
ExploreAppCategory
,
error
)
{
var
category
ExploreAppCategory
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
category
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
category
,
nil
}
pkg/e/code.go
View file @
14853cbb
...
@@ -26,6 +26,15 @@ const (
...
@@ -26,6 +26,15 @@ const (
ERROR_GET_ARTICLE_FAIL
=
10018
ERROR_GET_ARTICLE_FAIL
=
10018
ERROR_GEN_ARTICLE_POSTER_FAIL
=
10019
ERROR_GEN_ARTICLE_POSTER_FAIL
=
10019
ERROR_NOT_EXIST_CATEGORY
=
10011
ERROR_CHECK_EXIST_CATEGORY_FAIL
=
10012
ERROR_ADD_CATEGORY_FAIL
=
10013
ERROR_DELETE_CATEGORY_FAIL
=
10014
ERROR_EDIT_CATEGORY_FAIL
=
10015
ERROR_COUNT_CATEGORY_FAIL
=
10016
ERROR_GET_CATEGORIES_FAIL
=
10017
ERROR_GET_CATEGORY_FAIL
=
10018
ERROR_AUTH_CHECK_TOKEN_FAIL
=
40001
ERROR_AUTH_CHECK_TOKEN_FAIL
=
40001
ERROR_AUTH_CHECK_TOKEN_TIMEOUT
=
40002
ERROR_AUTH_CHECK_TOKEN_TIMEOUT
=
40002
ERROR_AUTH_TOKEN
=
40003
ERROR_AUTH_TOKEN
=
40003
...
...
pkg/setting/setting.go
View file @
14853cbb
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
type
App
struct
{
type
App
struct
{
JwtSecret
string
JwtSecret
string
PageSize
int
PageSize
int
Timeout
int
PrefixUrl
string
PrefixUrl
string
RuntimeRootPath
string
RuntimeRootPath
string
...
...
pkg/util/jwt.go
View file @
14853cbb
...
@@ -3,6 +3,7 @@ package util
...
@@ -3,6 +3,7 @@ package util
import
(
import
(
"github.com/dgrijalva/jwt-go"
"github.com/dgrijalva/jwt-go"
"time"
"time"
"bwallet/pkg/setting"
)
)
var
jwtSecret
[]
byte
var
jwtSecret
[]
byte
...
@@ -14,17 +15,19 @@ type Claims struct {
...
@@ -14,17 +15,19 @@ type Claims struct {
}
}
func
GenerateToken
(
username
,
password
string
)
(
string
,
error
)
{
func
GenerateToken
(
username
,
password
string
)
(
string
,
error
)
{
nowTime
:=
time
.
Now
()
//nowTime := time.Now()
expireTime
:=
nowTime
.
Add
(
3
*
time
.
Hour
)
//expireTime := nowTime.Add(3 * time.Hour)
expiresTime
:=
time
.
Now
()
.
Unix
()
+
int64
(
60
*
60
*
24
)
claims
:=
Claims
{
EncodeMD5
(
username
),
claims
:=
jwt
.
StandardClaims
{
EncodeMD5
(
password
),
Audience
:
username
,
jwt
.
StandardClaims
{
ExpiresAt
:
expiresTime
,
ExpiresAt
:
expireTime
.
Unix
(),
IssuedAt
:
time
.
Now
()
.
Unix
(),
Issuer
:
"bwallet"
,
Issuer
:
"bwallet"
,
},
NotBefore
:
time
.
Now
()
.
Unix
(),
Subject
:
"login"
,
}
}
var
jwtSecret
=
[]
byte
(
setting
.
AppSetting
.
JwtSecret
)
tokenClaims
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
claims
)
tokenClaims
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
claims
)
token
,
err
:=
tokenClaims
.
SignedString
(
jwtSecret
)
token
,
err
:=
tokenClaims
.
SignedString
(
jwtSecret
)
...
@@ -32,13 +35,13 @@ func GenerateToken(username, password string) (string, error) {
...
@@ -32,13 +35,13 @@ func GenerateToken(username, password string) (string, error) {
return
token
,
err
return
token
,
err
}
}
func
ParseToken
(
token
string
)
(
*
Claims
,
error
)
{
func
ParseToken
(
token
string
)
(
*
Claims
,
error
)
{
tokenClaims
,
err
:=
jwt
.
ParseWithClaims
(
token
,
&
Claims
{},
func
(
token
*
jwt
.
Token
)(
interface
{},
error
)
{
tokenClaims
,
err
:=
jwt
.
ParseWithClaims
(
token
,
&
Claims
{},
func
(
token
*
jwt
.
Token
)
(
interface
{},
error
)
{
return
jwtSecret
,
nil
return
jwtSecret
,
nil
})
})
if
tokenClaims
!=
nil
{
if
tokenClaims
!=
nil
{
if
claims
,
ok
:=
tokenClaims
.
Claims
.
(
*
Claims
);
ok
&&
tokenClaims
.
Valid
{
if
claims
,
ok
:=
tokenClaims
.
Claims
.
(
*
Claims
);
ok
&&
tokenClaims
.
Valid
{
return
claims
,
nil
return
claims
,
nil
}
}
}
}
...
...
routers/api/auth.go
View file @
14853cbb
...
@@ -15,7 +15,7 @@ type auth struct {
...
@@ -15,7 +15,7 @@ type auth struct {
Password
string
`valid:"Required; MaxSize(50)"`
Password
string
`valid:"Required; MaxSize(50)"`
}
}
func
GetAuth
(
c
*
gin
.
Context
){
func
GetAuth
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
appG
:=
app
.
Gin
{
C
:
c
}
valid
:=
validation
.
Validation
{}
valid
:=
validation
.
Validation
{}
...
...
routers/api/v1/explore_app_category.go
0 → 100644
View file @
14853cbb
package
v1
import
(
"github.com/gin-gonic/gin"
"bwallet/pkg/app"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"net/http"
"bwallet/pkg/e"
"bwallet/service/explore_service"
)
/**
* 通过id获取指定类别信息
* @return
*/
func
GetCategory
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
if
valid
.
HasErrors
()
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
categoryService
:=
explore_service
.
Category
{
Id
:
id
}
exists
,
err
:=
categoryService
.
ExistById
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_CATEGORY_FAIL
,
nil
)
return
}
if
!
exists
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR_NOT_EXIST_CATEGORY
,
nil
)
return
}
category
,
err
:=
categoryService
.
Get
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_CHECK_EXIST_ARTICLE_FAIL
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
category
)
}
routers/router.go
View file @
14853cbb
...
@@ -24,28 +24,30 @@ func InitRouter() *gin.Engine {
...
@@ -24,28 +24,30 @@ func InitRouter() *gin.Engine {
r
.
POST
(
"/auth"
,
api
.
GetAuth
)
r
.
POST
(
"/auth"
,
api
.
GetAuth
)
r
.
POST
(
"/upload"
,
api
.
UploadImage
)
r
.
POST
(
"/upload"
,
api
.
UploadImage
)
api
v1
:=
r
.
Group
(
"/api"
)
api
:=
r
.
Group
(
"/api"
)
api
v1
.
Use
(
jwt
.
JWT
())
api
.
Use
(
jwt
.
JWT
())
{
{
apiv1
.
GET
(
"/coins"
,
v1
.
GetCoins
)
api
.
GET
(
"/explore-app/category-update/:id"
,
v1
.
GetCategory
)
apiv1
.
POST
(
"/coin"
,
v1
.
AddCoin
)
apiv1
.
GET
(
"/coin/:id"
,
v1
.
GetCoin
)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
apiv1
.
PUT
(
"/coin/:id"
,
v1
.
EditCoin
)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
apiv1
.
DELETE
(
"/coin/:id"
,
v1
.
DeleteCoin
)
api
.
GET
(
"/coin/:id"
,
v1
.
GetCoin
)
apiv1
.
GET
(
"/get-platform"
,
v1
.
GetCoinsPlatform
)
api
.
PUT
(
"/coin/:id"
,
v1
.
EditCoin
)
api
.
DELETE
(
"/coin/:id"
,
v1
.
DeleteCoin
)
apiv1
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
api
.
GET
(
"/get-platform"
,
v1
.
GetCoinsPlatform
)
apiv1
.
POST
(
"/wallet"
,
v1
.
AddWallet
)
apiv1
.
GET
(
"/wallet/:id"
,
v1
.
GetWallet
)
api
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
apiv1
.
PUT
(
"/wallet/:id"
,
v1
.
EditWallet
)
api
.
POST
(
"/wallet"
,
v1
.
AddWallet
)
apiv1
.
DELETE
(
"/wallet/:id"
,
v1
.
DeleteWallet
)
api
.
GET
(
"/wallet/:id"
,
v1
.
GetWallet
)
api
.
PUT
(
"/wallet/:id"
,
v1
.
EditWallet
)
apiv1
.
GET
(
"/coins-recommend"
,
v1
.
GetCoinsRecommend
)
api
.
DELETE
(
"/wallet/:id"
,
v1
.
DeleteWallet
)
apiv1
.
POST
(
"/coin-recommend"
,
v1
.
AddCoinRecommend
)
apiv1
.
GET
(
"/coin-recommend/:id"
,
v1
.
GetCoinRecommend
)
api
.
GET
(
"/coins-recommend"
,
v1
.
GetCoinsRecommend
)
apiv1
.
PUT
(
"/coin-recommend/:id"
,
v1
.
EditCoinRecommend
)
api
.
POST
(
"/coin-recommend"
,
v1
.
AddCoinRecommend
)
apiv1
.
DELETE
(
"/coin-recommend/:id"
,
v1
.
DeleteCoinRecommend
)
api
.
GET
(
"/coin-recommend/:id"
,
v1
.
GetCoinRecommend
)
api
.
PUT
(
"/coin-recommend/:id"
,
v1
.
EditCoinRecommend
)
api
.
DELETE
(
"/coin-recommend/:id"
,
v1
.
DeleteCoinRecommend
)
}
}
return
r
return
r
...
...
service/explore_service/category.go
0 → 100644
View file @
14853cbb
package
explore_service
import
"bwallet/models"
type
Category
struct
{
Id
int
Name
string
Sort
int
Limit
int
Style
int
Status
int
PlatformId
int
}
func
(
c
*
Category
)
Get
()
(
*
models
.
ExploreAppCategory
,
error
)
{
category
,
err
:=
models
.
GetCategory
(
c
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
return
category
,
nil
}
func
(
c
*
Category
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistCategoryById
(
c
.
Id
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment