Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72b6537

Browse files
committed
解绑
1 parent 45c7090 commit 72b6537

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/http/controller/account.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (self AccountController) RegisterRoute(g *echo.Group) {
4242
g.Any("/account/forgetpwd", self.ForgetPasswd)
4343
g.Any("/account/resetpwd", self.ResetPasswd)
4444
g.Get("/account/logout", self.Logout, middleware.NeedLogin())
45+
g.POST("/account/social/unbind", self.Unbind, middleware.NeedLogin())
4546
}
4647

4748
func (self AccountController) Register(ctx echo.Context) error {
@@ -394,3 +395,12 @@ func (AccountController) Logout(ctx echo.Context) error {
394395
// 重定向得到登录页(TODO:重定向到什么页面比较好?)
395396
return ctx.Redirect(http.StatusSeeOther, "/account/login")
396397
}
398+
399+
// Unbind 第三方账号解绑
400+
func (AccountController) Unbind(ctx echo.Context) error {
401+
bindId := ctx.FormValue("bind_id")
402+
me := ctx.Get("user").(*model.Me)
403+
logic.DefaultThirdUser.UnBindUser(ctx, bindId, me)
404+
405+
return ctx.Redirect(http.StatusSeeOther, "/account/edit#connection")
406+
}

src/logic/third_user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ func (self ThirdUserLogic) BindGithub(ctx context.Context, code string, me *mode
190190
return nil
191191
}
192192

193+
func (ThirdUserLogic) UnBindUser(ctx context.Context, bindId interface{}, me *model.Me) error {
194+
_, err := MasterDB.Where("id=? AND uid=?", bindId, me.Uid).Delete(new(model.BindUser))
195+
return err
196+
}
197+
193198
func (ThirdUserLogic) githubTokenAndUser(ctx context.Context, code string) (*model.GithubUser, *oauth2.Token, error) {
194199
token, err := githubConf.Exchange(ctx, code)
195200
if err != nil {

template/user/edit.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ <h4 class="title">账号关联</h4>
198198
<p>您可以使用以下社交账户登录 {{.setting.Name}}。如果您删除了全部关联的社交账户,您仍可以使用<span class="text-danger">已验证的邮箱</span>或者以下用户名登录{{.setting.Name}}:</p>
199199
<p>您的用户名为:<span class="text-danger">{{.user.Username}}</span></p>
200200

201-
<form method="post" action="/user/social/connections">
201+
<form method="post" action="/account/social/unbind" id="unbind">
202202
<fieldset>
203203
<div>
204204
{{range .bind_users}}
@@ -269,16 +269,15 @@ <h5 class="mb-3">添加一个第三方账号</h5>
269269
<script type="text/javascript" src="/static/js/libs/plupload.full.min.js"></script>
270270
<script type="text/javascript" src="/static/js/user.js?v=1.1"></script>
271271
<script type="text/javascript">
272-
// 需要加载的侧边栏
273-
SG.SIDE_BARS = [
274-
"/topics/recent",
275-
"/resources/recent",
276-
"/comments/recent",
277-
];
278-
279272
$(function(){
280273
// 文本框自动伸缩
281274
$('.need-autogrow').autoGrow();
275+
276+
$('#unbind').submit(function(evt){
277+
if ($('input[name=bind_id]:checked').length == 0) {
278+
evt.preventDefault();
279+
}
280+
});
282281
});
283282
</script>
284283
{{end}}

0 commit comments

Comments
 (0)