diff --git a/conf/wide.go b/conf/wide.go index a9cc4c3..4ca9ade 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -42,7 +42,7 @@ const ( // CodeMirrorVer holds the current editor version. CodeMirrorVer = "5.1" // UserAgent represents HTTP client user agent. - UserAgent = "Wide/" + WideVersion + "; +https://github.com/b3log/wide" + UserAgent = "Wide/" + WideVersion + "; +https://github.com/88250/wide" HelloWorld = `package main diff --git a/main.go b/main.go index ab9ba09..3d07166 100644 --- a/main.go +++ b/main.go @@ -93,8 +93,8 @@ func main() { serveSingle("/favicon.ico", "./static/images/favicon.png") // oauth - http.HandleFunc("/oauth/github/redirect", session.RedirectGitHubHandler) - http.HandleFunc("/oauth/github/callback", session.GithubCallbackHandler) + http.HandleFunc("/login/redirect", session.LoginRedirectHandler) + http.HandleFunc("/login/callback", session.LoginCallbackHandler) // session http.HandleFunc("/session/ws", handlerWrapper(session.WSHandler)) diff --git a/package.json b/package.json index 1fbb9bd..015f165 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "homepage": "https://wide.b3log.org", "repository": { "type": "git", - "url": "git://github.com/b3log/wide.git" + "url": "git://github.com/88250/wide.git" }, "bugs": { "url": "https://github.com/88250/wide/issues" diff --git a/session/oauth.go b/session/oauth.go index 5934827..f1d73d1 100644 --- a/session/oauth.go +++ b/session/oauth.go @@ -15,7 +15,6 @@ package session import ( - "crypto/tls" "html/template" "math/rand" "net/http" @@ -24,46 +23,24 @@ import ( "strconv" "strings" "time" - "github.com/88250/gulu" "github.com/88250/wide/conf" "github.com/88250/wide/i18n" - "github.com/parnurzeal/gorequest" ) var states = map[string]string{} -// RedirectGitHubHandler redirects to GitHub auth page. -func RedirectGitHubHandler(w http.ResponseWriter, r *http.Request) { - requestResult := gulu.Ret.NewResult() - _, _, errs := gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true}). - Get("https://hacpai.com/oauth/wide/client"). - Set("user-agent", conf.UserAgent).Timeout(10 * time.Second).EndStruct(requestResult) - if nil != errs { - logger.Errorf("Get oauth client id failed: %+v", errs) - http.Error(w, "Get oauth info failed", http.StatusInternalServerError) +// LoginRedirectHandler redirects to HacPai auth page. +func LoginRedirectHandler(w http.ResponseWriter, r *http.Request) { + loginAuthURL := "https://hacpai.com/login?goto=" + conf.Wide.Server + "/login/callback" - return - } - if 0 != requestResult.Code { - logger.Errorf("get oauth client id failed [code=%d, msg=%s]", requestResult.Code, requestResult.Msg) - http.Error(w, "Get oauth info failed", http.StatusNotFound) - - return - } - data := requestResult.Data.(map[string]interface{}) - clientId := data["clientId"].(string) - loginAuthURL := data["loginAuthURL"].(string) - - state := r.URL.Query().Get("state") - referer := conf.Wide.Server + "__" + state - state = gulu.Rand.String(16) + referer + state := gulu.Rand.String(16) states[state] = state - path := loginAuthURL + "?client_id=" + clientId + "&state=" + state + path := loginAuthURL + "?state=" + state http.Redirect(w, r, path, http.StatusSeeOther) } -func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { +func LoginCallbackHandler(w http.ResponseWriter, r *http.Request) { state := r.URL.Query().Get("state") if _, exist := states[state]; !exist { http.Error(w, "Get state param failed", http.StatusBadRequest) @@ -72,26 +49,13 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { } delete(states, state) - referer := state[16:] - if strings.Contains(referer, "__0") || strings.Contains(referer, "__1") { - referer = referer[:len(referer)-len("__0")] - } - accessToken := r.URL.Query().Get("ak") - githubUser := GitHubUserInfo(accessToken) - if nil == githubUser { - logger.Warnf("Can not get user info with token [" + accessToken + "]") - http.Error(w, "Get user info failed", http.StatusUnauthorized) + userId := r.URL.Query().Get("userId") + userName := r.URL.Query().Get("userName") + avatar := r.URL.Query().Get("avatar") - return - } - - githubId := githubUser["userId"].(string) - userName := githubUser["userName"].(string) - avatar := githubUser["userAvatarURL"].(string) - - user := conf.GetUser(githubId) + user := conf.GetUser(userId) if nil == user { - msg := addUser(githubId, userName, avatar) + msg := addUser(userId, userName, avatar) if userCreated != msg { result := gulu.Ret.NewResult() result.Code = -1 @@ -104,7 +68,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) { // create a HTTP session httpSession, _ := HTTPSession.Get(r, CookieName) - httpSession.Values["uid"] = githubId + httpSession.Values["uid"] = userId httpSession.Values["id"] = strconv.Itoa(rand.Int()) httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge httpSession.Save(r, w) diff --git a/static/css/sign.css b/static/css/sign.css index f688eb3..d3dca94 100644 --- a/static/css/sign.css +++ b/static/css/sign.css @@ -94,7 +94,7 @@ body { .login__github { cursor: pointer; - background-image: url("/static/images/github.png"); + background-image: url("/static/images/hacpai.png"); height: 200px; width: 200px; background-size: cover; @@ -103,7 +103,7 @@ body { } .login__github:hover { - background-image: url("/static/images/github.gif"); + background-image: url("/static/images/hacpai.png"); } .btn { diff --git a/static/images/github.gif b/static/images/github.gif deleted file mode 100644 index 8320dd6..0000000 Binary files a/static/images/github.gif and /dev/null differ diff --git a/static/images/github.png b/static/images/github.png deleted file mode 100644 index 81f3685..0000000 Binary files a/static/images/github.png and /dev/null differ diff --git a/static/images/hacpai.png b/static/images/hacpai.png new file mode 100644 index 0000000..c935fef Binary files /dev/null and b/static/images/hacpai.png differ diff --git a/views/about.html b/views/about.html index 16346c6..f330438 100644 --- a/views/about.html +++ b/views/about.html @@ -15,7 +15,7 @@