| | |
| | | package com.dayu.pipirrapp.activity; |
| | | |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.LayoutInflater; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.dayu.pipirrapp.MyApplication; |
| | | import com.dayu.pipirrapp.bean.net.IssueResult; |
| | | import com.dayu.pipirrapp.databinding.ActivityChangePassWordBinding; |
| | | import com.dayu.pipirrapp.net.ApiManager; |
| | | import com.dayu.pipirrapp.net.BaseResponse; |
| | | import com.dayu.pipirrapp.net.Constants; |
| | | import com.dayu.pipirrapp.net.subscribers.SubscriberListener; |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.view.TitleBar; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * author: zuo |
| | |
| | | super.onCreate(savedInstanceState); |
| | | binding = ActivityChangePassWordBinding.inflate(LayoutInflater.from(this)); |
| | | setContentView(binding.getRoot()); |
| | | new TitleBar(this).setTitleText("修改密码"); |
| | | new TitleBar(this).setTitleText("修改密码").setLeftIco().setLeftIcoListening(v -> ChangePSActivity.this.finish()); |
| | | initView(); |
| | | } |
| | | |
| | | private void initView() { |
| | | binding.changePSBtn.setOnClickListener(v -> { |
| | | String oldPassword = binding.oldPassword.getText().toString(); |
| | | String newPSOne = binding.newPsone.getText().toString(); |
| | | String newPStwo = binding.newPsTwo.getText().toString(); |
| | | if (!TextUtils.isEmpty(oldPassword) && !TextUtils.isEmpty(newPSOne) && !TextUtils.isEmpty(newPStwo)) { |
| | | if (newPStwo.equals(newPSOne)) { |
| | | if (isPasswordComplex(newPSOne)) { |
| | | changePS(oldPassword, newPSOne); |
| | | } else { |
| | | ToastUtil.showToastShort(ChangePSActivity.this, "新密码长度应为6-12位,并且至少包含1个数字或字母!"); |
| | | } |
| | | } else { |
| | | ToastUtil.showToastShort(ChangePSActivity.this, "两次密码不一致!"); |
| | | } |
| | | } else { |
| | | ToastUtil.showToastShort(ChangePSActivity.this, "请输入完整信息!"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void changePS(String oldPassword, String newPassword) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("id", MyApplication.myApplication.userId); |
| | | params.put("oldPassword", oldPassword); |
| | | params.put("newPassword", newPassword); |
| | | ApiManager.getInstance().requestPost(this, Constants.BASE_URL + "/base/user/changePassword", IssueResult.class, params, new SubscriberListener<BaseResponse<IssueResult>>() { |
| | | @Override |
| | | public void onNext(BaseResponse<IssueResult> t) { |
| | | if (t.isSuccess()) { |
| | | ToastUtil.showToastLong(ChangePSActivity.this, "修改成功!"); |
| | | ChangePSActivity.this.finish(); |
| | | } else { |
| | | ToastUtil.showToast(ChangePSActivity.this, t.getMsg()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onCloose() { |
| | | super.onCloose(); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable e) { |
| | | super.onError(e); |
| | | ToastUtil.showToastLong(ChangePSActivity.this, "修改失败,请稍后再试"); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 检查密码复杂度的方法 |
| | | boolean isPasswordComplex(String password) { |
| | | // 密码复杂度规则:长度在6到12位之间,至少包含一个数字和一个字母 |
| | | return password.length() >= 6 && password.length() <= 12 && |
| | | password.matches(".*\\d.*") && // 至少包含一个数字 |
| | | password.matches(".*[a-zA-Z].*"); // 至少包含一个字母 |
| | | } |
| | | } |