Ejemplo n.º 1
0
 /**
  * 登录
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @api {post} /user/login 登录
  * @apiName PostLogin
  * @apiGroup User
  *
  * @apiParam {String} mobile 手机号
  * @apiParam {String} password 登录密码
  *
  * @apiSuccessExample Success-Response:
  *     {
  *         uid: 1
  *     }
  */
 public function login(Request $request)
 {
     // input
     $input = $request->all();
     // validate
     $validator = Validator::make($input, ['mobile' => 'required|size:11', 'password' => 'required|min:6']);
     if ($validator->fails()) {
         $errors = $validator->errors()->toArray();
         return Response::error(FaultCode::PARAMS_ERROR, $errors);
     }
     // grab
     $user = User::where('mobile', $input['mobile'])->first();
     if (is_null($user)) {
         return Response::error(FaultCode::USER_NOT_EXIST);
     }
     // password
     if (!CommonHelper::comparePassword($input['password'], $user->password, $user->salt)) {
         return Response::error(FaultCode::PASSWORD_NOT_MATCH);
     }
     return Response::result(['uid' => $user->uid]);
 }