From 569fd067299ff021e4d377fcb1038ee3a58dd827 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 11 Apr 2018 15:05:09 +0900 Subject: [PATCH] ing --- service/member-service.go | 53 ++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/service/member-service.go b/service/member-service.go index 112b182..1e31c00 100644 --- a/service/member-service.go +++ b/service/member-service.go @@ -60,17 +60,28 @@ type MemberService struct { _EmailConfirm cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='GET', entry='/account/email_confirm', params='[token]')"` } -func (ms *MemberService) EmailConfirm(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, token string) ([]byte, error) { +func (ms *MemberService) EmailConfirm(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, token string) error { + var c fasthttp.Cookie + c.SetKey("cookie-name") + c.SetValue("cookie-value") + ctx.Response.Header.SetCookie(&c) - return nil, nil + ctx.SetBody([]byte("DDDDDDD")) + + return nil } -func (ms *MemberService) Signin(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, signinID string, signinPW string) ([]byte, error) { +type SigninResult struct { + AuthToken string `json:"authToken"` + DomainMember interface{} `json:"domainMember"` +} + +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 nil, err + return err } token := jwt.New(jwt.SigningMethodRS512) @@ -90,29 +101,31 @@ 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 nil, err + return err } var domainMember interface{} err = json.Unmarshal([]byte(r), &domainMember) if nil != err { - return nil, err + return err } - signInResult := &SignInResult{ + signInResult := &SigninResult{ AuthToken: tokenString, DomainMember: domainMember, } buf, err := json.Marshal(signInResult) if nil != err { - return nil, err + return err } - return buf, nil + ctx.SetBody(buf) + + return nil } -func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, authToken string) ([]byte, 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: @@ -124,30 +137,30 @@ func (ms *MemberService) SigninByCookie(servletCtx server.ServletCtx, ctx *fasth return verifyKey, nil }) if nil != err { - return nil, 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 nil, fmt.Errorf("authToken is not valid") + return fmt.Errorf("authToken is not valid") } params := []string{claims["sub"].(string)} gRPCCtx := context.Background() r, err := grpc.Exec(gRPCCtx, "DomainMemberService.readByMemberEmail", params...) + if nil != err { + return err + } - return []byte(r), err + ctx.SetBody([]byte(r)) + + return nil } -func (ms *MemberService) Signup(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) ([]byte, error) { +func (ms *MemberService) Signup(servletCtx server.ServletCtx, ctx *fasthttp.RequestCtx, id string, pw string) error { - return nil, nil -} - -type SignInResult struct { - AuthToken string `json:"authToken"` - DomainMember interface{} `json:"domainMember"` + return nil }