This commit is contained in:
crusader 2018-04-11 15:05:09 +09:00
parent d38999da2b
commit 569fd06729

View File

@ -60,17 +60,28 @@ type MemberService struct {
_EmailConfirm cda.MethodAnnotation `annotation:"@overflow:RequestMapping(method='GET', entry='/account/email_confirm', params='[token]')"` _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() gRPCCtx := context.Background()
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", signinID, signinPW) r, err := grpc.Exec(gRPCCtx, "MemberService.signin", signinID, signinPW)
if nil != err { if nil != err {
return nil, err return err
} }
token := jwt.New(jwt.SigningMethodRS512) 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 */ /* Sign the token with our secret */
tokenString, err := token.SignedString(signKey) tokenString, err := token.SignedString(signKey)
if nil != err { if nil != err {
return nil, err return err
} }
var domainMember interface{} var domainMember interface{}
err = json.Unmarshal([]byte(r), &domainMember) err = json.Unmarshal([]byte(r), &domainMember)
if nil != err { if nil != err {
return nil, err return err
} }
signInResult := &SignInResult{ signInResult := &SigninResult{
AuthToken: tokenString, AuthToken: tokenString,
DomainMember: domainMember, DomainMember: domainMember,
} }
buf, err := json.Marshal(signInResult) buf, err := json.Marshal(signInResult)
if nil != err { 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) { token, err := jwt.Parse(authToken, func(token *jwt.Token) (interface{}, error) {
// Don't forget to validate the alg is what you expect: // 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 return verifyKey, nil
}) })
if nil != err { if nil != err {
return nil, err return err
} }
var ok bool var ok bool
var claims jwt.MapClaims var claims jwt.MapClaims
if claims, ok = token.Claims.(jwt.MapClaims); !ok || !token.Valid { if claims, ok = token.Claims.(jwt.MapClaims); !ok || !token.Valid {
logging.Logger().Warnf("Token is not valid %v", token) 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)} params := []string{claims["sub"].(string)}
gRPCCtx := context.Background() gRPCCtx := context.Background()
r, err := grpc.Exec(gRPCCtx, "DomainMemberService.readByMemberEmail", params...) 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 return nil
}
type SignInResult struct {
AuthToken string `json:"authToken"`
DomainMember interface{} `json:"domainMember"`
} }