/**
  * 注册
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @api {post} /user/register 注册
  * @apiName PostRegister
  * @apiGroup User
  *
  * @apiParam {String} mobile 手机号
  * @apiParam {String} password 登录密码
  *
  * @apiSuccessExample Success-Response:
  *     {
  *         uid: 1
  *     }
  */
 public function register(Request $request)
 {
     // 拒绝注册, 仅限登录
     return Response::error(FaultCode::RRJ);
     // 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);
     }
     // duplicate
     $user = User::where('mobile', $input['mobile'])->first();
     if ($user) {
         return Response::error(FaultCode::USER_EXIST);
     }
     // new
     $user = new User();
     $user->uid = uniqid() . mt_rand(1000, 2000);
     $user->mobile = $input['mobile'];
     $user->salt = CommonHelper::getSalt();
     $user->password = CommonHelper::makePassword($input['password'], $user->salt);
     $user->save();
     return Response::result(['uid' => $user->uid]);
 }
Example #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $salt = \App\Helpers\CommonHelper::getSalt();
     $passowrd = \App\Helpers\CommonHelper::makePassword('123456', $salt);
     DB::table('users')->insert(['uid' => uniqid() . mt_rand(1000, 2000), 'mobile' => '18612341234', 'password' => $passowrd, 'salt' => $salt, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]);
 }