prettier
This commit is contained in:
		
							parent
							
								
									3fa6077774
								
							
						
					
					
						commit
						e85afac9ed
					
				
							
								
								
									
										16
									
								
								.prettierrc.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								.prettierrc.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | /*  | ||||||
|  | 对 VSCode Prettier 有效;建议一直要有本配置文件,否则不同版本的 Prettier 的默认配置会不同,例如 TrailingComma | ||||||
|  | 对 VSCode Prettier Standard 无效,似乎是集成了不能修改的配置。 | ||||||
|  | */ | ||||||
|  | module.exports = { | ||||||
|  |   printWidth: 160, // default 80
 | ||||||
|  |   tabWidth: 2, // default 2
 | ||||||
|  |   useTabs: false, | ||||||
|  |   semi: false, // default true
 | ||||||
|  |   singleQuote: true, // default false
 | ||||||
|  |   trailingComma: 'es5', // none (default in v 1.*), es5 (default in v2.0.0), all
 | ||||||
|  |   bracketSpacing: true, // default true
 | ||||||
|  |   jsxBracketSameLine: false, // default false
 | ||||||
|  |   arrowParens: 'always', // avoid (default in v1.9.0), always (default since v2.0.0)
 | ||||||
|  |   quoteProps: 'as-needed', // as-needed (default), consistent, preserve
 | ||||||
|  | } | ||||||
							
								
								
									
										40
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								index.js
									
									
									
									
									
								
							| @ -2,32 +2,20 @@ const JsonWebToken = require('jsonwebtoken') | |||||||
| 
 | 
 | ||||||
| const crypto = require('crypto') | const crypto = require('crypto') | ||||||
| 
 | 
 | ||||||
| module.exports={ | module.exports = { | ||||||
|   createToken: function(content, key) { // content 可以是数字,字符串或对象,不可以是数组。
 |   createToken: function (content, key) { | ||||||
|     key=key||(wo&&wo.Config&&wo.Config.tokenKey?wo.Config.tokenKey:'') // key或wo.Config.tokenKey其中之一必须存在
 |     // content 可以是数字,非空字符串或非空对象,不可以是数组。
 | ||||||
|     if (content && !Array.isArray(content) && typeof(key)==='string' && key.length>0){ // 注意,jwt.sign(null|'') 会出错。但 sign(0)可以的。
 |     try { | ||||||
|       try{ |       return JsonWebToken.sign(content, crypto.createHash('sha256').update(key, 'utf8').digest('hex')) | ||||||
|         return JsonWebToken.sign(content, crypto.createHash('sha256').update(key, 'utf8').digest('hex')) |     } catch (exp) { | ||||||
|       }catch(exp){ |       return null | ||||||
|         return null |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|     return null |   }, | ||||||
|   } |   verifyToken: function (token, key) { | ||||||
|   , |     try { | ||||||
|   verifyToken: function(token, key) { |       return JsonWebToken.verify(token, crypto.createHash('sha256').update(key, 'utf8').digest('hex')) | ||||||
|     key=key||(wo&&wo.Config&&wo.Config.tokenKey?wo.Config.tokenKey:'') // key或wo.Config.tokenKey其中之一必须存在
 |     } catch (exp) { | ||||||
|     if (token && typeof token==='string' && typeof(key)==='string' && key.length>0) { |       return null | ||||||
|       try{ |  | ||||||
|         token=JsonWebToken.verify(token, crypto.createHash('sha256').update(key, 'utf8').digest('hex')) |  | ||||||
|       }catch(exp){ |  | ||||||
|         return null |  | ||||||
|       } |  | ||||||
|       if (Date.now() - Date.parse(token.whenStamp) > 2*60*60*1000) { // 每过2小时,核对一遍密码
 |  | ||||||
| 
 |  | ||||||
|       } |  | ||||||
|       return token |  | ||||||
|     } |     } | ||||||
|     return null |   }, | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user