mirror of
				https://github.com/cloudreve/cloudreve.git
				synced 2025-10-31 16:49:03 +08:00 
			
		
		
		
	Test: thumbnail and authn / Modify: read thumbnail config from file
This commit is contained in:
		
							
								
								
									
										53
									
								
								models/user_authn.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								models/user_authn.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"encoding/binary" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"github.com/duo-labs/webauthn/webauthn" | ||||
| ) | ||||
|  | ||||
| /* | ||||
| 	`webauthn.User` 接口的实现 | ||||
| */ | ||||
|  | ||||
| // WebAuthnID 返回用户ID | ||||
| func (user User) WebAuthnID() []byte { | ||||
| 	bs := make([]byte, 8) | ||||
| 	binary.LittleEndian.PutUint64(bs, uint64(user.ID)) | ||||
| 	return bs | ||||
| } | ||||
|  | ||||
| // WebAuthnName 返回用户名 | ||||
| func (user User) WebAuthnName() string { | ||||
| 	return user.Email | ||||
| } | ||||
|  | ||||
| // WebAuthnDisplayName 获得用于展示的用户名 | ||||
| func (user User) WebAuthnDisplayName() string { | ||||
| 	return user.Nick | ||||
| } | ||||
|  | ||||
| // WebAuthnIcon 获得用户头像 | ||||
| func (user User) WebAuthnIcon() string { | ||||
| 	return "https://cdn4.buysellads.net/uu/1/46074/1559075156-slack-carbon-red_2x.png" | ||||
| } | ||||
|  | ||||
| // WebAuthnCredentials 获得已注册的验证器凭证 | ||||
| func (user User) WebAuthnCredentials() []webauthn.Credential { | ||||
| 	var res []webauthn.Credential | ||||
| 	err := json.Unmarshal([]byte(user.Authn), &res) | ||||
| 	if err != nil { | ||||
| 		fmt.Println(err) | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
|  | ||||
| // RegisterAuthn 添加新的验证器 | ||||
| func (user *User) RegisterAuthn(credential *webauthn.Credential) { | ||||
| 	res, err := json.Marshal([]webauthn.Credential{*credential}) | ||||
| 	if err != nil { | ||||
| 		fmt.Println(err) | ||||
| 	} | ||||
| 	DB.Model(user).UpdateColumn("authn", string(res)) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 HFO4
					HFO4