更改密码
This commit is contained in:
parent
fbf5d34a19
commit
6f9e5870e9
@ -24,6 +24,19 @@ class StudentController extends BaseController
|
||||
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
|
||||
* @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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -41,9 +41,9 @@ class StudentService
|
||||
'data' => $token,
|
||||
'msg' => 'success'
|
||||
];
|
||||
}else{
|
||||
} else {
|
||||
$parent = StudentParent::where(['account' => $request['account']])->findOrEmpty();
|
||||
if(!$parent->isEmpty()){
|
||||
if (!$parent->isEmpty()) {
|
||||
if (md5($request['password'] . $parent->salt) != $parent->password) {
|
||||
throw new Exception('密码错误,请填写正确的密码');
|
||||
}
|
||||
@ -70,7 +70,68 @@ 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 登录
|
||||
* @param $request
|
||||
* @return array
|
||||
@ -81,14 +142,14 @@ class StudentService
|
||||
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
||||
throw new Exception('请登陆后再查看');
|
||||
}
|
||||
if(!empty((array)$request->student)){
|
||||
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('未找到学生信息');
|
||||
}
|
||||
$info = $student->toArray();
|
||||
$info['role'] = 'student';
|
||||
}elseif (!empty((array)$request->parent)){
|
||||
} 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('未找到家长信息');
|
||||
@ -121,7 +182,7 @@ class StudentService
|
||||
public function updateOpenid($request)
|
||||
{
|
||||
try {
|
||||
if(empty((array)$request->student) || empty((array)$request->parent)){
|
||||
if (empty((array)$request->student) || empty((array)$request->parent)) {
|
||||
throw new Exception('请先登陆');
|
||||
}
|
||||
|
||||
@ -135,15 +196,15 @@ class StudentService
|
||||
|
||||
$user_info = WechatSubscriptController::getUserInfo($access_token['openid'], $access_token['access_token']);
|
||||
|
||||
if(!empty((array)$request->student)){
|
||||
if (!empty((array)$request->student)) {
|
||||
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||
if($student->isEmpty()){
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到学生信息');
|
||||
}
|
||||
|
||||
if($student->openid && $student->openid != $user_info['openid']){
|
||||
if ($student->openid && $student->openid != $user_info['openid']) {
|
||||
throw new Exception('当前账号已绑定其它学生,不能重复绑定');
|
||||
}else{
|
||||
} else {
|
||||
$student->save([
|
||||
'openid' => $user_info['openid'],
|
||||
'nickname' => $user_info['nickname'],
|
||||
@ -151,14 +212,14 @@ class StudentService
|
||||
]);
|
||||
}
|
||||
|
||||
}else{
|
||||
} else {
|
||||
$parent = StudentParent::where(['id' => $request->parent->id])->findOrEmpty();
|
||||
if($parent->isEmpty()){
|
||||
if ($parent->isEmpty()) {
|
||||
throw new Exception('未找到家长信息');
|
||||
}
|
||||
if($parent->openid && $parent->openid != $user_info['openid']){
|
||||
if ($parent->openid && $parent->openid != $user_info['openid']) {
|
||||
throw new Exception('当前账号已绑定其它家长,不能重复绑定');
|
||||
}else{
|
||||
} else {
|
||||
$parent->save([
|
||||
'openid' => $user_info['openid'],
|
||||
'nickname' => $user_info['nickname'],
|
||||
@ -170,7 +231,7 @@ class StudentService
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'msg' => 'success'
|
||||
];
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'code' => ResponseCode::FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
|
@ -61,11 +61,11 @@ class TeacherService
|
||||
public function setTimeZone($request)
|
||||
{
|
||||
try {
|
||||
if(empty($request->teacher)){
|
||||
if (empty($request->teacher)) {
|
||||
throw new Exception('请教师登陆后再设置');
|
||||
}
|
||||
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
||||
if($teacher->isEmpty()){
|
||||
if ($teacher->isEmpty()) {
|
||||
throw new Exception('未找到教师信息,设置失败');
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ class TeacherService
|
||||
'time_zone_abbr' => $time_zone->abbr,
|
||||
'time_zone_offset' => $time_zone->offset,
|
||||
]);
|
||||
if(!$res){
|
||||
if (!$res) {
|
||||
throw new Exception('设置失败');
|
||||
}
|
||||
|
||||
@ -109,7 +109,47 @@ class TeacherService
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $teacher,
|
||||
];
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'code' => ResponseCode::FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
@ -126,11 +166,11 @@ class TeacherService
|
||||
public function updateOpenid($request)
|
||||
{
|
||||
try {
|
||||
if(empty($request->teacher)){
|
||||
if (empty($request->teacher)) {
|
||||
throw new Exception('请先教师登陆');
|
||||
}
|
||||
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
||||
if($teacher->isEmpty()){
|
||||
if ($teacher->isEmpty()) {
|
||||
throw new Exception('未找到教师信息');
|
||||
}
|
||||
|
||||
@ -141,10 +181,10 @@ class TeacherService
|
||||
throw new Exception('获取信息失败');
|
||||
}
|
||||
$openid = $user_info['openid'];
|
||||
$teacher = Teacher::where(['id'=>$request->teacher->id])->findOrEmpty();
|
||||
if($teacher->openid && $teacher->openid != $openid){
|
||||
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
||||
if ($teacher->openid && $teacher->openid != $openid) {
|
||||
throw new Exception('当前账号已绑定其它教师,不能重复绑定');
|
||||
}else{
|
||||
} else {
|
||||
$teacher->save([
|
||||
'openid' => $openid,
|
||||
]);
|
||||
@ -154,7 +194,7 @@ class TeacherService
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'msg' => 'success'
|
||||
];
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'code' => ResponseCode::FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
|
Loading…
x
Reference in New Issue
Block a user