Просмотр исходного кода

Merge pull request #32 from IamTaoChen/bug/odic-user

delete user from user_thirds and update README
1 год назад
Родитель
Сommit
68065d3372
6 измененных файлов с 27 добавлено и 7 удалено
  1. 5 3
      README.md
  2. 5 3
      README_EN.md
  3. BIN
      docs/en_img/web_admin_oauth.png
  4. BIN
      docs/web_admin_oauth.png
  5. 6 0
      service/oauth.go
  6. 11 1
      service/user.go

+ 5 - 3
README.md

@@ -19,7 +19,7 @@
19 19
     - 登录
20 20
     - 地址簿
21 21
     - 群组
22
-    - 授权登录,支持`github`和`google`登录,支持`web后台`授权登录
22
+    - 授权登录,支持`github`, `google` 和 `OIDC` 登录,支持`web后台`授权登录
23 23
     - i18n
24 24
 - Web Admin
25 25
     - 用户管理
@@ -92,7 +92,7 @@
92 92
 
93 93
 #### 登录
94 94
 
95
-- 添加了`github`和`google`授权登录,需要在后台配置好就可以用了,具体可看后台OAuth配置
95
+- 添加了`github`, `google` 以及`OIDC`授权登录,需要在后台配置好就可以用了,具体可看后台OAuth配置
96 96
 - 添加了web后台授权登录,点击后直接登录后台就自动登录客户端了
97 97
 
98 98
 ![pc_login](docs/pc_login.png)
@@ -124,8 +124,10 @@
124 124
 4. 可以直接打开webclient,方便使用;也可以分享给游客,游客可以直接通过webclient远程到设备
125 125
 
126 126
    ![web_webclient](docs/admin_webclient.png)
127
-5. Oauth,暂时只支持了`Github`和`Google`, 需要创建一个`OAuth App`,然后配置到后台
127
+5. Oauth,支持了`Github`, `Google` 以及 `OIDC`, 需要创建一个`OAuth App`,然后配置到后台
128 128
    ![web_admin_oauth](docs/web_admin_oauth.png)
129
+    - 对于`Google` 和 `Github`, `Issuer` 和 `Scopes`不需要填写.
130
+    - 对于`OIDC`, `Issuer`是必须的。`Scopes`是可选的,默认为 `openid,profile,email`. 确保可以获取 `sub`,`email` 和`preferred_username`
129 131
     - `github oauth app`在`Settings`->`Developer settings`->`OAuth Apps`->`New OAuth App`
130 132
       中创建,地址 [https://github.com/settings/developers](https://github.com/settings/developers)
131 133
     - `Authorization callback URL`填写`http://<your server[:port]>/api/oauth/callback`

+ 5 - 3
README_EN.md

@@ -18,7 +18,7 @@ desktop software that provides self-hosted solutions.
18 18
     - Login
19 19
     - Address Book
20 20
     - Groups
21
-    - Authorized login, supports `GitHub` and `Google` login, supports `web admin` authorized login
21
+    - Authorized login, supports `GitHub`, `Google` and `OIDC` login, supports `web admin` authorized login
22 22
     - i18n
23 23
 - Web Admin
24 24
     - User Management
@@ -93,7 +93,7 @@ Basic implementation of the PC client's primary interfaces.Supports the Personal
93 93
 
94 94
 #### Login
95 95
 
96
-- Added `GitHub` and `Google` login, which can be used after configuration in the admin panel. See the OAuth
96
+- Added `GitHub`, `Google` and `OIDC` login, which can be used after configuration in the admin panel. See the OAuth
97 97
   configuration section for details.
98 98
 - Added authorization login for the web admin panel.
99 99
 
@@ -128,9 +128,11 @@ installation are `admin` `admin`, please change the password immediately.
128 128
 4. You can directly launch the client or open the web client for convenience; you can also share it with guests, who can remotely access the device via the web client.
129 129
 
130 130
    ![web_webclient](docs/en_img/admin_webclient.png)
131
-5. OAuth support: Currently, `GitHub` and `Google`  is supported. You need to create an `OAuth App` and configure it in
131
+5. OAuth support: Currently, `GitHub`, `Google` and `OIDC`  are supported. You need to create an `OAuth App` and configure it in
132 132
    the admin panel.
133 133
    ![web_admin_oauth](docs/en_img/web_admin_oauth.png)
134
+    - For `Google` and `Github`, you don't need to fill the `Issuer` and `Scpoes`
135
+    - For `OIDC`, you must set the `Issuer`. And `Scopes` is optional which default is `openid,email,profile`, please make sure this `Oauth App` can access `sub`, `email` and `preferred_username`
134 136
     - Create a `GitHub OAuth App`
135 137
       at `Settings` -> `Developer settings` -> `OAuth Apps` -> `New OAuth App` [here](https://github.com/settings/developers).
136 138
     - Set the `Authorization callback URL` to `http://<your server[:port]>/api/oauth/callback`,

BIN
docs/en_img/web_admin_oauth.png


BIN
docs/web_admin_oauth.png


+ 6 - 0
service/oauth.go

@@ -441,6 +441,12 @@ func (os *OauthService) UnBindThird(thirdType string, userid uint) error {
441 441
 	return global.DB.Where("user_id = ? and third_type = ?", userid, thirdType).Delete(&model.UserThird{}).Error
442 442
 }
443 443
 
444
+// DeleteUserByUserId: When user is deleted, delete all third party bindings
445
+func (os *OauthService) DeleteUserByUserId(userid uint) error {
446
+	return global.DB.Where("user_id = ?", userid).Delete(&model.UserThird{}).Error
447
+}
448
+
449
+
444 450
 // InfoById 根据id取用户信息
445 451
 func (os *OauthService) InfoById(id uint) *model.Oauth {
446 452
 	u := &model.Oauth{}

+ 11 - 1
service/user.go

@@ -148,8 +148,18 @@ func (us *UserService) Create(u *model.User) error {
148 148
 func (us *UserService) Logout(u *model.User, token string) error {
149 149
 	return global.DB.Where("user_id = ? and token = ?", u.Id, token).Delete(&model.UserToken{}).Error
150 150
 }
151
+
152
+// Delete 删除用户和oauth信息
151 153
 func (us *UserService) Delete(u *model.User) error {
152
-	return global.DB.Delete(u).Error
154
+    // 删除用户
155
+    if err := global.DB.Delete(u).Error; err != nil {
156
+        return err
157
+    }
158
+    // 删除关联的 OAuth 信息
159
+    if err := AllService.OauthService.DeleteUserByUserId(u.Id); err != nil {
160
+        return err
161
+    }
162
+    return nil
153 163
 }
154 164
 
155 165
 // Update 更新