@@ -15,67 +15,67 @@ |
||
| 15 | 15 | use Spatie\MediaLibrary\Models\Media; |
| 16 | 16 | |
| 17 | 17 | class User extends Authenticatable implements MustVerifyEmail { |
| 18 | - use HasFactory, Notifiable, HasApiTokens, Billable, HasRoles; |
|
| 18 | + use HasFactory, Notifiable, HasApiTokens, Billable, HasRoles; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The attributes that are mass assignable. |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $fillable = [ |
|
| 26 | - 'first_name', |
|
| 27 | - 'last_name', |
|
| 28 | - 'email', |
|
| 29 | - 'password', |
|
| 30 | - ]; |
|
| 31 | - protected $connection = 'landlord'; |
|
| 20 | + /** |
|
| 21 | + * The attributes that are mass assignable. |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $fillable = [ |
|
| 26 | + 'first_name', |
|
| 27 | + 'last_name', |
|
| 28 | + 'email', |
|
| 29 | + 'password', |
|
| 30 | + ]; |
|
| 31 | + protected $connection = 'landlord'; |
|
| 32 | 32 | |
| 33 | - public function sendPasswordResetNotification($token) { |
|
| 34 | - // Your your own implementation. |
|
| 35 | - $this->notify(new ResetPasswordNotification($token)); |
|
| 36 | - } |
|
| 33 | + public function sendPasswordResetNotification($token) { |
|
| 34 | + // Your your own implementation. |
|
| 35 | + $this->notify(new ResetPasswordNotification($token)); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The attributes that should be hidden for arrays. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $hidden = [ |
|
| 44 | - 'password', |
|
| 45 | - 'remember_token', |
|
| 46 | - ]; |
|
| 38 | + /** |
|
| 39 | + * The attributes that should be hidden for arrays. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $hidden = [ |
|
| 44 | + 'password', |
|
| 45 | + 'remember_token', |
|
| 46 | + ]; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * The attributes that should be cast to native types. |
|
| 50 | - * |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - protected $casts = [ |
|
| 54 | - 'email_verified_at' => 'datetime', |
|
| 55 | - ]; |
|
| 48 | + /** |
|
| 49 | + * The attributes that should be cast to native types. |
|
| 50 | + * |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + protected $casts = [ |
|
| 54 | + 'email_verified_at' => 'datetime', |
|
| 55 | + ]; |
|
| 56 | 56 | |
| 57 | - public function providers() { |
|
| 58 | - return $this->hasMany(Provider::class, 'user_id', 'id'); |
|
| 59 | - } |
|
| 57 | + public function providers() { |
|
| 58 | + return $this->hasMany(Provider::class, 'user_id', 'id'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function userStartedChats() { |
|
| 62 | - return $this->hasMany(Chat::class, 'user_1')->join('users as partner', 'user_2', '=', 'partner.id'); |
|
| 63 | - } |
|
| 61 | + public function userStartedChats() { |
|
| 62 | + return $this->hasMany(Chat::class, 'user_1')->join('users as partner', 'user_2', '=', 'partner.id'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - public function userNotStartedChats() { |
|
| 66 | - return $this->hasMany(Chat::class, 'user_2')->join('users as partner', 'user_1', '=', 'partner.id'); |
|
| 67 | - } |
|
| 65 | + public function userNotStartedChats() { |
|
| 66 | + return $this->hasMany(Chat::class, 'user_2')->join('users as partner', 'user_1', '=', 'partner.id'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function userChats() { |
|
| 70 | - return $this->userStartedChats->merge($this->userNotStartedChats); |
|
| 71 | - } |
|
| 72 | - public function Company() { |
|
| 73 | - return $this->belongsToMany(Company::class, 'user_company'); |
|
| 69 | + public function userChats() { |
|
| 70 | + return $this->userStartedChats->merge($this->userNotStartedChats); |
|
| 71 | + } |
|
| 72 | + public function Company() { |
|
| 73 | + return $this->belongsToMany(Company::class, 'user_company'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public function sendEmailVerificationNotification() { |
|
| 76 | + public function sendEmailVerificationNotification() { |
|
| 77 | 77 | |
| 78 | - return $this->notify(new VerifyNotification()); |
|
| 78 | + return $this->notify(new VerifyNotification()); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | } |
@@ -6,5 +6,5 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Role extends BaseRole |
| 8 | 8 | { |
| 9 | - protected $connection = 'landlord'; |
|
| 9 | + protected $connection = 'landlord'; |
|
| 10 | 10 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | |
| 37 | 37 | public function addr() |
| 38 | 38 | { |
| 39 | - return $this->belongsTo(Addr::class); |
|
| 39 | + return $this->belongsTo(Addr::class); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -9,5 +9,5 @@ |
||
| 9 | 9 | { |
| 10 | 10 | use HasFactory; |
| 11 | 11 | |
| 12 | - protected $fillable = ['title']; |
|
| 12 | + protected $fillable = ['title']; |
|
| 13 | 13 | } |
@@ -10,121 +10,121 @@ |
||
| 10 | 10 | use Spatie\Multitenancy\Models\Concerns\UsesLandlordConnection; |
| 11 | 11 | use Illuminate\Auth\Events\Registered; |
| 12 | 12 | class RegisterController extends Controller { |
| 13 | - use UsesLandlordConnection; |
|
| 14 | - |
|
| 15 | - public function register(Request $request) { |
|
| 16 | - |
|
| 17 | - $request->validate([ |
|
| 18 | - 'first_name' => ['required'], |
|
| 19 | - 'last_name' => ['required'], |
|
| 20 | - 'email' => ['required', 'email', 'unique:landlord.users'], |
|
| 21 | - 'password' => ['required', 'min:8', 'confirmed'], |
|
| 22 | - ]); |
|
| 23 | - |
|
| 24 | - DB::connection($this->getConnectionName())->beginTransaction(); |
|
| 25 | - |
|
| 26 | - try |
|
| 27 | - { |
|
| 28 | - |
|
| 29 | - // $user_id = DB::connection($this->getConnectionName())->table('users')->insertGetId([ |
|
| 30 | - // 'first_name' => $request->first_name, |
|
| 31 | - // 'last_name' => $request->last_name, |
|
| 32 | - // 'email' => $request->email, |
|
| 33 | - // 'password' => bcrypt($request->password), |
|
| 34 | - // ]); |
|
| 35 | - // $user = User::create([ |
|
| 36 | - // 'first_name' => $request->first_name, |
|
| 37 | - // 'last_name' => $request->last_name, |
|
| 38 | - // 'email' => $request->email, |
|
| 39 | - // 'password' => bcrypt($request->password) |
|
| 40 | - // ]); |
|
| 41 | - |
|
| 42 | - $user = new User; |
|
| 43 | - |
|
| 44 | - $user->first_name = $request->first_name; |
|
| 45 | - $user->last_name = $request->last_name; |
|
| 46 | - $user->email = $request->email; |
|
| 47 | - $user->password = bcrypt($request->password); |
|
| 48 | - $user->save(); |
|
| 49 | - event(new Registered($user)); |
|
| 50 | - $user_id = $user->id; |
|
| 51 | - $user = User::find($user_id); |
|
| 13 | + use UsesLandlordConnection; |
|
| 14 | + |
|
| 15 | + public function register(Request $request) { |
|
| 16 | + |
|
| 17 | + $request->validate([ |
|
| 18 | + 'first_name' => ['required'], |
|
| 19 | + 'last_name' => ['required'], |
|
| 20 | + 'email' => ['required', 'email', 'unique:landlord.users'], |
|
| 21 | + 'password' => ['required', 'min:8', 'confirmed'], |
|
| 22 | + ]); |
|
| 23 | + |
|
| 24 | + DB::connection($this->getConnectionName())->beginTransaction(); |
|
| 25 | + |
|
| 26 | + try |
|
| 27 | + { |
|
| 28 | + |
|
| 29 | + // $user_id = DB::connection($this->getConnectionName())->table('users')->insertGetId([ |
|
| 30 | + // 'first_name' => $request->first_name, |
|
| 31 | + // 'last_name' => $request->last_name, |
|
| 32 | + // 'email' => $request->email, |
|
| 33 | + // 'password' => bcrypt($request->password), |
|
| 34 | + // ]); |
|
| 35 | + // $user = User::create([ |
|
| 36 | + // 'first_name' => $request->first_name, |
|
| 37 | + // 'last_name' => $request->last_name, |
|
| 38 | + // 'email' => $request->email, |
|
| 39 | + // 'password' => bcrypt($request->password) |
|
| 40 | + // ]); |
|
| 41 | + |
|
| 42 | + $user = new User; |
|
| 43 | + |
|
| 44 | + $user->first_name = $request->first_name; |
|
| 45 | + $user->last_name = $request->last_name; |
|
| 46 | + $user->email = $request->email; |
|
| 47 | + $user->password = bcrypt($request->password); |
|
| 48 | + $user->save(); |
|
| 49 | + event(new Registered($user)); |
|
| 50 | + $user_id = $user->id; |
|
| 51 | + $user = User::find($user_id); |
|
| 52 | 52 | $user->assignRole('free'); |
| 53 | 53 | // $user->sendEmailVerificationNotification(); |
| 54 | 54 | |
| 55 | - $random = $this->unique_random('companies', 'name', 5); |
|
| 56 | - $company_id = DB::connection($this->getConnectionName())->table('companies')->insertGetId([ |
|
| 57 | - 'name' => 'company' . $random, |
|
| 58 | - 'status' => 1, |
|
| 59 | - 'current_tenant' => 1, |
|
| 60 | - ]); |
|
| 55 | + $random = $this->unique_random('companies', 'name', 5); |
|
| 56 | + $company_id = DB::connection($this->getConnectionName())->table('companies')->insertGetId([ |
|
| 57 | + 'name' => 'company' . $random, |
|
| 58 | + 'status' => 1, |
|
| 59 | + 'current_tenant' => 1, |
|
| 60 | + ]); |
|
| 61 | 61 | |
| 62 | - DB::connection($this->getConnectionName())->table('user_company')->insert([ |
|
| 63 | - 'user_id' => $user_id, |
|
| 64 | - 'company_id' => $company_id, |
|
| 65 | - ]); |
|
| 62 | + DB::connection($this->getConnectionName())->table('user_company')->insert([ |
|
| 63 | + 'user_id' => $user_id, |
|
| 64 | + 'company_id' => $company_id, |
|
| 65 | + ]); |
|
| 66 | 66 | |
| 67 | - $tree_id = DB::connection($this->getConnectionName())->table('trees')->insertGetId([ |
|
| 68 | - 'company_id' => $company_id, |
|
| 69 | - 'name' => 'tree' . $company_id, |
|
| 70 | - 'description' => '', |
|
| 71 | - 'current_tenant' => 1, |
|
| 72 | - ]); |
|
| 67 | + $tree_id = DB::connection($this->getConnectionName())->table('trees')->insertGetId([ |
|
| 68 | + 'company_id' => $company_id, |
|
| 69 | + 'name' => 'tree' . $company_id, |
|
| 70 | + 'description' => '', |
|
| 71 | + 'current_tenant' => 1, |
|
| 72 | + ]); |
|
| 73 | 73 | |
| 74 | - $tenant_id = DB::connection($this->getConnectionName())->table('tenants')->insertGetId([ |
|
| 75 | - 'name' => 'tenant' . $tree_id, |
|
| 76 | - 'tree_id' => $tree_id, |
|
| 77 | - 'database' => 'tenant' . $tree_id, |
|
| 78 | - ]); |
|
| 74 | + $tenant_id = DB::connection($this->getConnectionName())->table('tenants')->insertGetId([ |
|
| 75 | + 'name' => 'tenant' . $tree_id, |
|
| 76 | + 'tree_id' => $tree_id, |
|
| 77 | + 'database' => 'tenant' . $tree_id, |
|
| 78 | + ]); |
|
| 79 | 79 | |
| 80 | - DB::statement('create database tenant' . $tree_id); |
|
| 80 | + DB::statement('create database tenant' . $tree_id); |
|
| 81 | 81 | |
| 82 | - Artisan::call('tenants:artisan "migrate --database=tenant --force"'); |
|
| 83 | - } catch (Exception $e) { |
|
| 84 | - DB::connection($this->getConnectionName())->rollback(); |
|
| 85 | - } |
|
| 82 | + Artisan::call('tenants:artisan "migrate --database=tenant --force"'); |
|
| 83 | + } catch (Exception $e) { |
|
| 84 | + DB::connection($this->getConnectionName())->rollback(); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - DB::connection($this->getConnectionName())->commit(); |
|
| 88 | - } |
|
| 87 | + DB::connection($this->getConnectionName())->commit(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function unique_random($table, $col, $chars = 16) { |
|
| 90 | + public function unique_random($table, $col, $chars = 16) { |
|
| 91 | 91 | |
| 92 | - $unique = false; |
|
| 92 | + $unique = false; |
|
| 93 | 93 | |
| 94 | - // Store tested results in array to not test them again |
|
| 95 | - $tested = []; |
|
| 94 | + // Store tested results in array to not test them again |
|
| 95 | + $tested = []; |
|
| 96 | 96 | |
| 97 | - do { |
|
| 97 | + do { |
|
| 98 | 98 | |
| 99 | - // Generate random string of characters |
|
| 100 | - $random = Str::random($chars); |
|
| 99 | + // Generate random string of characters |
|
| 100 | + $random = Str::random($chars); |
|
| 101 | 101 | |
| 102 | - // Check if it's already testing |
|
| 103 | - // If so, don't query the database again |
|
| 104 | - if (in_array($random, $tested)) { |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 102 | + // Check if it's already testing |
|
| 103 | + // If so, don't query the database again |
|
| 104 | + if (in_array($random, $tested)) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - // Check if it is unique in the database |
|
| 109 | - $count = DB::connection($this->getConnectionName())->table('companies')->where($col, '=', $random)->count(); |
|
| 108 | + // Check if it is unique in the database |
|
| 109 | + $count = DB::connection($this->getConnectionName())->table('companies')->where($col, '=', $random)->count(); |
|
| 110 | 110 | |
| 111 | - // Store the random character in the tested array |
|
| 112 | - // To keep track which ones are already tested |
|
| 113 | - $tested[] = $random; |
|
| 111 | + // Store the random character in the tested array |
|
| 112 | + // To keep track which ones are already tested |
|
| 113 | + $tested[] = $random; |
|
| 114 | 114 | |
| 115 | - // String appears to be unique |
|
| 116 | - if ($count == 0) { |
|
| 117 | - // Set unique to true to break the loop |
|
| 118 | - $unique = true; |
|
| 119 | - } |
|
| 115 | + // String appears to be unique |
|
| 116 | + if ($count == 0) { |
|
| 117 | + // Set unique to true to break the loop |
|
| 118 | + $unique = true; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - // If unique is still false at this point |
|
| 122 | - // it will just repeat all the steps until |
|
| 123 | - // it has generated a random string of characters |
|
| 121 | + // If unique is still false at this point |
|
| 122 | + // it will just repeat all the steps until |
|
| 123 | + // it has generated a random string of characters |
|
| 124 | 124 | |
| 125 | - } while (!$unique); |
|
| 125 | + } while (!$unique); |
|
| 126 | 126 | |
| 127 | - return $random; |
|
| 128 | - } |
|
| 127 | + return $random; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
@@ -94,7 +94,7 @@ |
||
| 94 | 94 | |
| 95 | 95 | else if ($role == 5 || $role == 6) { |
| 96 | 96 | if(Tree::whereIn('company_id', $companies_id)->count() < 10){ |
| 97 | - return response()->json(['create_tree' => true]); |
|
| 97 | + return response()->json(['create_tree' => true]); |
|
| 98 | 98 | } else { |
| 99 | 99 | return response()->json(['create_tree' => false]); |
| 100 | 100 | } |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | { |
| 10 | 10 | public function index() { |
| 11 | 11 | |
| 12 | - return auth()->user()->getAllPermissions()->pluck('name'); |
|
| 12 | + return auth()->user()->getAllPermissions()->pluck('name'); |
|
| 13 | 13 | } |
| 14 | - public function getPermission(Request $request) { |
|
| 15 | - $query = Permission::query(); |
|
| 14 | + public function getPermission(Request $request) { |
|
| 15 | + $query = Permission::query(); |
|
| 16 | 16 | |
| 17 | 17 | if($request->has('searchTerm')) { |
| 18 | 18 | $columnsToSearch = ['name']; |
@@ -12,42 +12,42 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | public function verify(Request $request) |
| 14 | 14 | { |
| 15 | - $user = User::findOrFail($request->id); |
|
| 15 | + $user = User::findOrFail($request->id); |
|
| 16 | 16 | |
| 17 | 17 | // do this check ,only if you allow verified user to login |
| 18 | 18 | // if(! hash_equals((string) $request->id,(string) $user->getKey())){ |
| 19 | 19 | // throw new AuthorizationException; |
| 20 | 20 | // } |
| 21 | 21 | |
| 22 | - if(! hash_equals((string) $request->hash,sha1($user->getEmailForVerification()))) |
|
| 23 | - { |
|
| 24 | - return response()->json([ |
|
| 25 | - "message" => "Unauthorized", |
|
| 26 | - "success" => false |
|
| 27 | - ]); |
|
| 28 | - } |
|
| 22 | + if(! hash_equals((string) $request->hash,sha1($user->getEmailForVerification()))) |
|
| 23 | + { |
|
| 24 | + return response()->json([ |
|
| 25 | + "message" => "Unauthorized", |
|
| 26 | + "success" => false |
|
| 27 | + ]); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - if($user->hasVerifiedEmail()) |
|
| 31 | - { |
|
| 32 | - return response()->json([ |
|
| 33 | - "message" => "User Allready Verified!", |
|
| 34 | - "success" => false |
|
| 35 | - ]); |
|
| 36 | - } |
|
| 30 | + if($user->hasVerifiedEmail()) |
|
| 31 | + { |
|
| 32 | + return response()->json([ |
|
| 33 | + "message" => "User Allready Verified!", |
|
| 34 | + "success" => false |
|
| 35 | + ]); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if($user->markEmailAsVerified()) |
|
| 39 | - { |
|
| 38 | + if($user->markEmailAsVerified()) |
|
| 39 | + { |
|
| 40 | 40 | event(new Verified($user)); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return response()->json([ |
|
| 44 | - "message" => "Email verified successfully!", |
|
| 45 | - "success" => true |
|
| 46 | - ]); |
|
| 43 | + return response()->json([ |
|
| 44 | + "message" => "Email verified successfully!", |
|
| 45 | + "success" => true |
|
| 46 | + ]); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function resendVerificatonEmail(Request $request) |
|
| 50 | - { |
|
| 49 | + public function resendVerificatonEmail(Request $request) |
|
| 50 | + { |
|
| 51 | 51 | $user = User::where('email',$request->email)->firstOrFail(); |
| 52 | 52 | if(!$user) |
| 53 | 53 | { |
@@ -61,5 +61,5 @@ discard block |
||
| 61 | 61 | "message" => "Check your email", |
| 62 | 62 | "success" => true |
| 63 | 63 | ]); |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | // |
| 81 | 81 | $request->validate([ |
| 82 | - 'name' => ['required','unique:landlord.companies'], |
|
| 82 | + 'name' => ['required','unique:landlord.companies'], |
|
| 83 | 83 | |
| 84 | 84 | ]); |
| 85 | 85 | return $user->Company()->create([ |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | { |
| 124 | 124 | // |
| 125 | 125 | $request->validate([ |
| 126 | - 'name' => ['required','unique:landlord.companies'], |
|
| 126 | + 'name' => ['required','unique:landlord.companies'], |
|
| 127 | 127 | |
| 128 | 128 | ]); |
| 129 | 129 | |