mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 12:34:13 +00:00
105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\User;
|
|
use App\VerifyUser;
|
|
use App\Role;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
use App\Notifications\VerifyEmail;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
use RegistersUsers;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('guest');
|
|
}
|
|
|
|
/**
|
|
* The user has been registered.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param mixed $user
|
|
* @return mixed
|
|
*/
|
|
protected function registered(Request $request, $user)
|
|
{
|
|
$this->guard()->logout();
|
|
return response()->json(['status'=>'We sent you an activation code. Check your email and click on the link to verify.'],200);
|
|
return $user;
|
|
}
|
|
|
|
/**
|
|
* 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|max:255',
|
|
'email' => 'required|email|max:255|unique:users',
|
|
'password' => 'required|min:6|confirmed',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Create a new user instance after a valid registration.
|
|
*
|
|
* @param array $data
|
|
* @return User
|
|
*/
|
|
protected function create(array $data)
|
|
{
|
|
$role = Role::where('name','=','member')->first();
|
|
$user = new User();
|
|
$user->name = $data['name'];
|
|
$user->email = $data['email'];
|
|
$user->password = bcrypt($data['password']);
|
|
$user->save();
|
|
$user->attachRole($role);
|
|
|
|
$verifyUser = VerifyUser::create([
|
|
'user_id' => $user->id,
|
|
'token' => str_random(40)
|
|
]);
|
|
|
|
//Notification::send($user, new VerifyUser($user));
|
|
$user->notify(new VerifyEmail($verifyUser));
|
|
return $user;
|
|
|
|
}
|
|
|
|
public function verifyUser($token)
|
|
{
|
|
$verifyUser = VerifyUser::where('token', $token)->first();
|
|
if(isset($verifyUser) ){
|
|
$user = $verifyUser->user;
|
|
if(!$user->verified) {
|
|
$verifyUser->user->verified = 1;
|
|
$verifyUser->user->save();
|
|
return response()->json(['status' => 'Your e-mail is verified. You can now login'], 400);
|
|
//$status = "Your e-mail is verified. You can now login.";
|
|
}else{
|
|
return response()->json(['status' => 'Your e-mail is already verified. Please login.'], 400);
|
|
//$status = "Your e-mail is already verified. You can now login.";
|
|
}
|
|
}else{
|
|
return response()->json(['warning' => 'Sorry your email cannot be identified.'], 400);
|
|
//return redirect('/login')->with('warning', "Sorry your email cannot be identified.");
|
|
}
|
|
//return response()->json(['status']);
|
|
}
|
|
}
|