mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 02:51:06 +03:30
142 lines
3.8 KiB
PHP
142 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\User;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Validator;
|
|
// use Illuminate\Foundation\Auth\RegistersUsers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Appended\Traites\Auth\Verification;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use App\Appended\Traites\Auth\Mc;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Register Controller
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This controller handles the registration of new users as well as their
|
|
| validation and creation. By default this controller uses a trait to
|
|
| provide this functionality without requiring any additional code.
|
|
|
|
|
*/
|
|
use Verification;
|
|
// use RegistersUsers;
|
|
|
|
/**
|
|
* Where to redirect users after registration.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $redirectTo = '/';
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// $this->middleware('guest');
|
|
}
|
|
|
|
/**
|
|
* Get a validator for an incoming registration request.
|
|
*
|
|
* @param array $data
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
*/
|
|
protected function validator(array $data)
|
|
{
|
|
return Validator::make($data, [
|
|
'name' => 'required|string|max:255',
|
|
'medical_center_id' => 'required',
|
|
'email' => 'email|max:255|unique:users',
|
|
'cell_number' => 'required|digits_between:10,11|unique:users',
|
|
'password' => 'required|string|min:6|confirmed',
|
|
]);
|
|
|
|
}
|
|
|
|
/**
|
|
* Create a new user instance after a valid registration.
|
|
*
|
|
* @param array $data
|
|
* @return \App\User
|
|
*/
|
|
protected function create(array $data)
|
|
{
|
|
$userData = [
|
|
'name' => $data['name'],
|
|
'password' => bcrypt($data['password']),
|
|
'email' => $data['email'],
|
|
'cell_number' => $data['cell_number'],
|
|
'medical_center_id' => $data['medical_center_id'],
|
|
'status' => 'Registered',
|
|
];
|
|
|
|
$userData['email'] ==="" ? $userData['email'] = null : null;
|
|
$userData['cell_number'] ==="" ? $userData['cell_number'] = null : null;
|
|
|
|
// $answer=$data['mathcaptcha'];
|
|
|
|
$user = User::create($userData);
|
|
if ($data['cell_number']) {
|
|
session(['temp_user' => $user]);
|
|
// $this->phone_confirmation($user);
|
|
} else
|
|
throw new \Exception('لطفا شماره همراه خود را وارد نمایید.');
|
|
|
|
return $user;
|
|
|
|
|
|
// $user = User::create($userData);
|
|
// dd($user);
|
|
|
|
// if (!empty($userData['email'])) {
|
|
// $this->mail_confirmation($user,'register');
|
|
// } else {
|
|
// $this->phone_confirmation($user);
|
|
// }
|
|
|
|
|
|
}
|
|
public function showRegistrationForm()
|
|
{
|
|
return view('auth.register');
|
|
}
|
|
|
|
public function register(Request $request)
|
|
{
|
|
$this->validator($request->all())->validate();
|
|
|
|
event(new Registered($user = $this->create($request->all())));
|
|
\Auth::loginUsingId($user->id);
|
|
return $this->registered($request, $user)
|
|
?: response()->json(['url' => $this->redirectTo, 'message' => 'ثبت نام شما با موفقیت انجام شد.']);
|
|
}
|
|
|
|
/**
|
|
* Get the guard to be used during registration.
|
|
*
|
|
* @return \Illuminate\Contracts\Auth\StatefulGuard
|
|
*/
|
|
protected function guard()
|
|
{
|
|
return Auth::guard();
|
|
}
|
|
|
|
protected function registered(Request $request, $user)
|
|
{
|
|
//
|
|
}
|
|
|
|
}
|