forgot password

This commit is contained in:
geek 2017-08-31 19:23:38 +09:00
parent 6724e5841b
commit 4f60a512ab
2 changed files with 44 additions and 21 deletions

41
main.go
View File

@ -6,14 +6,19 @@ import (
"git.loafle.net/overflow/overflow_server_app/backend"
"git.loafle.net/overflow/overflow_server_app/module/member"
"git.loafle.net/overflow/overflow_server_app/server"
"git.loafle.net/commons_go/cors_fasthttp"
grpcAPI "git.loafle.net/overflow/overflow_api_server/golang"
"github.com/valyala/fasthttp"
"google.golang.org/grpc"
)
func main() {
ctx := context.Background()
c := cors_fasthttp.AllowAll(ctx)
s := server.New()
grpcPool, err := backend.NewPool(backend.Options{
@ -47,24 +52,24 @@ func main() {
s.SetContextValue("grpc", grpcPool)
s.Route("POST", "/account/signin", CORS(member.SignIn))
s.Route("POST", "/account/signup", CORS(member.SignUp))
s.Route("POST", "/account/forgot_password", CORS(member.ForgotPassword))
s.Route("POST", "/account/reset_password", CORS(member.ResetPassword))
s.Route("GET", "/account/check_email", CORS(member.CheckEmail))
s.Route("POST", "/account/signin", member.SignIn)
s.Route("POST", "/account/signup", member.SignUp)
s.Route("POST", "/account/forgot_password", member.ForgotPassword)
s.Route("POST", "/account/reset_password", member.ResetPassword)
s.Route("GET", "/account/check_email", member.CheckEmail)
fasthttp.ListenAndServe(":19080", s.Handler)
fasthttp.ListenAndServe(":19080", c.Handler(s.Handler))
}
func CORS(next server.RequestHandler) server.RequestHandler {
return server.RequestHandler(func(sctx *server.ServerContext, ctx * fasthttp.RequestCtx) {
ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true" )
ctx.Response.Header.Set("Access-Control-Allow-Headers", "authorization")
ctx.Response.Header.Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,DELETE,OPTIONS" )
ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
next(sctx, ctx)
})
}
//
//func CORS(next server.RequestHandler) server.RequestHandler {
// return server.RequestHandler(func(sctx *server.ServerContext, ctx * fasthttp.RequestCtx) {
//
// ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true" )
// ctx.Response.Header.Set("Access-Control-Allow-Headers", "authorization")
// ctx.Response.Header.Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,DELETE,OPTIONS" )
// ctx.Response.Header.Set("Access-Control-Allow-Origin", "*")
//
// next(sctx, ctx)
// })
//}

View File

@ -7,6 +7,7 @@ import (
"github.com/valyala/fasthttp"
"git.loafle.net/overflow/overflow_server_app/backend"
"encoding/json"
)
func ForgotPassword(sctx *server.ServerContext, ctx *fasthttp.RequestCtx) {
@ -23,12 +24,29 @@ func ForgotPassword(sctx *server.ServerContext, ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "avail: %d\n", grpcPool.Available())
signinId := string(ctx.FormValue("signinId"))
//signinId := ctx.QueryArgs().Peek("signinId")
//signinId := string(ctx.FormValue("signinId"))
//tt := ctx.PostArgs().Peek("signinId")
//fmt.Println(string(tt))
signinId := ctx.PostBody()
fmt.Println(signinId)
params := []string{signinId}
data := make(map[string]interface{})
err = json.Unmarshal(signinId, &data)
if err != nil {
fmt.Fprintf(ctx, "Err!!!!: %s\n", err)
}
params := []string{data["signinId"].(string)}
r, err := c.Exec("MemberService", "sendEmailForPassword", params)
jData,_ := json.Marshal(r)
fmt.Println(r)
ctx.Response.Header.Set("Content-Type", "application/json")
ctx.Write(jData)
//gg, err := ctx.Response.BodyWriter().Write(jData)
//fmt.Println(gg)
fmt.Println(err)
fmt.Fprintf(ctx, "Confirm Email!!!!: %s\n", r)
}