(ctx)
| 124 | } |
| 125 | |
| 126 | async checkLogin(ctx) { |
| 127 | let token = ctx.cookies.get('_yapi_token'); |
| 128 | let uid = ctx.cookies.get('_yapi_uid'); |
| 129 | try { |
| 130 | if (!token || !uid) { |
| 131 | return false; |
| 132 | } |
| 133 | let userInst = yapi.getInst(userModel); //创建user实体 |
| 134 | let result = await userInst.findById(uid); |
| 135 | if (!result) { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | let decoded; |
| 140 | try { |
| 141 | decoded = jwt.verify(token, result.passsalt); |
| 142 | } catch (err) { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | if (decoded.uid == uid) { |
| 147 | this.$uid = uid; |
| 148 | this.$auth = true; |
| 149 | this.$user = result; |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | return false; |
| 154 | } catch (e) { |
| 155 | yapi.commons.log(e, 'error'); |
| 156 | return false; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | async checkRegister() { |
| 161 | // console.log('config', yapi.WEBCONFIG); |
no test coverage detected