This commit is contained in:
crusader 2018-04-11 13:35:29 +09:00
parent 882a1dddf3
commit d38999da2b
2 changed files with 19 additions and 17 deletions

View File

@ -1,7 +1,7 @@
package: git.loafle.net/overflow/member_gateway_rest
import:
- package: git.loafle.net/commons/server-go
- package: git.loafle.net/commons/rpc-go
- package: git.loafle.net/commons/rest-go
- package: git.loafle.net/overflow/central_api
- package: google.golang.org/grpc
version: ^1.11.2

View File

@ -57,14 +57,20 @@ type MemberService struct {
_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]')"`
_EmailConfirm cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='GET', entry='/account/email_confirm', params='[token]')"`
}
func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, signinID string, signinPW string) error {
func (ms *MemberService) EmailConfirm(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, token string) ([]byte, error) {
return nil, nil
}
func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, signinID string, signinPW string) ([]byte, error) {
gRPCCtx := context.Background()
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", signinID, signinPW)
if nil != err {
return err
return nil, err
}
token := jwt.New(jwt.SigningMethodRS512)
@ -84,13 +90,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 nil, err
}
var domainMember interface{}
err = json.Unmarshal([]byte(r), &domainMember)
if nil != err {
return err
return nil, err
}
signInResult := &SignInResult{
@ -100,15 +106,13 @@ func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.Requ
buf, err := json.Marshal(signInResult)
if nil != err {
return err
return nil, err
}
ctx.SetBody(buf)
return nil
return buf, nil
}
func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, authToken string) error {
func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, authToken string) ([]byte, error) {
token, err := jwt.Parse(authToken, func(token *jwt.Token) (interface{}, error) {
// Don't forget to validate the alg is what you expect:
@ -120,14 +124,14 @@ func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasth
return verifyKey, nil
})
if nil != err {
return err
return nil, 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 nil, fmt.Errorf("authToken is not valid")
}
params := []string{claims["sub"].(string)}
@ -135,14 +139,12 @@ func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasth
gRPCCtx := context.Background()
r, err := grpc.Exec(gRPCCtx, "DomainMemberService.readByMemberEmail", params...)
ctx.SetBody([]byte(r))
return err
return []byte(r), err
}
func (ms *MemberService) Signup(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) error {
func (ms *MemberService) Signup(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) ([]byte, error) {
return nil
return nil, nil
}
type SignInResult struct {