func RefreshToken(w http.ResponseWriter, r *http.Request) { userID := context.Get(r, "user_id").(uint64) token := context.Get(r, "user_token").(string) var reqBody authorizePutBody if appErr := decode(r, &reqBody); appErr != nil { reply.Err(w, appErr) return } userToken := model.UserToken{UserID: userID, Token: token, RefreshToken: reqBody.RefreshToken} if valid, err := userToken.RefreshTokenValid(); !valid || err != nil { if !valid { reply.Err(w, ae.TokenInvalid("", err, "refresh_token")) } else { reply.Err(w, ae.DB("", err)) } return } if err := userToken.Delete(); err != nil { reply.Err(w, ae.DB("", err)) return } newToken := model.UserToken{UserID: userID} if err := newToken.Add(); err != nil { reply.Err(w, ae.DB("", err)) return } reply.OK(w, newToken) }
func SignOut(w http.ResponseWriter, r *http.Request) { userToken := model.UserToken{} userToken.Token = context.Get(r, "user_token").(string) if err := userToken.GetUserIdFromToken(); err != nil { reply.Err(w, ae.DB("", err)) return } if err := userToken.Delete(); err != nil { reply.Err(w, ae.DB("", err)) return } reply.OK(w, userToken) }