更改密码
This commit is contained in:
parent
fbf5d34a19
commit
6f9e5870e9
@ -24,6 +24,19 @@ class StudentController extends BaseController
|
|||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 更改密码
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function resetPassword(Request $request)
|
||||||
|
{
|
||||||
|
$service = new StudentService();
|
||||||
|
$res = $service->resetPassword($request->post());
|
||||||
|
return $this->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc 获取code
|
* @desc 获取code
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
@ -70,6 +70,20 @@ class TeacherController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 重置密码
|
||||||
|
* @param Request $request
|
||||||
|
* @return \support\Response
|
||||||
|
*/
|
||||||
|
public function resetPassword(Request $request)
|
||||||
|
{
|
||||||
|
$service = new TeacherService();
|
||||||
|
$res = $service->resetPassword($request);
|
||||||
|
return $this->json($res);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -70,6 +70,67 @@ class StudentService
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 充值密码
|
||||||
|
* @param $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function resetPassword($request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
||||||
|
throw new Exception('请登陆后再操作');
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestData = $request->post();
|
||||||
|
|
||||||
|
if (!empty((array)$request->student)) {
|
||||||
|
$student = Student::where(['id' => $request->student->id])->with(['parentArr'])->field('id,student_name,account,openid,avatar,nickname,parent_id')->findOrEmpty();
|
||||||
|
if ($student->isEmpty()) {
|
||||||
|
throw new Exception('未找到学生信息');
|
||||||
|
}
|
||||||
|
if(empty($requestData['pwd']) || strlen(trim($requestData['pwd'])) < 6){
|
||||||
|
throw new Exception('请输入密码或者长度大于6位');
|
||||||
|
}
|
||||||
|
|
||||||
|
$salt = random_str(16);
|
||||||
|
$password = md5(trim($requestData['pwd'] . $salt));
|
||||||
|
$student->save([
|
||||||
|
'password' => $password,
|
||||||
|
'salt' => $salt
|
||||||
|
]);
|
||||||
|
|
||||||
|
} elseif (!empty((array)$request->parent)) {
|
||||||
|
$parent = StudentParent::where(['id' => $request->parent->id])->with(['studentArr'])->field('id,parent_name,account,openid,avatar,nickname')->findOrEmpty();
|
||||||
|
if ($parent->isEmpty()) {
|
||||||
|
throw new Exception('未找到家长信息');
|
||||||
|
}
|
||||||
|
if(empty($requestData['pwd']) || strlen(trim($requestData['pwd'])) < 6){
|
||||||
|
throw new Exception('请输入密码或者长度大于6位');
|
||||||
|
}
|
||||||
|
|
||||||
|
$salt = random_str(16);
|
||||||
|
$password = md5(trim($requestData['pwd'] . $salt));
|
||||||
|
$parent->save([
|
||||||
|
'password' => $password,
|
||||||
|
'salt' => $salt
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::SUCCESS,
|
||||||
|
'msg' => '更改成功'
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc 登录
|
* @desc 登录
|
||||||
* @param $request
|
* @param $request
|
||||||
|
@ -117,6 +117,46 @@ class TeacherService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 教师信息
|
||||||
|
* @param $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function resetPassword($request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (empty($request->teacher)) {
|
||||||
|
throw new Exception('请先教师登陆');
|
||||||
|
}
|
||||||
|
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
||||||
|
if ($teacher->isEmpty()) {
|
||||||
|
throw new Exception('未找到教师信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
$requestData = $request->post();
|
||||||
|
if (empty($requestData['pwd']) || strlen(trim($requestData['pwd'])) < 6) {
|
||||||
|
throw new Exception('请输入密码或者长度大于6位');
|
||||||
|
}
|
||||||
|
|
||||||
|
$salt = random_str(16);
|
||||||
|
$password = md5(trim($requestData['pwd'] . $salt));
|
||||||
|
$teacher->save([
|
||||||
|
'password' => $password,
|
||||||
|
'salt' => $salt
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::SUCCESS,
|
||||||
|
'msg' => '操作成功',
|
||||||
|
];
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc 更新code
|
* @desc 更新code
|
||||||
* @param $request
|
* @param $request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user