diff --git a/editor/editors.go b/editor/editors.go index 64c0e85..f7b3536 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -106,7 +106,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -125,7 +125,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -135,7 +135,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { if err := fout.Close(); nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -168,7 +168,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { output, err := cmd.CombinedOutput() if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -188,7 +188,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -233,7 +233,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) { output, err := cmd.CombinedOutput() if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -264,7 +264,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { var args map[string]interface{} if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -309,7 +309,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { output, err := cmd.CombinedOutput() if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -353,7 +353,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -397,7 +397,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { output, err := cmd.CombinedOutput() if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/main.go b/main.go index 386fbba..5b10d1a 100644 --- a/main.go +++ b/main.go @@ -150,6 +150,7 @@ func main() { http.HandleFunc("/notification/ws", handlerWrapper(notification.WSHandler)) // user + http.HandleFunc("/login", handlerWrapper(session.LoginHandler)) http.HandleFunc("/logout", handlerWrapper(session.LogoutHandler)) http.HandleFunc("/preference", handlerWrapper(session.PreferenceHandler)) @@ -219,7 +220,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { t, err := template.ParseFiles("views/index.html") if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -279,7 +280,7 @@ func startHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -308,7 +309,7 @@ func keyboardShortcutsHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -338,7 +339,7 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/playground/autocomplete.go b/playground/autocomplete.go index 81d5af0..3894027 100644 --- a/playground/autocomplete.go +++ b/playground/autocomplete.go @@ -32,7 +32,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { if err := json.NewDecoder(r.Body).Decode(&args); err != nil { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -61,7 +61,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { output, err := cmd.CombinedOutput() if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/playground/playgrounds.go b/playground/playgrounds.go index 8191bdf..68c643c 100644 --- a/playground/playgrounds.go +++ b/playground/playgrounds.go @@ -97,7 +97,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/session/oauthctl.go b/session/oauthctl.go index 9e4bad3..d13a586 100644 --- a/session/oauthctl.go +++ b/session/oauthctl.go @@ -16,6 +16,8 @@ package session import ( "crypto/tls" + "github.com/b3log/wide/i18n" + "html/template" "math/rand" "net/http" "os" @@ -141,6 +143,22 @@ func GitHubUserInfo(accessToken string) (ret map[string]interface{}) { return result["data"].(map[string]interface{}) } +// LoginHandler handles request of show login page. +func LoginHandler(w http.ResponseWriter, r *http.Request) { + model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(conf.Wide.Locale), + "locale": conf.Wide.Locale, "ver": conf.WideVersion, "year": time.Now().Year()} + + t, err := template.ParseFiles("views/login.html") + if nil != err { + logger.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + + return + } + + t.Execute(w, model) +} + // LogoutHandler handles request of user logout (exit). func LogoutHandler(w http.ResponseWriter, r *http.Request) { result := util.NewResult() diff --git a/session/users.go b/session/users.go index 5522a0f..002b2d8 100644 --- a/session/users.go +++ b/session/users.go @@ -74,7 +74,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { if nil != err { logger.Error(err) - http.Error(w, err.Error(), 500) + http.Error(w, err.Error(), http.StatusInternalServerError) user.GoBuildArgsForLinux = tmpLinux user.GoBuildArgsForWindows = tmpWindows diff --git a/static/js/playground.js b/static/js/playground.js index ae6a253..b296cea 100644 --- a/static/js/playground.js +++ b/static/js/playground.js @@ -218,7 +218,7 @@ var playground = { if (!hovered) { $(".menu .share-panel").hide(); } - }, 500); + }, http.StatusInternalServerError; }); $(".menu .share-panel").hover(function () {