This commit is contained in:
parent
358067ea10
commit
89e3b7be8f
|
@ -42,7 +42,7 @@ const (
|
||||||
// CodeMirrorVer holds the current editor version.
|
// CodeMirrorVer holds the current editor version.
|
||||||
CodeMirrorVer = "5.1"
|
CodeMirrorVer = "5.1"
|
||||||
// UserAgent represents HTTP client user agent.
|
// 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
|
HelloWorld = `package main
|
||||||
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -93,8 +93,8 @@ func main() {
|
||||||
serveSingle("/favicon.ico", "./static/images/favicon.png")
|
serveSingle("/favicon.ico", "./static/images/favicon.png")
|
||||||
|
|
||||||
// oauth
|
// oauth
|
||||||
http.HandleFunc("/oauth/github/redirect", session.RedirectGitHubHandler)
|
http.HandleFunc("/login/redirect", session.LoginRedirectHandler)
|
||||||
http.HandleFunc("/oauth/github/callback", session.GithubCallbackHandler)
|
http.HandleFunc("/login/callback", session.LoginCallbackHandler)
|
||||||
|
|
||||||
// session
|
// session
|
||||||
http.HandleFunc("/session/ws", handlerWrapper(session.WSHandler))
|
http.HandleFunc("/session/ws", handlerWrapper(session.WSHandler))
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"homepage": "https://wide.b3log.org",
|
"homepage": "https://wide.b3log.org",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/b3log/wide.git"
|
"url": "git://github.com/88250/wide.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/88250/wide/issues"
|
"url": "https://github.com/88250/wide/issues"
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
package session
|
package session
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -24,46 +23,24 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/wide/conf"
|
"github.com/88250/wide/conf"
|
||||||
"github.com/88250/wide/i18n"
|
"github.com/88250/wide/i18n"
|
||||||
"github.com/parnurzeal/gorequest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var states = map[string]string{}
|
var states = map[string]string{}
|
||||||
|
|
||||||
// RedirectGitHubHandler redirects to GitHub auth page.
|
// LoginRedirectHandler redirects to HacPai auth page.
|
||||||
func RedirectGitHubHandler(w http.ResponseWriter, r *http.Request) {
|
func LoginRedirectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
requestResult := gulu.Ret.NewResult()
|
loginAuthURL := "https://hacpai.com/login?goto=" + conf.Wide.Server + "/login/callback"
|
||||||
_, _, 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)
|
|
||||||
|
|
||||||
return
|
state := gulu.Rand.String(16)
|
||||||
}
|
|
||||||
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
|
|
||||||
states[state] = state
|
states[state] = state
|
||||||
path := loginAuthURL + "?client_id=" + clientId + "&state=" + state
|
path := loginAuthURL + "?state=" + state
|
||||||
http.Redirect(w, r, path, http.StatusSeeOther)
|
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")
|
state := r.URL.Query().Get("state")
|
||||||
if _, exist := states[state]; !exist {
|
if _, exist := states[state]; !exist {
|
||||||
http.Error(w, "Get state param failed", http.StatusBadRequest)
|
http.Error(w, "Get state param failed", http.StatusBadRequest)
|
||||||
|
@ -72,26 +49,13 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
delete(states, state)
|
delete(states, state)
|
||||||
|
|
||||||
referer := state[16:]
|
userId := r.URL.Query().Get("userId")
|
||||||
if strings.Contains(referer, "__0") || strings.Contains(referer, "__1") {
|
userName := r.URL.Query().Get("userName")
|
||||||
referer = referer[:len(referer)-len("__0")]
|
avatar := r.URL.Query().Get("avatar")
|
||||||
}
|
|
||||||
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)
|
|
||||||
|
|
||||||
return
|
user := conf.GetUser(userId)
|
||||||
}
|
|
||||||
|
|
||||||
githubId := githubUser["userId"].(string)
|
|
||||||
userName := githubUser["userName"].(string)
|
|
||||||
avatar := githubUser["userAvatarURL"].(string)
|
|
||||||
|
|
||||||
user := conf.GetUser(githubId)
|
|
||||||
if nil == user {
|
if nil == user {
|
||||||
msg := addUser(githubId, userName, avatar)
|
msg := addUser(userId, userName, avatar)
|
||||||
if userCreated != msg {
|
if userCreated != msg {
|
||||||
result := gulu.Ret.NewResult()
|
result := gulu.Ret.NewResult()
|
||||||
result.Code = -1
|
result.Code = -1
|
||||||
|
@ -104,7 +68,7 @@ func GithubCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// create a HTTP session
|
// create a HTTP session
|
||||||
httpSession, _ := HTTPSession.Get(r, CookieName)
|
httpSession, _ := HTTPSession.Get(r, CookieName)
|
||||||
httpSession.Values["uid"] = githubId
|
httpSession.Values["uid"] = userId
|
||||||
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
httpSession.Values["id"] = strconv.Itoa(rand.Int())
|
||||||
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
|
||||||
httpSession.Save(r, w)
|
httpSession.Save(r, w)
|
||||||
|
|
|
@ -94,7 +94,7 @@ body {
|
||||||
|
|
||||||
.login__github {
|
.login__github {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background-image: url("/static/images/github.png");
|
background-image: url("/static/images/hacpai.png");
|
||||||
height: 200px;
|
height: 200px;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
|
@ -103,7 +103,7 @@ body {
|
||||||
}
|
}
|
||||||
|
|
||||||
.login__github:hover {
|
.login__github:hover {
|
||||||
background-image: url("/static/images/github.gif");
|
background-image: url("/static/images/hacpai.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 69 KiB |
Binary file not shown.
Before Width: | Height: | Size: 26 KiB |
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<label>{{.i18n.project_address}}{{.i18n.colon}}</label>
|
<label>{{.i18n.project_address}}{{.i18n.colon}}</label>
|
||||||
<a href="https://github.com/b3log/wide" target="_blank">github.com/b3log/wide</a><br/>
|
<a href="https://github.com/88250/wide" target="_blank">github.com/88250/wide</a><br/>
|
||||||
|
|
||||||
<label>{{.i18n.dev_team}}{{.i18n.colon}}</label>
|
<label>{{.i18n.dev_team}}{{.i18n.colon}}</label>
|
||||||
<a href="https://github.com/b3log" target="_blank">B3log</a><br/>
|
<a href="https://github.com/b3log" target="_blank">B3log</a><br/>
|
||||||
|
|
|
@ -342,7 +342,7 @@
|
||||||
src="{{.user.Avatar}}"
|
src="{{.user.Avatar}}"
|
||||||
title="{{.user.Name}}"/>
|
title="{{.user.Name}}"/>
|
||||||
<span class="font-ico ico-share"></span>
|
<span class="font-ico ico-share"></span>
|
||||||
<span onclick="window.open('https://github.com/b3log/wide')"
|
<span onclick="window.open('https://github.com/88250/wide')"
|
||||||
class="font-ico ico-github"></span>
|
class="font-ico ico-github"></span>
|
||||||
<div class="share-panel frame">
|
<div class="share-panel frame">
|
||||||
<span title="Email" class="font-ico ico-email"></span>
|
<span title="Email" class="font-ico ico-email"></span>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<img title="A Web-based Go IDE" src="/static/images/wide-logo.png" class="logo"/></a>
|
<img title="A Web-based Go IDE" src="/static/images/wide-logo.png" class="logo"/></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/playground" target="_blank" style="color: #cd504a">Play</a></li>
|
<li><a href="/playground" target="_blank" style="color: #cd504a">Play</a></li>
|
||||||
<li><a rel="bookmark" href="https://github.com/b3log/wide" target="_blank">GitHub</a></li>
|
<li><a rel="bookmark" href="https://github.com/88250/wide" target="_blank">GitHub</a></li>
|
||||||
<li><a rel="help" href="https://hacpai.com/article/1538873544275" target="_blank">{{.i18n.help}}</a></li>
|
<li><a rel="help" href="https://hacpai.com/article/1538873544275" target="_blank">{{.i18n.help}}</a></li>
|
||||||
<li><a rel="bookmark" href="https://hacpai.com" target="_blank">{{.i18n.community}}</a></li>
|
<li><a rel="bookmark" href="https://hacpai.com" target="_blank">{{.i18n.community}}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -37,8 +37,8 @@
|
||||||
<div class="form fn-right">
|
<div class="form fn-right">
|
||||||
<div style="text-align: center"><a href="https://hacpai.com/article/1558097702072" target="_blank">2019-05-17 关于账号迁移的公告</a></div>
|
<div style="text-align: center"><a href="https://hacpai.com/article/1558097702072" target="_blank">2019-05-17 关于账号迁移的公告</a></div>
|
||||||
<div class="login__github oauth"></div>
|
<div class="login__github oauth"></div>
|
||||||
<img style="display: none" src="/static/images/github.gif"/>
|
<img style="display: none" src="/static/images/hacpai.png"/>
|
||||||
<button class="btn oauth">登录 GitHub 账号后即可开始使用</button>
|
<button class="btn oauth">登录黑客派社区账号后即可开始使用</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
<script type="text/javascript" src="/static/js/lib/jquery-2.1.1.min.js"></script>
|
<script type="text/javascript" src="/static/js/lib/jquery-2.1.1.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$('.oauth').click(function () {
|
$('.oauth').click(function () {
|
||||||
window.location.href = '/oauth/github/redirect?state=' + ($('input').prop('checked') ? '0' : '1')
|
window.location.href = '/login/redirect'
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<div class="fn-right">
|
<div class="fn-right">
|
||||||
<span class="font-ico ico-about" onclick='$("#dialogAbout").dialog("open");'></span>
|
<span class="font-ico ico-about" onclick='$("#dialogAbout").dialog("open");'></span>
|
||||||
<span class="font-ico ico-share"></span>
|
<span class="font-ico ico-share"></span>
|
||||||
<span onclick="window.open('https://github.com/b3log/wide')"
|
<span onclick="window.open('https://github.com/88250/wide')"
|
||||||
class="font-ico ico-github"></span>
|
class="font-ico ico-github"></span>
|
||||||
<div class="share-panel frame" style="display: none;">
|
<div class="share-panel frame" style="display: none;">
|
||||||
<span title="Email" class="font-ico ico-email"></span>
|
<span title="Email" class="font-ico ico-email"></span>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<label>{{.i18n.current_ver}}{{.i18n.colon}}</label>
|
<label>{{.i18n.current_ver}}{{.i18n.colon}}</label>
|
||||||
{{.ver}}<br/>
|
{{.ver}}<br/>
|
||||||
<label>{{.i18n.project_address}}{{.i18n.colon}}</label>
|
<label>{{.i18n.project_address}}{{.i18n.colon}}</label>
|
||||||
<a href="https://github.com/b3log/wide" target="_blank">github.com/b3log/wide</a><br/>
|
<a href="https://github.com/88250/wide" target="_blank">github.com/88250/wide</a><br/>
|
||||||
<label>{{.i18n.dev_team}}{{.i18n.colon}}</label>
|
<label>{{.i18n.dev_team}}{{.i18n.colon}}</label>
|
||||||
<a href="https://github.com/b3log/b3log-solo/wiki/About_us" target="_blank">B3log</a>
|
<a href="https://github.com/b3log/b3log-solo/wiki/About_us" target="_blank">B3log</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue