| xqd
@@ -129,6 +129,36 @@ class AuthorizationsController extends Controller
|
|
|
return response()->json($resdata)->setStatusCode(201);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 注册账号
|
|
|
+ */
|
|
|
+ public function register(Request $request){
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'mobile' => ['required', 'regex:/^1[3456789]\d{9}$/'],
|
|
|
+ 'password' => 'bail|required',
|
|
|
+ ],[
|
|
|
+ 'mobile.required'=>"手机号码必须",
|
|
|
+ 'mobile.regex'=>"手机号码格式错误",
|
|
|
+ 'password.required'=>"密码必须",
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()){
|
|
|
+ return $this->response()->errorForbidden($validator->messages()->first());
|
|
|
+ }
|
|
|
+ if(User::where(['mobile'=>$request->mobile])->first()){
|
|
|
+ return $this->response->errorForbidden("该手机号码已使用");
|
|
|
+ }
|
|
|
+ $ins = array();
|
|
|
+ $ins['mobile'] = $request->mobile;
|
|
|
+ $ins['password'] = $request->password;
|
|
|
+ if(User::create($ins)){
|
|
|
+ return response()->json(['message'=>"注册成功"])->setStatusCode(201);
|
|
|
+ }else{
|
|
|
+ return $this->response->errorForbidden("注册失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 忘记密码
|
| xqd
@@ -161,7 +191,7 @@ class AuthorizationsController extends Controller
|
|
|
$user = User::where(['mobile'=>$request->mobile])->first();
|
|
|
$user->password =$request->password;// Hash::make($request->password);
|
|
|
if($user->save()){
|
|
|
- return $this->response->noContent();
|
|
|
+ return $this->response->noContent()->setStatusCode(201);
|
|
|
}
|
|
|
}
|
|
|
|