Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
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
ligaishun
chain33-pai
Commits
466eb331
Commit
466eb331
authored
Oct 11, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add stat_service
parent
9c84ca8d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
64 deletions
+35
-64
auth.go
routers/api/auth.go
+0
-64
rasp_miner_stat.go
service/stat_service/rasp_miner_stat.go
+35
-0
No files found.
routers/api/auth.go
deleted
100644 → 0
View file @
9c84ca8d
package
api
import
(
"net/http"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"chain33-pai/pkg/app"
"chain33-pai/pkg/e"
"chain33-pai/pkg/util"
"chain33-pai/service/auth_service"
)
type
auth
struct
{
Username
string
`valid:"Required; MaxSize(50)"`
Password
string
`valid:"Required; MaxSize(50)"`
}
// @Summary Get Auth
// @Produce json
// @Param username query string true "userName"
// @Param password query string true "password"
// @Success 200 {object} app.Response
// @Failure 500 {object} app.Response
// @Router /auth [get]
func
GetAuth
(
c
*
gin
.
Context
)
{
appG
:=
app
.
Gin
{
C
:
c
}
valid
:=
validation
.
Validation
{}
username
:=
c
.
Query
(
"username"
)
password
:=
c
.
Query
(
"password"
)
a
:=
auth
{
Username
:
username
,
Password
:
password
}
ok
,
_
:=
valid
.
Valid
(
&
a
)
if
!
ok
{
app
.
MarkErrors
(
valid
.
Errors
)
appG
.
Response
(
http
.
StatusBadRequest
,
e
.
INVALID_PARAMS
,
nil
)
return
}
authService
:=
auth_service
.
Auth
{
Username
:
username
,
Password
:
password
}
isExist
,
err
:=
authService
.
Check
()
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_CHECK_TOKEN_FAIL
,
nil
)
return
}
if
!
isExist
{
appG
.
Response
(
http
.
StatusUnauthorized
,
e
.
ERROR_AUTH
,
nil
)
return
}
token
,
err
:=
util
.
GenerateToken
(
username
,
password
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusInternalServerError
,
e
.
ERROR_AUTH_TOKEN
,
nil
)
return
}
appG
.
Response
(
http
.
StatusOK
,
e
.
SUCCESS
,
map
[
string
]
string
{
"token"
:
token
,
})
}
service/stat_service/rasp_miner_stat.go
0 → 100644
View file @
466eb331
package
stat_service
import
(
"chain33-pai/models"
)
type
RaspMinerStat
struct
{
Addr
string
`json:"addr"`
MinedAmount
int64
`json:"mined_amount"`
Height
int64
`json:"height"`
Time
int64
`json:"time"`
}
func
(
s
*
RaspMinerStat
)
GetMinerStat
(
addr
string
)
(
*
models
.
RaspMinerStat
,
error
)
{
return
models
.
GetAddr
(
addr
)
}
func
(
s
*
RaspMinerStat
)
SetMineTime
(
addr
string
,
start
,
end
int64
)
error
{
stat
,
err
:=
models
.
GetAddr
(
addr
)
if
err
!=
nil
{
return
err
}
m
:=
map
[
string
]
interface
{}{
"miner_start_time"
:
start
,
"miner_end_time"
:
end
}
if
stat
.
MinerStartTime
<=
0
{
m
[
"miner_start_time"
]
=
start
m
[
"miner_end_time"
]
=
0
}
if
stat
.
MinerStartTime
>
0
&&
stat
.
MinerEndTime
<=
0
{
m
[
"miner_start_time"
]
=
stat
.
MinerStartTime
m
[
"miner_end_time"
]
=
end
}
return
models
.
EditAddr
(
addr
,
m
)
}
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