Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/test.tradze.com/app_old/Http/Controllers/Auth/ |
<?php
namespace App\Http\Controllers\Auth;
// use App\Http\Requests\Request;
use App\Modules\Users\Models\UserProfile;
use App\User;
use Bican\Roles\Models\Role;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Laravel\Socialite\Facades\Socialite;
use Symfony\Component\Translation\Tests\Writer\BackupDumper;
use Validator;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* 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',
// 'payment-method-nonce' => 'required',
]);
}
/**
* Show the application admin login form.
*
* @return \Illuminate\Http\Response
*/
public function getLogin()
{
return view('auth.login');
}
/**
* Show the application registration form.
*
* @return \Illuminate\Http\Response
*/
public function getRegister()
{
return view('auth.register');
}
public function getSalonRegister()
{
return view('auth.salonRegister');
}
public function postSalonRegister(Request $request)
{
// dd("inside post salon register");
$validator = $this->validator($request->all());
if ($validator->fails()) {
// dd($validator->getMessageBag());
return redirect()->back()->with($validator->getMessageBag());
}
else
{
// Auth::guard($this->getGuard())->login($this->create($request->all()));
$responseData = $this->createsalon($request->all());
return redirect('/login');
}
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
DB::beginTransaction();
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'trial_ends_at' => Carbon::now()->addYears(10),
'newsletter' => $data['newsletter'],
]);
$name = explode(' ',$data['name']);
//create user account on braintree and associate braintree_id to user account
// $token = $data['payment-method-nonce'];
// try {
// $user->newSubscription('single-charge', env('BRAINTREE_PLAN'))->create($token, [
// 'firstName' => $name[0],
// 'lastName' => isset($name[1]) ? $name[1] : '',
// 'email' => $user->email,
// 'phone' => $data['phone'],
// ]);
// }
// catch (\Exception $e){
// $message = $e->getMessage();
// $message = str_ireplace('braintree','Zen London',$message);
// flash(strtoupper($message), 'danger');
// } //end try/catch
//create user profile
$profile = UserProfile::create([
'user_id' => $user->id,
'first_name' => $name[0],
'last_name' => isset($name[1])?$name[1]:'',
'mobile_number' => $data['phone'],
'trial_ends_at' => Carbon::now()->addYears(10),
]);
//save profile avatar
if (isset($data['avatar'])){
$file = $data['avatar'];
$filename = str_slug(str_replace($file->getClientOriginalExtension(),'',str_random(30)));
$extension = $file->getClientOriginalExtension();
$path_file = 'avatar/'.$filename.".".$extension;
//upload file
$upload = Storage::disk('public_images')->put(
$path_file,
file_get_contents($file->getRealPath())
);
//attach file path to user profile
$profile->avatar = $path_file;
$profile->save();
$img = Image::make(public_path('images/'.$profile->avatar))->fit(400,400,null,'top')->save(public_path('images/'.$profile->avatar),100);
}
//get customer role
$role = Role::where('slug','customer')->first();
//attach role
if ($role)
$user->attachRole($role);
//commit or rollback transaction
if ($user && $profile){
//commit transaction
DB::commit();
//send mail
//send confirmation email
$data['user'] = $user;
Mail::send('users::frontend_new.emails.newaccount', ['user' => $user], function ($m) use ($data) {
$m->from(env('MAIL_FROM'), env('APP_NAME'));
$m->to($data['user']->email, $data['user']->name);
$m->bcc(explode(',',env('MAIL_NEWORDER_BCC')), env('MAIL_NEWORDER_BCC_NAME'));
$m->subject(env('APP_NAME').' – New account');
});
//inform user that hos account is created and
flash()->overlay('<h3>Your account is created and you are logged in.</h3>','Zen London - Create account');
//return user
return $user;
}
else{
DB::rollback();
return redirect('/register');
} //end elseif
} //end method
// Create Salon Method
protected function createsalon(array $data)
{
DB::beginTransaction();
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'trial_ends_at' => Carbon::now()->addYears(10),
'newsletter' => isset($data['newsletter'])?$data['newsletter']:0,
]);
$name = explode(' ',$data['name']);
//create user account on braintree and associate braintree_id to user account
// $token = $data['payment-method-nonce'];
// try {
// $user->newSubscription('single-charge', env('BRAINTREE_PLAN'))->create($token, [
// 'firstName' => $name[0],
// 'lastName' => isset($name[1]) ? $name[1] : '',
// 'email' => $user->email,
// 'phone' => $data['phone'],
// ]);
// }
// catch (\Exception $e){
// $message = $e->getMessage();
// $message = str_ireplace('braintree','Zen London',$message);
// flash(strtoupper($message), 'danger');
// } //end try/catch
//create user profile
$profile = UserProfile::create([
'user_id' => $user->id,
'first_name' => $name[0],
'last_name' => isset($name[1])?$name[1]:'',
'mobile_number' => $data['phone'],
'trial_ends_at' => Carbon::now()->addYears(10),
]);
//save profile avatar
if (isset($data['avatar'])){
$file = $data['avatar'];
$filename = str_slug(str_replace($file->getClientOriginalExtension(),'',str_random(30)));
$extension = $file->getClientOriginalExtension();
$path_file = 'avatar/'.$filename.".".$extension;
//upload file
$upload = Storage::disk('public_images')->put(
$path_file,
file_get_contents($file->getRealPath())
);
//attach file path to user profile
$profile->avatar = $path_file;
$profile->save();
$img = Image::make(public_path('images/'.$profile->avatar))->fit(400,400,null,'top')->save(public_path('images/'.$profile->avatar),100);
}
//get customer role
$role = Role::where('slug','salon')->first();
//attach role
if ($role)
$user->attachRole($role);
//commit or rollback transaction
if ($user && $profile){
//commit transaction
DB::commit();
//send mail
//send confirmation email
$data['user'] = $user;
Mail::send('users::frontend_new.emails.newaccount', ['user' => $user], function ($m) use ($data) {
$m->from(env('MAIL_FROM'), env('APP_NAME'));
$m->to($data['user']->email, $data['user']->name);
$m->bcc(explode(',',env('MAIL_NEWORDER_BCC')), env('MAIL_NEWORDER_BCC_NAME'));
$m->subject(env('APP_NAME').' – New account');
});
//inform user that hos account is created and
flash()->overlay('<h3>Your account is created and you are logged in.</h3>','Zen London - Create account');
//return user
return $user;
}
else{
DB::rollback();
return redirect('/salon/register');
} //end elseif
} //end method
} //end class controller