app/Http/Controllers/RegisterController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request->all();
        if($data['password'] != $data['confirm_password']) return back()->withErrors('两次密码不一致');
         在对数据进行校验一次
        $this->validate($request ,[
            'email'     => 'required|email',
            'username'  => 'required|min:2|max:10',
            'password'  => 'required|min:6'
        ]);
        查询邮箱是否被注册
        $email = self::$user->checkUserEmail(['email' => $data['email']]);
        if($email){
            return back()->withErrors('此邮箱已存在！');
        }
        加工存入的用户信息
        $datas = [
            'gu_id' => Uuid::uuid1()->getHex(),  用户唯一id
            'user_name' => $data['username'],
            'email' => $data['email'],
            'password' => md5(md5($data['password'].$data['email'])),    密码加密
            'create_at' => time()
        ];
        注册用户
        $result = self::$user->addUser($datas);
        if($result){
            return redirect('/login');
        }
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; if ( $ data [ 'password' ] != $ data [ 'confirm_password' ] ) return back ( ) -> withErrors ( '两次密码不一致'); $ this -> validate ( $ request , [ 'email' => 'required|email' , 'username' => 'required|min:2|max:10' , 'password' => 'required|min:6' ] ) ; $ email = self :: $ user -> checkUserEmail ( [ 'email' => $ data [ 'email' ] ] ) ; if ( $ email ) { return back ( ) -> withErrors ( '此邮箱已存在！'); } $ datas = [ 'gu_id' => Uuid :: uuid1 ( ) -> getHex ( ) , 'user_name' => $ data [ 'username' ] , 'email' => $ data [ 'email' ] , 'password' => md5 ( md5 ( $ data [ 'password' ] . $ data [ 'email' ] ) ) , 'create_at' => time ( ) ] ; $ result = self :: $ user -> addUser ( $ datas ) ; if ( $ result ) { return redirect ( '/login' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// // 在对数据进行校验一次 //查询邮箱是否被注册 //加工存入的用户信息 //用户唯一id //密码加密 //注册用户