ing
This commit is contained in:
parent
a658ab86c5
commit
882a1dddf3
|
@ -3,8 +3,6 @@ package server
|
|||
import (
|
||||
cdr "git.loafle.net/commons/di-go/registry"
|
||||
"git.loafle.net/commons/logging-go"
|
||||
crpj "git.loafle.net/commons/rpc-go/protocol/json"
|
||||
crr "git.loafle.net/commons/rpc-go/registry"
|
||||
cswf "git.loafle.net/commons/server-go/web/fasthttp"
|
||||
oca "git.loafle.net/overflow/commons-go/annotation"
|
||||
"git.loafle.net/overflow/member_gateway_rest/config"
|
||||
|
@ -12,23 +10,16 @@ import (
|
|||
)
|
||||
|
||||
func NewServer(_config *config.Config) *cswf.Server {
|
||||
serverCodec := crpj.NewServerCodec()
|
||||
rpcRegistry := crr.NewRPCRegistry()
|
||||
|
||||
services, err := cdr.GetInstancesByAnnotationType(oca.ServiceAnnotationType)
|
||||
services, err := cdr.GetInstancesByAnnotationType(oca.RESTServiceAnnotationType)
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
for _, _service := range services {
|
||||
if err := rpcRegistry.RegisterService(_service, ""); nil != err {
|
||||
webappS := &servlet.WebappServlets{}
|
||||
if err := webappS.RegisterRESTServices(services); nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
webappS := &servlet.WebappServlets{}
|
||||
webappS.ServerCodec = serverCodec
|
||||
webappS.RPCInvoker = rpcRegistry
|
||||
|
||||
sh := &ServerHandlers{
|
||||
ServerHandlers: *_config.ServerHandler,
|
||||
|
|
|
@ -52,15 +52,19 @@ func init() {
|
|||
}
|
||||
|
||||
type MemberService struct {
|
||||
cda.TypeAnnotation `annotation:"@overflow:Service()"`
|
||||
cda.TypeAnnotation `annotation:"@overflow:RESTService()"`
|
||||
|
||||
_Signin cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='POST', entry='/account/signin', params='[signinID, signinPW]')"`
|
||||
_SigninByCookie cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='POST', entry='/account/signin_cookie', params='[authToken]')"`
|
||||
_Signup cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='POST', entry='/account/signup', params='[member]')"`
|
||||
}
|
||||
|
||||
func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, signinID string, signinPW string) (string, error) {
|
||||
func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, signinID string, signinPW string) error {
|
||||
|
||||
gRPCCtx := context.Background()
|
||||
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", signinID, signinPW)
|
||||
if nil != err {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
token := jwt.New(jwt.SigningMethodRS512)
|
||||
|
@ -80,13 +84,13 @@ func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.Requ
|
|||
/* Sign the token with our secret */
|
||||
tokenString, err := token.SignedString(signKey)
|
||||
if nil != err {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
var domainMember interface{}
|
||||
err = json.Unmarshal([]byte(r), &domainMember)
|
||||
if nil != err {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
signInResult := &SignInResult{
|
||||
|
@ -96,13 +100,15 @@ func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.Requ
|
|||
|
||||
buf, err := json.Marshal(signInResult)
|
||||
if nil != err {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
return string(buf), nil
|
||||
ctx.SetBody(buf)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, authToken string) (string, error) {
|
||||
func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, authToken string) error {
|
||||
|
||||
token, err := jwt.Parse(authToken, func(token *jwt.Token) (interface{}, error) {
|
||||
// Don't forget to validate the alg is what you expect:
|
||||
|
@ -114,14 +120,14 @@ func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasth
|
|||
return verifyKey, nil
|
||||
})
|
||||
if nil != err {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
var ok bool
|
||||
var claims jwt.MapClaims
|
||||
if claims, ok = token.Claims.(jwt.MapClaims); !ok || !token.Valid {
|
||||
logging.Logger().Warnf("Token is not valid %v", token)
|
||||
return "", fmt.Errorf("authToken is not valid")
|
||||
return fmt.Errorf("authToken is not valid")
|
||||
}
|
||||
|
||||
params := []string{claims["sub"].(string)}
|
||||
|
@ -129,12 +135,14 @@ func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasth
|
|||
gRPCCtx := context.Background()
|
||||
r, err := grpc.Exec(gRPCCtx, "DomainMemberService.readByMemberEmail", params...)
|
||||
|
||||
return r, err
|
||||
ctx.SetBody([]byte(r))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (ms *MemberService) Register(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) (string, error) {
|
||||
func (ms *MemberService) Signup(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) error {
|
||||
|
||||
return "dkfksddfk", nil
|
||||
return nil
|
||||
}
|
||||
|
||||
type SignInResult struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user