This commit is contained in:
Liang Ding 2019-05-17 10:34:09 +08:00
parent e7a3fa9334
commit b8507efed3
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
7 changed files with 38 additions and 19 deletions

View File

@ -106,7 +106,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -125,7 +125,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -135,7 +135,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
if err := fout.Close(); nil != err { if err := fout.Close(); nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -168,7 +168,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -188,7 +188,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
var args map[string]interface{} var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -233,7 +233,7 @@ func GetExprInfoHandler(w http.ResponseWriter, r *http.Request) {
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -264,7 +264,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
var args map[string]interface{} var args map[string]interface{}
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -309,7 +309,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -353,7 +353,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -397,7 +397,7 @@ func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }

View File

@ -150,6 +150,7 @@ func main() {
http.HandleFunc("/notification/ws", handlerWrapper(notification.WSHandler)) http.HandleFunc("/notification/ws", handlerWrapper(notification.WSHandler))
// user // user
http.HandleFunc("/login", handlerWrapper(session.LoginHandler))
http.HandleFunc("/logout", handlerWrapper(session.LogoutHandler)) http.HandleFunc("/logout", handlerWrapper(session.LogoutHandler))
http.HandleFunc("/preference", handlerWrapper(session.PreferenceHandler)) 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") t, err := template.ParseFiles("views/index.html")
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -279,7 +280,7 @@ func startHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -308,7 +309,7 @@ func keyboardShortcutsHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -338,7 +339,7 @@ func aboutHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }

View File

@ -32,7 +32,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&args); err != nil { if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
@ -61,7 +61,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }

View File

@ -97,7 +97,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }

View File

@ -16,6 +16,8 @@ package session
import ( import (
"crypto/tls" "crypto/tls"
"github.com/b3log/wide/i18n"
"html/template"
"math/rand" "math/rand"
"net/http" "net/http"
"os" "os"
@ -141,6 +143,22 @@ func GitHubUserInfo(accessToken string) (ret map[string]interface{}) {
return result["data"].(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). // LogoutHandler handles request of user logout (exit).
func LogoutHandler(w http.ResponseWriter, r *http.Request) { func LogoutHandler(w http.ResponseWriter, r *http.Request) {
result := util.NewResult() result := util.NewResult()

View File

@ -74,7 +74,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
if nil != err { if nil != err {
logger.Error(err) logger.Error(err)
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), http.StatusInternalServerError)
user.GoBuildArgsForLinux = tmpLinux user.GoBuildArgsForLinux = tmpLinux
user.GoBuildArgsForWindows = tmpWindows user.GoBuildArgsForWindows = tmpWindows

View File

@ -218,7 +218,7 @@ var playground = {
if (!hovered) { if (!hovered) {
$(".menu .share-panel").hide(); $(".menu .share-panel").hide();
} }
}, 500); }, http.StatusInternalServerError;
}); });
$(".menu .share-panel").hover(function () { $(".menu .share-panel").hover(function () {