This commit is contained in:
Liang Ding 2019-12-13 20:50:35 +08:00
parent 358067ea10
commit 89e3b7be8f
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
13 changed files with 26 additions and 62 deletions

View File

@ -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

View File

@ -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))

View File

@ -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"

View File

@ -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)

View File

@ -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 {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

BIN
static/images/hacpai.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -15,7 +15,7 @@
<div class="item">
<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>
<a href="https://github.com/b3log" target="_blank">B3log</a><br/>

View File

@ -342,7 +342,7 @@
src="{{.user.Avatar}}"
title="{{.user.Name}}"/>
<span class="font-ico ico-share"></span> &nbsp;
<span onclick="window.open('https://github.com/b3log/wide')"
<span onclick="window.open('https://github.com/88250/wide')"
class="font-ico ico-github"></span>&nbsp;
<div class="share-panel frame">
<span title="Email" class="font-ico ico-email"></span>

View File

@ -22,7 +22,7 @@
<img title="A Web-based Go IDE" src="/static/images/wide-logo.png" class="logo"/></a>
<ul>
<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="bookmark" href="https://hacpai.com" target="_blank">{{.i18n.community}}</a></li>
</ul>
@ -37,8 +37,8 @@
<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 class="login__github oauth"></div>
<img style="display: none" src="/static/images/github.gif"/>
<button class="btn oauth">登录 GitHub 账号后即可开始使用</button>
<img style="display: none" src="/static/images/hacpai.png"/>
<button class="btn oauth">登录黑客派社区账号后即可开始使用</button>
</div>
</div>
</div>
@ -50,7 +50,7 @@
<script type="text/javascript" src="/static/js/lib/jquery-2.1.1.min.js"></script>
<script>
$('.oauth').click(function () {
window.location.href = '/oauth/github/redirect?state=' + ($('input').prop('checked') ? '0' : '1')
window.location.href = '/login/redirect'
})
</script>
</body>

View File

@ -58,7 +58,7 @@
<div class="fn-right">
<span class="font-ico ico-about" onclick='$("#dialogAbout").dialog("open");'></span> &nbsp;
<span class="font-ico ico-share"></span> &nbsp;
<span onclick="window.open('https://github.com/b3log/wide')"
<span onclick="window.open('https://github.com/88250/wide')"
class="font-ico ico-github"></span>&nbsp;
<div class="share-panel frame" style="display: none;">
<span title="Email" class="font-ico ico-email"></span>

View File

@ -21,7 +21,7 @@
<label>{{.i18n.current_ver}}{{.i18n.colon}}</label>
{{.ver}}<br/>
<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>
<a href="https://github.com/b3log/b3log-solo/wiki/About_us" target="_blank">B3log</a>
</li>