Showing
6 changed files
with
118 additions
and
19 deletions
| @@ -382,7 +382,7 @@ export class HttpUrlUtils { | @@ -382,7 +382,7 @@ export class HttpUrlUtils { | ||
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | static getLogoutUrl() { | 384 | static getLogoutUrl() { |
| 385 | - let url = HttpUrlUtils._hostUrl + "/api/rmrb-user-center/user/zh/c/logout"; | 385 | + let url = HttpUrlUtils._hostUrl + "/api/rmrb-user-center/user/zh/c/appLogout"; |
| 386 | return url; | 386 | return url; |
| 387 | } | 387 | } |
| 388 | 388 |
| @@ -12,6 +12,10 @@ import router from '@ohos.router'; | @@ -12,6 +12,10 @@ import router from '@ohos.router'; | ||
| 12 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; | 12 | import { WDRouterPage, WDRouterRule } from 'wdRouter'; |
| 13 | import { Params } from 'wdBean'; | 13 | import { Params } from 'wdBean'; |
| 14 | import { SettingPasswordParams } from 'wdLogin'; | 14 | import { SettingPasswordParams } from 'wdLogin'; |
| 15 | +import { LoginViewModel } from 'wdLogin/src/main/ets/pages/login/LoginViewModel'; | ||
| 16 | +import { Router } from '@ohos.arkui.UIContext'; | ||
| 17 | +import promptAction from '@ohos.promptAction'; | ||
| 18 | + | ||
| 15 | export { SettingPasswordParams } from "wdLogin" | 19 | export { SettingPasswordParams } from "wdLogin" |
| 16 | 20 | ||
| 17 | @Component | 21 | @Component |
| @@ -83,16 +87,21 @@ export struct AccountAndSecurityLayout { | @@ -83,16 +87,21 @@ export struct AccountAndSecurityLayout { | ||
| 83 | 87 | ||
| 84 | Column() { | 88 | Column() { |
| 85 | Button('退出登录',{ stateEffect: true ,type: ButtonType.Normal}).width('90%').height('80lpx').backgroundColor('#da3e22').fontColor('#fff').margin('20lpx').borderRadius('8lpx').onClick(()=>{ | 89 | Button('退出登录',{ stateEffect: true ,type: ButtonType.Normal}).width('90%').height('80lpx').backgroundColor('#da3e22').fontColor('#fff').margin('20lpx').borderRadius('8lpx').onClick(()=>{ |
| 86 | - AlertDialog.show({ | ||
| 87 | - title: '🥟id : ' + "button", | ||
| 88 | - message: '标题:' + '退出登录', | ||
| 89 | - confirm: { | ||
| 90 | - value: "OK", | ||
| 91 | - action: () => { | ||
| 92 | - | ||
| 93 | - }, | ||
| 94 | - } | ||
| 95 | - }) | 90 | + let login = new LoginViewModel; |
| 91 | + promptAction.showToast({ message: '退出登录' }) | ||
| 92 | + login.logOut(); | ||
| 93 | + router.back(); | ||
| 94 | + router.back(); | ||
| 95 | + // AlertDialog.show({ | ||
| 96 | + // title: '🥟id : ' + "button", | ||
| 97 | + // message: '标题:' + '退出登录', | ||
| 98 | + // confirm: { | ||
| 99 | + // value: "OK", | ||
| 100 | + // action: () => { | ||
| 101 | + // | ||
| 102 | + // }, | ||
| 103 | + // } | ||
| 104 | + // }) | ||
| 96 | }) | 105 | }) |
| 97 | } | 106 | } |
| 98 | 107 |
| @@ -121,6 +121,7 @@ export class LoginModel { | @@ -121,6 +121,7 @@ export class LoginModel { | ||
| 121 | bean['verifyCode'] = verifyCode | 121 | bean['verifyCode'] = verifyCode |
| 122 | bean['phone'] = phone | 122 | bean['phone'] = phone |
| 123 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 123 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 124 | + headers.set('cookie', ''); | ||
| 124 | return new Promise<CheckVerifyBean>((success, fail) => { | 125 | return new Promise<CheckVerifyBean>((success, fail) => { |
| 125 | HttpRequest.post<ResponseDTO<CheckVerifyBean>>(HttpUrlUtils.getCheckVerifyCodeUrl(), bean, headers).then((data: ResponseDTO<CheckVerifyBean>) => { | 126 | HttpRequest.post<ResponseDTO<CheckVerifyBean>>(HttpUrlUtils.getCheckVerifyCodeUrl(), bean, headers).then((data: ResponseDTO<CheckVerifyBean>) => { |
| 126 | Logger.debug("LoginViewModel:success2 ", data.message) | 127 | Logger.debug("LoginViewModel:success2 ", data.message) |
| @@ -230,7 +231,7 @@ export class LoginModel { | @@ -230,7 +231,7 @@ export class LoginModel { | ||
| 230 | 231 | ||
| 231 | return new Promise<string>((success, fail) => { | 232 | return new Promise<string>((success, fail) => { |
| 232 | HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getLogoutUrl(), bean, headers).then((data: ResponseDTO<string>) => { | 233 | HttpRequest.post<ResponseDTO<string>>(HttpUrlUtils.getLogoutUrl(), bean, headers).then((data: ResponseDTO<string>) => { |
| 233 | - if (!data || !data.data) { | 234 | + if (!data) { |
| 234 | fail("数据为空") | 235 | fail("数据为空") |
| 235 | return | 236 | return |
| 236 | } | 237 | } |
| @@ -238,7 +239,7 @@ export class LoginModel { | @@ -238,7 +239,7 @@ export class LoginModel { | ||
| 238 | fail(data.message) | 239 | fail(data.message) |
| 239 | return | 240 | return |
| 240 | } | 241 | } |
| 241 | - success(data.data) | 242 | + success('') |
| 242 | }, (error: Error) => { | 243 | }, (error: Error) => { |
| 243 | fail(error.message) | 244 | fail(error.message) |
| 244 | Logger.debug("LoginViewModel:error ", error.toString()) | 245 | Logger.debug("LoginViewModel:error ", error.toString()) |
| @@ -5,6 +5,8 @@ import { SPHelper } from 'wdKit' | @@ -5,6 +5,8 @@ import { SPHelper } from 'wdKit' | ||
| 5 | import { CheckVerifyBean } from './CheckVerifyBean' | 5 | import { CheckVerifyBean } from './CheckVerifyBean' |
| 6 | import cryptoFramework from '@ohos.security.cryptoFramework' | 6 | import cryptoFramework from '@ohos.security.cryptoFramework' |
| 7 | import buffer from '@ohos.buffer' | 7 | import buffer from '@ohos.buffer' |
| 8 | +import { encryptMessage } from '../../utils/cryptoUtil' | ||
| 9 | + | ||
| 8 | import { | 10 | import { |
| 9 | SpConstants | 11 | SpConstants |
| 10 | } from '../../../../../../../commons/wdNetwork/oh_modules/wdConstant/src/main/ets/constants/SpConstants' | 12 | } from '../../../../../../../commons/wdNetwork/oh_modules/wdConstant/src/main/ets/constants/SpConstants' |
| @@ -119,7 +121,8 @@ export class LoginViewModel { | @@ -119,7 +121,8 @@ export class LoginViewModel { | ||
| 119 | //重置密码 需要老密码 | 121 | //重置密码 需要老密码 |
| 120 | resetPassword(password: string, tempToken: string) { | 122 | resetPassword(password: string, tempToken: string) { |
| 121 | return new Promise<string>(async (success, fail) => { | 123 | return new Promise<string>(async (success, fail) => { |
| 122 | - let passwordNew = await this.doMd(password) | 124 | + |
| 125 | + let passwordNew = await encryptMessage(password); | ||
| 123 | this.loginModel.resetPassword(passwordNew, tempToken).then((data) => { | 126 | this.loginModel.resetPassword(passwordNew, tempToken).then((data) => { |
| 124 | success(data) | 127 | success(data) |
| 125 | }).catch((message: string) => { | 128 | }).catch((message: string) => { |
| @@ -132,7 +135,7 @@ export class LoginViewModel { | @@ -132,7 +135,7 @@ export class LoginViewModel { | ||
| 132 | //忘记密码 | 135 | //忘记密码 |
| 133 | forgotPassword(password: string, tempToken: string) { | 136 | forgotPassword(password: string, tempToken: string) { |
| 134 | return new Promise<string>(async (success, fail) => { | 137 | return new Promise<string>(async (success, fail) => { |
| 135 | - let passwordNew = await this.doMd(password) | 138 | + let passwordNew = await encryptMessage(password) |
| 136 | this.loginModel.forgotPassword(passwordNew, tempToken).then((data) => { | 139 | this.loginModel.forgotPassword(passwordNew, tempToken).then((data) => { |
| 137 | success(data) | 140 | success(data) |
| 138 | }).catch((message: string) => { | 141 | }).catch((message: string) => { |
| @@ -146,9 +149,18 @@ export class LoginViewModel { | @@ -146,9 +149,18 @@ export class LoginViewModel { | ||
| 146 | return new Promise<string>(async (success, fail) => { | 149 | return new Promise<string>(async (success, fail) => { |
| 147 | this.loginModel.logOut().then((data) => { | 150 | this.loginModel.logOut().then((data) => { |
| 148 | //清除登录状态以及token、userid等信息 | 151 | //清除登录状态以及token、userid等信息 |
| 149 | - HttpUrlUtils.setUserId(''); | ||
| 150 | - HttpUrlUtils.setUserType(''); | ||
| 151 | - HttpUrlUtils.setUserToken(''); | 152 | + |
| 153 | + SPHelper.default.save(SpConstants.USER_FIRST_MARK, '') | ||
| 154 | + SPHelper.default.save(SpConstants.USER_ID, '') | ||
| 155 | + SPHelper.default.save(SpConstants.USER_JWT_TOKEN, '') | ||
| 156 | + SPHelper.default.save(SpConstants.USER_LONG_TIME_NO_LOGIN_MARK, '') | ||
| 157 | + SPHelper.default.save(SpConstants.USER_REFRESH_TOKEN, '') | ||
| 158 | + SPHelper.default.save(SpConstants.USER_STATUS, '') | ||
| 159 | + SPHelper.default.save(SpConstants.USER_Type, '') | ||
| 160 | + SPHelper.default.save(SpConstants.USER_NAME, '') | ||
| 161 | + HttpUrlUtils.setUserId("") | ||
| 162 | + HttpUrlUtils.setUserType("") | ||
| 163 | + HttpUrlUtils.setUserToken('') | ||
| 152 | success(data) | 164 | success(data) |
| 153 | }).catch((message: string) => { | 165 | }).catch((message: string) => { |
| 154 | fail(message) | 166 | fail(message) |
| @@ -188,7 +188,7 @@ export struct SettingPasswordLayout { | @@ -188,7 +188,7 @@ export struct SettingPasswordLayout { | ||
| 188 | Row() { | 188 | Row() { |
| 189 | TextInput({ placeholder: item.inputPlacholder }) | 189 | TextInput({ placeholder: item.inputPlacholder }) |
| 190 | .type(InputType.Password) | 190 | .type(InputType.Password) |
| 191 | - .showPasswordIcon(false) | 191 | + .showPasswordIcon(true) |
| 192 | .backgroundColor('#00000000') | 192 | .backgroundColor('#00000000') |
| 193 | .onChange((value: string) => { | 193 | .onChange((value: string) => { |
| 194 | this.inputTextChange(value, item.inputTag) | 194 | this.inputTextChange(value, item.inputTag) |
| 1 | +import cryptoFramework from '@ohos.security.cryptoFramework'; | ||
| 2 | +import buffer from '@ohos.buffer'; | ||
| 3 | +import util from '@ohos.util'; | ||
| 4 | + | ||
| 5 | +// 加密消息 | ||
| 6 | + | ||
| 7 | +let pubKeyString = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAI05e8RfyEnLW/Un629lVJoVHntIanEAETot5nRcLmPJpXbC5lf5UgvVrDPPmoTxc567Hg9qq3AyAqWrSyqI6MECAwEAAQ=='; | ||
| 8 | + | ||
| 9 | +async function encryptMessagePromise(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { | ||
| 10 | + let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); | ||
| 11 | + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); | ||
| 12 | + let encryptData = await cipher.doFinal(plainText); | ||
| 13 | + return encryptData; | ||
| 14 | +} | ||
| 15 | +// 解密消息 | ||
| 16 | +async function decryptMessagePromise(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { | ||
| 17 | + let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); | ||
| 18 | + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); | ||
| 19 | + let decryptData = await decoder.doFinal(cipherText); | ||
| 20 | + return decryptData; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +// 生成RSA密钥对 | ||
| 25 | +async function genKeyPairByData() { | ||
| 26 | + | ||
| 27 | + let base64 = new util.Base64Helper(); | ||
| 28 | + let pubKeyData = base64.decodeSync(pubKeyString); | ||
| 29 | + | ||
| 30 | + let pkData = new Uint8Array(buffer.from(pubKeyString, 'utf-8').buffer) | ||
| 31 | + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; | ||
| 32 | + | ||
| 33 | + let pkData2 = new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, 74, 42, 173, 40, 215, 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, 210, 181, 12, 29, 70, 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, 245, 46, 70, 45, 157, 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, 118, 92, 147, 121, 220, 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, 105, 208, 133, 140, 13, 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1]); | ||
| 34 | + let pubKeyBlob2: cryptoFramework.DataBlob = { data: pkData2 }; | ||
| 35 | + | ||
| 36 | + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + rsaGenerator.convertKey(pubKeyBlob2, null, (err, keyPair) => { | ||
| 40 | + if (err) { | ||
| 41 | + console.error(`convertKey failed, ${err.code}, ${err.message}`); | ||
| 42 | + } | ||
| 43 | + console.info('convertKey success'); | ||
| 44 | + }); | ||
| 45 | + | ||
| 46 | + rsaGenerator.convertKey(pubKeyBlob, null, (err, keyPair) => { | ||
| 47 | + if (err) { | ||
| 48 | + console.error(`convertKey failed, ${err.code}, ${err.message}`); | ||
| 49 | + } | ||
| 50 | + console.info('convertKey success'); | ||
| 51 | + }); | ||
| 52 | + | ||
| 53 | + let keyPair = await rsaGenerator.convertKey(pubKeyBlob, null) | ||
| 54 | + console.info('convertKey success'); | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + return keyPair; | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +export async function encryptMessage(text:string) { | ||
| 63 | + let keyPair = await genKeyPairByData(); | ||
| 64 | + let pubKey = keyPair.pubKey; | ||
| 65 | + let priKey = keyPair.priKey; | ||
| 66 | + let message = text; | ||
| 67 | + // 把字符串按utf-8解码为Uint8Array | ||
| 68 | + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; | ||
| 69 | + let encryptText = await encryptMessagePromise(pubKey, plainText); | ||
| 70 | + | ||
| 71 | + //base 64加密 | ||
| 72 | + let base64 = new util.Base64Helper(); | ||
| 73 | + | ||
| 74 | + let result = base64.encodeToStringSync(encryptText.data); | ||
| 75 | + | ||
| 76 | + return result; | ||
| 77 | +} |
-
Please register or login to post a comment